int main(int argc, char* argv[]) { std::string map; std::string style; double latTop,latBottom,lonLeft,lonRight; unsigned long xTileStart,xTileEnd,xTileCount,yTileStart,yTileEnd,yTileCount; unsigned long startZoom; unsigned long endZoom; unsigned long tileWidth; unsigned long tileHeight; std::string driver; if (argc!=12) { std::cerr << "DrawMap "; std::cerr << "<map directory> <style-file> "; std::cerr << "<lat_top> <lon_left> <lat_bottom> <lon_right> "; std::cerr << "<start zoom>" << std::endl; std::cerr << "<end zoom>" << std::endl; std::cerr << "<tile width>" << std::endl; std::cerr << "<tile height>" << std::endl; std::cerr << "<driver>" << std::endl; return 1; } map=argv[1]; style=argv[2]; if (sscanf(argv[3],"%lf",&latTop)!=1) { std::cerr << "lon is not numeric!" << std::endl; return 1; } if (sscanf(argv[4],"%lf",&lonLeft)!=1) { std::cerr << "lat is not numeric!" << std::endl; return 1; } if (sscanf(argv[5],"%lf",&latBottom)!=1) { std::cerr << "lon is not numeric!" << std::endl; return 1; } if (sscanf(argv[6],"%lf",&lonRight)!=1) { std::cerr << "lat is not numeric!" << std::endl; return 1; } if (sscanf(argv[7],"%lu",&startZoom)!=1) { std::cerr << "start zoom is not numeric!" << std::endl; return 1; } if (sscanf(argv[8],"%lu",&endZoom)!=1) { std::cerr << "end zoom is not numeric!" << std::endl; return 1; } if (sscanf(argv[9],"%lu",&tileWidth)!=1) { std::cerr << "tile width is not numeric!" << std::endl; return 1; } if (sscanf(argv[10],"%lu",&tileHeight)!=1) { std::cerr << "tile height is not numeric!" << std::endl; return 1; } driver=argv[11]; #if defined(HAVE_LIB_OSMSCOUTMAPCAIRO) cairo_surface_t *surface=NULL; cairo_t *cairo=NULL; #endif if (driver=="cairo") { std::cout << "Using driver 'cairo'..." << std::endl; #if defined(HAVE_LIB_OSMSCOUTMAPCAIRO) surface=cairo_image_surface_create(CAIRO_FORMAT_RGB24,tileWidth,tileHeight); if (surface==NULL) { std::cerr << "Cannot create cairo image surface" << std::endl; return 1; } cairo=cairo_create(surface); if (cairo==NULL) { std::cerr << "Cannot create cairo_t for image surface" << std::endl; return 1; } #else std::cerr << "Driver 'cairo' is not enabled" << std::endl; return 1; #endif } else { std::cerr << "Unsupported driver '" << driver << "'" << std::endl; return 1; } osmscout::DatabaseParameter databaseParameter; //databaseParameter.SetDebugPerformance(true); osmscout::DatabaseRef database(new osmscout::Database(databaseParameter)); osmscout::MapServiceRef mapService(new osmscout::MapService(database)); if (!database->Open(map.c_str())) { std::cerr << "Cannot open database" << std::endl; return 1; } osmscout::StyleConfigRef styleConfig(new osmscout::StyleConfig(database->GetTypeConfig())); if (!styleConfig->Load(style)) { std::cerr << "Cannot open style" << std::endl; } osmscout::TileProjection projection; osmscout::MapParameter drawParameter; osmscout::AreaSearchParameter searchParameter; for (size_t zoom=std::min(startZoom,endZoom); zoom<=std::max(startZoom,endZoom); zoom++) { xTileStart=osmscout::LonToTileX(std::min(lonLeft,lonRight),zoom); xTileEnd=osmscout::LonToTileX(std::max(lonLeft,lonRight),zoom); xTileCount=xTileEnd-xTileStart+1; yTileStart=osmscout::LatToTileY(std::max(latTop,latBottom),zoom); yTileEnd=osmscout::LatToTileY(std::min(latTop,latBottom),zoom); yTileCount=yTileEnd-yTileStart+1; std::cout << "Drawing zoom " << zoom; //<< ", " << (xTileCount)*(yTileCount) << " tiles [" << xTileStart << "," << yTileStart << " - " << xTileEnd << "," << yTileEnd << "]"; std::cout << std::endl; #if defined(HAVE_LIB_OSMSCOUTMAPCAIRO) osmscout::MapPainterCairo cairoPainter(styleConfig); #endif osmscout::Magnification magnification; magnification.SetLevel(zoom); double dbMinTime=std::numeric_limits<double>::max(); double dbMaxTime=0.0; double dbTotalTime=0.0; double drawMinTime=std::numeric_limits<double>::max(); double drawMaxTime=0.0; double drawTotalTime=0.0; for (size_t y=yTileStart; y<=yTileEnd; y++) { for (size_t x=xTileStart; x<=xTileEnd; x++) { double lat,lon; osmscout::MapData data; lat=(osmscout::TileYToLat(y,zoom)+osmscout::TileYToLat(y+1,zoom))/2; lon=(osmscout::TileXToLon(x,zoom)+osmscout::TileXToLon(x+1,zoom))/2; //std::cout << "Drawing tile at " << lat << "," << lon << "/"; //std::cout << x << "," << y << "/"; //std::cout << x-xTileStart << "," << y-yTileStart << std::endl; projection.Set(lon, lat, magnification, DPI, tileWidth, tileHeight); osmscout::StopClock dbTimer; mapService->GetObjects(searchParameter, styleConfig, projection, data); dbTimer.Stop(); double dbTime=dbTimer.GetMilliseconds(); dbMinTime=std::min(dbMinTime,dbTime); dbMaxTime=std::max(dbMaxTime,dbTime); dbTotalTime+=dbTime; osmscout::StopClock drawTimer; #if defined(HAVE_LIB_OSMSCOUTMAPCAIRO) if (driver=="cairo") { //std::cout << data.nodes.size() << " " << data.ways.size() << " " << data.areas.size() << std::endl; cairoPainter.DrawMap(projection, drawParameter, data, cairo); } #endif drawTimer.Stop(); double drawTime=drawTimer.GetMilliseconds(); drawMinTime=std::min(drawMinTime,drawTime); drawMaxTime=std::max(drawMaxTime,drawTime); drawTotalTime+=drawTime; } } std::cout << "GetObjects: "; std::cout << "total: " << dbTotalTime << " msec "; std::cout << "min: " << dbMinTime << " msec "; std::cout << "avg: " << dbTotalTime/(xTileCount*yTileCount) << " msec "; std::cout << "max: " << dbMaxTime << " msec" << std::endl; std::cout << "DrawMap: "; std::cout << "total: " << drawTotalTime << " msec "; std::cout << "min: " << drawMinTime << " msec "; std::cout << "avg: " << drawTotalTime/(xTileCount*yTileCount) << " msec "; std::cout << "max: " << drawMaxTime << " msec" << std::endl; } database->Close(); #if defined(HAVE_LIB_OSMSCOUTMAPCAIRO) if (driver=="cairo") { cairo_destroy(cairo); cairo_surface_destroy(surface); } #endif return 0; }
int main(int argc, char* argv[]) { std::string map; std::string style; std::string output; size_t width,height; double lon,lat,zoom; if (argc!=9) { std::cerr << "DrawMap <map directory> <style-file> <width> <height> <lon> <lat> <zoom> <output>" << std::endl; return 1; } map=argv[1]; style=argv[2]; if (!osmscout::StringToNumber(argv[3],width)) { std::cerr << "width is not numeric!" << std::endl; return 1; } if (!osmscout::StringToNumber(argv[4],height)) { std::cerr << "height is not numeric!" << std::endl; return 1; } if (sscanf(argv[5],"%lf",&lon)!=1) { std::cerr << "lon is not numeric!" << std::endl; return 1; } if (sscanf(argv[6],"%lf",&lat)!=1) { std::cerr << "lat is not numeric!" << std::endl; return 1; } if (sscanf(argv[7],"%lf",&zoom)!=1) { std::cerr << "zoom is not numeric!" << std::endl; return 1; } output=argv[8]; osmscout::DatabaseParameter databaseParameter; osmscout::DatabaseRef database(new osmscout::Database(databaseParameter)); osmscout::MapServiceRef mapService(new osmscout::MapService(database)); if (!database->Open(map.c_str())) { std::cerr << "Cannot open database" << std::endl; return 1; } osmscout::StyleConfigRef styleConfig(new osmscout::StyleConfig(database->GetTypeConfig())); if (!styleConfig->Load(style)) { std::cerr << "Cannot open style" << std::endl; } cairo_surface_t *surface; cairo_t *cairo; surface=cairo_image_surface_create(CAIRO_FORMAT_RGB24,width,height); if (surface!=NULL) { cairo=cairo_create(surface); if (cairo!=NULL) { osmscout::MercatorProjection projection; osmscout::MapParameter drawParameter; osmscout::AreaSearchParameter searchParameter; osmscout::MapData data; osmscout::MapPainterCairo painter(styleConfig); drawParameter.SetFontSize(3.0); projection.Set(lon, lat, zoom, width, height); osmscout::TypeSet nodeTypes; std::vector<osmscout::TypeSet> wayTypes; osmscout::TypeSet areaTypes; styleConfig->GetNodeTypesWithMaxMag(projection.GetMagnification(), nodeTypes); styleConfig->GetWayTypesByPrioWithMaxMag(projection.GetMagnification(), wayTypes); styleConfig->GetAreaTypesWithMaxMag(projection.GetMagnification(), areaTypes); mapService->GetObjects(nodeTypes, wayTypes, areaTypes, projection.GetLonMin(), projection.GetLatMin(), projection.GetLonMax(), projection.GetLatMax(), projection.GetMagnification(), searchParameter, data.nodes, data.ways, data.areas); if (painter.DrawMap(projection, drawParameter, data, cairo)) { if (cairo_surface_write_to_png(surface,output.c_str())!=CAIRO_STATUS_SUCCESS) { std::cerr << "Cannot write PNG" << std::endl; } } cairo_destroy(cairo); } else { std::cerr << "Cannot create cairo cairo" << std::endl; } cairo_surface_destroy(surface); } else { std::cerr << "Cannot create cairo surface" << std::endl; } return 0; }
int main(int argc, char* argv[]) { std::string map; std::string style; size_t width,height; std::vector<Action> actions; if (argc<5) { DumpHelp(); return 1; } if ((argc-5)%3!=0) { DumpHelp(); return 1; } map=argv[1]; style=argv[2]; if (!osmscout::StringToNumber(argv[3],width)) { std::cerr << "width is not numeric!" << std::endl; return 1; } if (!osmscout::StringToNumber(argv[4],height)) { std::cerr << "height is not numeric!" << std::endl; return 1; } int arg=5; while (arg<argc) { Action action; if (sscanf(argv[arg],"%lf",&action.lat)!=1) { std::cerr << "lat is not numeric!" << std::endl; return 1; } arg++; if (sscanf(argv[arg],"%lf",&action.lon)!=1) { std::cerr << "lon is not numeric!" << std::endl; return 1; } arg++; if (sscanf(argv[arg],"%lf",&action.magnification)!=1) { std::cerr << "zoom is not numeric!" << std::endl; return 1; } arg++; actions.push_back(action); } std::cout << "# General program resources initialized, press return to start rendering emulation!" << std::endl; std::cin.get(); { osmscout::DatabaseParameter databaseParameter; databaseParameter.SetAreaAreaIndexCacheSize(0); databaseParameter.SetAreaNodeIndexCacheSize(0); databaseParameter.SetNodeCacheSize(0); databaseParameter.SetWayCacheSize(0); databaseParameter.SetAreaCacheSize(0); osmscout::DatabaseRef database(new osmscout::Database(databaseParameter)); osmscout::MapServiceRef mapService(new osmscout::MapService(database)); if (!database->Open(map.c_str())) { std::cerr << "Cannot open database" << std::endl; return 1; } database->DumpStatistics(); osmscout::StyleConfigRef styleConfig(new osmscout::StyleConfig(database->GetTypeConfig())); if (!styleConfig->Load(style)) { std::cerr << "Cannot open style" << std::endl; } for (std::vector<Action>::const_iterator action=actions.begin(); action!=actions.end(); ++action) { std::cout << "-------------------" << std::endl; std::cout << "# Rendering " << action->lat << "," << action->lon << " with zoom " << action->magnification << " and size " << width << "x" << height << std::endl; osmscout::MercatorProjection projection; osmscout::AreaSearchParameter searchParameter; osmscout::MapData data; projection.Set(action->lon, action->lat, action->magnification, width, height); osmscout::TypeSet nodeTypes; std::vector<osmscout::TypeSet> wayTypes; osmscout::TypeSet areaTypes; styleConfig->GetNodeTypesWithMaxMag(projection.GetMagnification(), nodeTypes); styleConfig->GetWayTypesByPrioWithMaxMag(projection.GetMagnification(), wayTypes); styleConfig->GetAreaTypesWithMaxMag(projection.GetMagnification(), areaTypes); osmscout::StopClock dbTimer; mapService->GetObjects(nodeTypes, wayTypes, areaTypes, projection.GetLonMin(), projection.GetLatMin(), projection.GetLonMax(), projection.GetLatMax(), projection.GetMagnification(), searchParameter, data.nodes, data.ways, data.areas); dbTimer.Stop(); std::cout << "# DB access time " << dbTimer << std::endl; database->DumpStatistics(); } std::cout << "# Press return to flush caches" << std::endl; std::cin.get(); database->FlushCache(); std::cout << "# Press return to close database" << std::endl; std::cin.get(); } std::cout << "# Press return to end application" << std::endl; std::cin.get(); return 0; }
int main(int argc, char* argv[]) { std::string map; std::string style; size_t width,height; std::vector<Action> actions; if (argc<5) { DumpHelp(); return 1; } if ((argc-5)%3!=0) { DumpHelp(); return 1; } map=argv[1]; style=argv[2]; if (!osmscout::StringToNumber(argv[3],width)) { std::cerr << "width is not numeric!" << std::endl; return 1; } if (!osmscout::StringToNumber(argv[4],height)) { std::cerr << "height is not numeric!" << std::endl; return 1; } int arg=5; while (arg<argc) { Action action; if (sscanf(argv[arg],"%lf",&action.lat)!=1) { std::cerr << "lat is not numeric!" << std::endl; return 1; } arg++; if (sscanf(argv[arg],"%lf",&action.lon)!=1) { std::cerr << "lon is not numeric!" << std::endl; return 1; } arg++; if (sscanf(argv[arg],"%lf",&action.magnification)!=1) { std::cerr << "zoom is not numeric!" << std::endl; return 1; } arg++; actions.push_back(action); } std::cout << "# General program resources initialized, press return to start rendering emulation!" << std::endl; std::cin.get(); { osmscout::DatabaseParameter databaseParameter; databaseParameter.SetAreaAreaIndexCacheSize(0); databaseParameter.SetAreaNodeIndexCacheSize(0); osmscout::DatabaseRef database(new osmscout::Database(databaseParameter)); osmscout::MapServiceRef mapService(new osmscout::MapService(database)); if (!database->Open(map.c_str())) { std::cerr << "Cannot open database" << std::endl; return 1; } database->DumpStatistics(); osmscout::StyleConfigRef styleConfig(new osmscout::StyleConfig(database->GetTypeConfig())); if (!styleConfig->Load(style)) { std::cerr << "Cannot open style" << std::endl; } for (std::vector<Action>::const_iterator action=actions.begin(); action!=actions.end(); ++action) { std::cout << "-------------------" << std::endl; std::cout << "# Rendering " << action->lat << "," << action->lon << " with zoom " << action->magnification << " and size " << width << "x" << height << std::endl; osmscout::MercatorProjection projection; osmscout::AreaSearchParameter searchParameter; osmscout::MapData data; projection.Set(osmscout::GeoCoord(action->lat, action->lon), osmscout::Magnification(action->magnification), 96.0, width, height); osmscout::StopClock dbTimer; std::list<osmscout::TileRef> tiles; mapService->LookupTiles(projection,tiles); mapService->LoadMissingTileData(searchParameter,*styleConfig,tiles); mapService->ConvertTilesToMapData(tiles,data); dbTimer.Stop(); std::cout << "# DB access time " << dbTimer << std::endl; database->DumpStatistics(); } std::cout << "# Press return to close database" << std::endl; std::cin.get(); database->Close(); } std::cout << "# Press return to end application" << std::endl; std::cin.get(); return 0; }
int main(int argc, char* argv[]) { std::string map; std::string style; std::string output; size_t width,height; double lon,lat,zoom; if (argc!=9) { std::cerr << "DrawMap <map directory> <style-file> <width> <height> <lon> <lat> <zoom> <output>" << std::endl; return 1; } map=argv[1]; style=argv[2]; if (!osmscout::StringToNumber(argv[3],width)) { std::cerr << "width is not numeric!" << std::endl; return 1; } if (!osmscout::StringToNumber(argv[4],height)) { std::cerr << "height is not numeric!" << std::endl; return 1; } if (sscanf(argv[5],"%lf",&lon)!=1) { std::cerr << "lon is not numeric!" << std::endl; return 1; } if (sscanf(argv[6],"%lf",&lat)!=1) { std::cerr << "lat is not numeric!" << std::endl; return 1; } if (sscanf(argv[7],"%lf",&zoom)!=1) { std::cerr << "zoom is not numeric!" << std::endl; return 1; } output=argv[8]; osmscout::DatabaseParameter databaseParameter; osmscout::DatabaseRef database(new osmscout::Database(databaseParameter)); osmscout::MapServiceRef mapService(new osmscout::MapService(database)); if (!database->Open(map.c_str())) { std::cerr << "Cannot open database" << std::endl; return 1; } osmscout::StyleConfigRef styleConfig(new osmscout::StyleConfig(database->GetTypeConfig())); if (!styleConfig->Load(style)) { std::cerr << "Cannot open style" << std::endl; } cairo_surface_t *surface; cairo_t *cairo; surface=cairo_image_surface_create(CAIRO_FORMAT_RGB24,width,height); if (surface!=NULL) { cairo=cairo_create(surface); if (cairo!=NULL) { osmscout::MercatorProjection projection; osmscout::MapParameter drawParameter; osmscout::AreaSearchParameter searchParameter; osmscout::MapData data; osmscout::MapPainterCairo painter(styleConfig); drawParameter.SetFontSize(3.0); projection.Set(osmscout::GeoCoord(lat,lon), osmscout::Magnification(zoom), DPI, width, height); std::list<osmscout::TileRef> tiles; mapService->LookupTiles(projection,tiles); mapService->LoadMissingTileData(searchParameter,*styleConfig,tiles); mapService->ConvertTilesToMapData(tiles,data); if (painter.DrawMap(projection, drawParameter, data, cairo)) { if (cairo_surface_write_to_png(surface,output.c_str())!=CAIRO_STATUS_SUCCESS) { std::cerr << "Cannot write PNG" << std::endl; } } cairo_destroy(cairo); } else { std::cerr << "Cannot create cairo cairo" << std::endl; } cairo_surface_destroy(surface); } else { std::cerr << "Cannot create cairo surface" << std::endl; } return 0; }