[generator] Convert our .borders files into OSM .poly format with generator_tool -export_poly_path <path>

This commit is contained in:
Alex Zolotarev 2014-09-14 13:35:41 -07:00 committed by Alex Zolotarev
parent ad13b65f4b
commit 23e3e307c9
3 changed files with 43 additions and 0 deletions

View file

@ -7,6 +7,7 @@
#include "../indexer/geometry_serialization.hpp"
#include "../indexer/scales.hpp"
#include "../indexer/mercator.hpp"
#include "../geometry/simplification.hpp"
#include "../geometry/distance.hpp"
@ -173,4 +174,35 @@ void GeneratePackedBorders(string const & baseDir)
generator.WritePolygonsInfo();
}
void ExportOSMPolylines(string const & outDir, CountriesContainerT const & countries)
{
countries.ForEach( [&](CountryPolygons const & cp)
{
// .poly file format described here: http://wiki.openstreetmap.org/wiki/Osmosis/Polygon_Filter_File_Format
ostringstream stream;
stream << cp.m_name << endl;
size_t regionNumber = 0;
cp.m_regions.ForEach( [&](Region const & r)
{
stream << ++regionNumber << endl;
r.ForEachPoint( [&](m2::PointD const & pt)
{
stream << '\t' << std::scientific << MercatorBounds::XToLon(pt.x) << '\t' << MercatorBounds::YToLat(pt.y) << endl;
} );
stream << "END" << endl;
} );
stream << "END" << endl;
FileWriter w(outDir + "/" + cp.m_name + ".poly");
string const contents = stream.str();
w.Write(contents.data(), contents.size());
} );
}
} // namespace borders

View file

@ -32,4 +32,7 @@ namespace borders
bool LoadCountriesList(string const & baseDir, CountriesContainerT & countries);
void GeneratePackedBorders(string const & baseDir);
/// Converts our borders into OSM .poly file format
void ExportOSMPolylines(string const & outDir, CountriesContainerT const & countries);
}

View file

@ -61,6 +61,7 @@ DEFINE_bool(check_mwm, false, "Check map file to be correct.");
DEFINE_string(delete_section, "", "Delete specified section (defines.hpp) from container.");
DEFINE_bool(fail_on_coasts, false, "Stop and exit with '255' code if some coastlines are not merged.");
DEFINE_string(address_file_name, "", "Output file name for storing full addresses.");
DEFINE_string(export_poly_path, "", "Output dir for osm .poly files created from .borders (countires are read from polygons.lst)");
string AddSlashIfNeeded(string const & str)
@ -254,5 +255,12 @@ int main(int argc, char ** argv)
if (FLAGS_check_mwm)
check_model::ReadFeatures(datFile);
if (!FLAGS_export_poly_path.empty())
{
borders::CountriesContainerT countries;
borders::LoadCountriesList(path, countries);
borders::ExportOSMPolylines(FLAGS_export_poly_path, countries);
}
return 0;
}