forked from organicmaps/organicmaps
PR fixes
This commit is contained in:
parent
9ec59f5968
commit
85a845717c
4 changed files with 49 additions and 48 deletions
|
@ -1,3 +0,0 @@
|
|||
Threads = 4
|
||||
IP = 0.0.0.0
|
||||
Port = 5000
|
|
@ -10,35 +10,4 @@
|
|||
|
||||
namespace osm
|
||||
{
|
||||
bool ReadPolygon(istream & stream, m2::RegionD & region, string const & filename)
|
||||
{
|
||||
string line, name;
|
||||
double lon, lat;
|
||||
|
||||
// read ring id, fail if it's empty
|
||||
getline(stream, name);
|
||||
if (name.empty() || name == "END")
|
||||
return false;
|
||||
|
||||
while (stream.good())
|
||||
{
|
||||
getline(stream, line);
|
||||
strings::Trim(line);
|
||||
|
||||
if (line.empty())
|
||||
continue;
|
||||
|
||||
if (line == "END")
|
||||
break;
|
||||
|
||||
istringstream iss(line);
|
||||
iss >> lon >> lat;
|
||||
CHECK(!iss.fail(), ("Incorrect data in", filename));
|
||||
|
||||
region.AddPoint(MercatorBounds::FromLatLon(lat, lon));
|
||||
}
|
||||
|
||||
// drop inner rings
|
||||
return name[0] != '!';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,11 +4,41 @@
|
|||
#include "../base/logging.hpp"
|
||||
|
||||
#include "../coding/file_reader.hpp"
|
||||
#include "../coding/file_writer.hpp"
|
||||
#include "../coding/streams_sink.hpp"
|
||||
|
||||
namespace borders
|
||||
{
|
||||
bool ReadPolygon(istream & stream, m2::RegionD & region, string const & filename)
|
||||
{
|
||||
string line, name;
|
||||
double lon, lat;
|
||||
|
||||
// read ring id, fail if it's empty
|
||||
getline(stream, name);
|
||||
if (name.empty() || name == "END")
|
||||
return false;
|
||||
|
||||
while (stream.good())
|
||||
{
|
||||
getline(stream, line);
|
||||
strings::Trim(line);
|
||||
|
||||
if (line.empty())
|
||||
continue;
|
||||
|
||||
if (line == "END")
|
||||
break;
|
||||
|
||||
istringstream iss(line);
|
||||
iss >> lon >> lat;
|
||||
CHECK(!iss.fail(), ("Incorrect data in", filename));
|
||||
|
||||
region.AddPoint(MercatorBounds::FromLatLon(lat, lon));
|
||||
}
|
||||
|
||||
// drop inner rings
|
||||
return name[0] != '!';
|
||||
}
|
||||
|
||||
bool LoadBorders(string const & borderFile, vector<m2::RegionD> & outBorders)
|
||||
{
|
||||
|
@ -16,8 +46,12 @@ bool LoadBorders(string const & borderFile, vector<m2::RegionD> & outBorders)
|
|||
string line;
|
||||
if (!getline(stream, line).good()) // skip title
|
||||
{
|
||||
LOG(LERROR, ("Polygon file is empty:", borderFile));
|
||||
return false;
|
||||
FileReader file(borderFile);
|
||||
ReaderSource<FileReader> source(file);
|
||||
stream::SinkReaderStream<ReaderSource<FileReader> > stream(source);
|
||||
|
||||
stream >> outBorders;
|
||||
CHECK(!outBorders.empty(), ("Borders weren't loaded from", borderFile));
|
||||
}
|
||||
|
||||
m2::RegionD currentRegion;
|
||||
|
@ -34,12 +68,6 @@ bool LoadBorders(string const & borderFile, vector<m2::RegionD> & outBorders)
|
|||
|
||||
class PolygonLoader
|
||||
{
|
||||
CountryPolygons m_polygons;
|
||||
m2::RectD m_rect;
|
||||
|
||||
string const & m_baseDir;
|
||||
CountriesContainerT & m_countries;
|
||||
|
||||
public:
|
||||
PolygonLoader(string const & baseDir, CountriesContainerT & countries)
|
||||
: m_baseDir(baseDir), m_countries(countries) {}
|
||||
|
@ -52,11 +80,11 @@ public:
|
|||
vector<m2::RegionD> borders;
|
||||
if (LoadBorders(m_baseDir + BORDERS_DIR + name + BORDERS_EXTENSION, borders))
|
||||
{
|
||||
for (size_t i = 0; i < borders.size(); ++i)
|
||||
for (auto const & border : borders)
|
||||
{
|
||||
m2::RectD const rect(borders[i].GetRect());
|
||||
m2::RectD const rect(border.GetRect());
|
||||
m_rect.Add(rect);
|
||||
m_polygons.m_regions.Add(borders[i], rect);
|
||||
m_polygons.m_regions.Add(border, rect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -72,13 +100,20 @@ public:
|
|||
m_polygons.Clear();
|
||||
m_rect.MakeEmpty();
|
||||
}
|
||||
|
||||
private:
|
||||
CountryPolygons m_polygons;
|
||||
m2::RectD m_rect;
|
||||
|
||||
string const & m_baseDir;
|
||||
CountriesContainerT & m_countries;
|
||||
};
|
||||
|
||||
bool LoadCountriesList(string const & baseDir, CountriesContainerT & countries)
|
||||
{
|
||||
countries.Clear();
|
||||
|
||||
LOG(LINFO, ("Loading countries."));
|
||||
LOG(LINFO, ("Loading countries..."));
|
||||
|
||||
PolygonLoader loader(baseDir, countries);
|
||||
ForEachCountry(baseDir, loader);
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
#include "../geometry/region2d.hpp"
|
||||
#include "../geometry/tree4d.hpp"
|
||||
|
||||
#include "../std/string.hpp"
|
||||
#include "../std/fstream.hpp"
|
||||
#include "../std/string.hpp"
|
||||
|
||||
#define BORDERS_DIR "borders/"
|
||||
#define BORDERS_EXTENSION ".poly"
|
||||
|
|
Loading…
Add table
Reference in a new issue