1 #ifndef OSMSCOUT_IMPORT_WATERINDEXPROCESSOR_H 2 #define OSMSCOUT_IMPORT_WATERINDEXPROCESSOR_H 55 template<
typename InputIterator>
56 void WriteGpx(InputIterator begin, InputIterator end,
const std::string &name)
58 std::ofstream gpxFile;
60 gpxFile.open(name.c_str());
61 gpxFile.imbue(std::locale(
"C"));
62 gpxFile.precision(100);
64 gpxFile <<
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
65 gpxFile <<
"<gpx creator=\"osmscout\" version=\"1.1\" xmlns=\"http://www.topografix.com/GPX/1/1\"";
66 gpxFile <<
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"";
67 gpxFile <<
" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">\n";
69 gpxFile <<
" <trk><trkseg>\n";
70 for (InputIterator it=begin; it!=end;it++) {
71 gpxFile <<
"<trkpt lat=\"" << it->GetLat() <<
"\" lon=\"" << it->GetLon() <<
"\"></trkpt>\n";
73 gpxFile <<
" </trkseg></trk>\n</gpx>";
78 extern void WriteGpx(
const std::vector<Point> &path,
const std::string& name);
171 std::vector<uint8_t> area;
174 void SetBox(
const GeoBox& boundingBox,
220 return x>=cellXStart &&
226 State GetState(uint32_t x, uint32_t y)
const;
229 return GetState(x-cellXStart,
233 void SetState(uint32_t x, uint32_t y,
State state);
236 SetState(x-cellXStart,
259 void SetBox(
const GeoBox& boundingBox,
324 struct IntersectionByPathComparator
328 if (a->prevWayPointIndex==b->prevWayPointIndex) {
329 return a->distanceSquare<b->distanceSquare;
332 return a->prevWayPointIndex<b->prevWayPointIndex;
339 struct IntersectionCWComparator
341 inline bool operator()(
const IntersectionRef& a,
const IntersectionRef& b)
const 343 if (a->borderIndex==b->borderIndex) {
344 switch (a->borderIndex) {
346 if (a->point.GetLon()==b->point.GetLon()){
347 return a->prevPoint.GetLon()<b->prevPoint.GetLon();
349 return a->point.GetLon()<b->point.GetLon();
352 if (a->point.GetLat()==b->point.GetLat()){
353 return a->prevPoint.GetLat()>b->prevPoint.GetLat();
355 return a->point.GetLat()>b->point.GetLat();
358 if (a->point.GetLon()==b->point.GetLon()){
359 return a->prevPoint.GetLon()>b->prevPoint.GetLon();
361 return a->point.GetLon()>b->point.GetLon();
364 if (a->point.GetLat()==b->point.GetLat()){
365 return a->prevPoint.GetLat()<b->prevPoint.GetLat();
367 return a->point.GetLat()<b->point.GetLat();
371 return a->borderIndex<b->borderIndex;
379 struct CellBoundaries
386 using BorderCoords = std::array<GroundTile::Coord, 4>;
387 using BorderPoints = std::array<GeoCoord, 4>;
388 BorderCoords borderCoords;
389 BorderPoints borderPoints;
391 inline CellBoundaries(
const StateMap &stateMap,
const Pixel &cell)
393 lonMin=(stateMap.GetXStart()+cell.x)*stateMap.GetCellWidth()-180.0;
394 lonMax=(stateMap.GetXStart()+cell.x+1)*stateMap.GetCellWidth()-180.0;
395 latMin=(stateMap.GetYStart()+cell.y)*stateMap.GetCellHeight()-90.0;
396 latMax=(stateMap.GetYStart()+cell.y+1)*stateMap.GetCellHeight()-90.0;
398 borderPoints[0]=GeoCoord(latMax,lonMin);
399 borderPoints[1]=GeoCoord(latMax,lonMax);
400 borderPoints[2]=GeoCoord(latMin,lonMax);
401 borderPoints[3]=GeoCoord(latMin,lonMin);
403 borderCoords[0].Set(0,GroundTile::Coord::CELL_MAX,
false);
404 borderCoords[1].Set(GroundTile::Coord::CELL_MAX,GroundTile::Coord::CELL_MAX,
false);
405 borderCoords[2].Set(GroundTile::Coord::CELL_MAX,0,
false);
406 borderCoords[3].Set(0,0,
false);
411 std::string StateToString(State state)
const;
412 std::string TypeToString(GroundTile::Type type)
const;
429 GroundTile::Coord
Transform(
const GeoCoord& point,
430 const StateMap& stateMap,
448 void GetCells(
const StateMap& stateMap,
451 std::set<Pixel>& cellIntersections)
const;
462 void GetCellIntersections(
const StateMap& stateMap,
463 const std::vector<GeoCoord>& points,
465 std::map<Pixel,std::list<IntersectionRef>>& cellIntersections);
470 bool IsCellInBoundingPolygon(
const CellBoundaries& cellBoundary,
471 const std::list<CoastRef>& boundingPolygons);
476 bool ContainsCoord(
const std::list<GroundTile> &tiles,
477 const GroundTile::Coord &coord,
478 GroundTile::Type type);
483 bool ContainsCoord(
const std::list<GroundTile> &tiles,
484 const GroundTile::Coord &coord);
489 bool ContainsWater(
const Pixel &coord,
490 const StateMap &stateMap,
491 const std::map<Pixel,std::list<GroundTile>>& cellGroundTileMap,
492 const GroundTile::Coord &testCoord1,
493 const GroundTile::Coord &testCoord2);
500 void WalkBorderCW(GroundTile& groundTile,
501 const StateMap& stateMap,
504 const IntersectionRef& incoming,
505 const IntersectionRef& outgoing,
506 const CellBoundaries::BorderCoords &borderCoords);
511 IntersectionRef GetNextCW(
const std::list<IntersectionRef>& intersectionsCW,
512 const IntersectionRef& current)
const;
518 void WalkPathBack(GroundTile& groundTile,
519 const StateMap& stateMap,
522 const IntersectionRef& pathStart,
523 const IntersectionRef& pathEnd,
524 const std::vector<GeoCoord>& points,
531 void WalkPathForward(GroundTile& groundTile,
532 const StateMap& stateMap,
535 const IntersectionRef& pathStart,
536 const IntersectionRef& pathEnd,
537 const std::vector<GeoCoord>& points,
546 IntersectionRef FindSiblingIntersection(
const IntersectionRef &intersection,
547 const std::list<IntersectionRef> &intersectionsCW,
560 bool WalkFromTripoint(GroundTile &groundTile,
561 const StateMap& stateMap,
562 const CellBoundaries &cellBoundaries,
563 IntersectionRef &pathStart,
564 IntersectionRef &pathEnd,
566 const std::list<IntersectionRef> &intersectionsCW,
567 const std::vector<size_t> &containingPaths);
573 void WalkPath(GroundTile &groundTile,
574 const StateMap& stateMap,
575 const CellBoundaries &cellBoundaries,
576 const IntersectionRef pathStart,
577 const IntersectionRef pathEnd,
578 CoastlineDataRef coastline);
585 bool WalkBoundaryCW(GroundTile &groundTile,
586 const StateMap &stateMap,
587 const IntersectionRef outIntersection,
588 const std::list<IntersectionRef> &intersectionsCW,
589 std::set<IntersectionRef> &visitedIntersections,
590 const CellBoundaries &cellBoundaries,
592 const std::vector<size_t> &containingPaths);
605 void SynthesizeCoastlines2(Progress& progress,
606 const std::list<CoastRef>& boundingPolygons,
607 const std::list<CoastRef>& coastlines,
608 std::list<CoastRef>& synthesized);
613 void HandleCoastlineCell(Progress& progress,
615 const std::list<size_t>& intersectCoastlines,
616 const StateMap& stateMap,
617 std::map<Pixel,std::list<GroundTile> >& cellGroundTileMap,
620 void TransformCoastlines(Progress& progress,
621 TransPolygon::OptimizeMethod optimizationMethod,
623 double minObjectDimension,
624 const Projection& projection,
625 const std::list<CoastRef>& coastlines,
626 std::vector<CoastlineDataRef> &transformedCoastlines);
628 void FilterIntersectCoastlines(Progress& progress,
629 std::vector<CoastlineDataRef> &transformedCoastlines);
631 void FilterEncapsulatedCoastlines(Progress& progress,
632 std::vector<CoastlineDataRef> &transformedCoastlines);
634 void ComputeCoveredTiles(Progress& progress,
635 const StateMap& stateMap,
637 std::vector<CoastlineDataRef> &transformedCoastlines);
642 static bool CoastlineGeoSizeSorter(
const CoastlineDataRef &a,
const CoastlineDataRef &b);
648 void MergeCoastlines(Progress& progress,
649 std::list<WaterIndexProcessor::CoastRef>& coastlines);
661 void GetCells(
const StateMap& stateMap,
662 const std::vector<GeoCoord>& points,
663 std::set<Pixel>& cellIntersections)
const;
675 void GetCells(
const StateMap& stateMap,
676 const std::vector<Point>& points,
677 std::set<Pixel>& cellIntersections)
const;
687 void SynthesizeCoastlines(Progress& progress,
688 std::list<CoastRef>& coastlines,
689 std::list<CoastRef>& boundingPolygons);
694 void CalculateCoastlineData(Progress& progress,
695 TransPolygon::OptimizeMethod optimizationMethod,
697 double minObjectDimension,
698 const Projection& projection,
699 const StateMap& stateMap,
700 const std::list<CoastRef>& coastlines,
706 void MarkCoastlineCells(Progress& progress,
718 void HandleAreaCoastlinesCompletelyInACell(Progress& progress,
719 const StateMap& stateMap,
721 std::map<Pixel,std::list<GroundTile> >& cellGroundTileMap);
726 void HandleCoastlinesPartiallyInACell(Progress& progress,
727 const StateMap& stateMap,
728 std::map<Pixel,std::list<GroundTile> >& cellGroundTileMap,
738 void CalculateCoastEnvironment(Progress& progress,
740 const std::map<Pixel,std::list<GroundTile> >& cellGroundTileMap);
745 void FillWaterAroundIsland(Progress& progress,
747 std::map<Pixel,std::list<GroundTile> >& cellGroundTileMap,
748 const std::list<CoastRef>& boundingPolygons);
756 void FillWater(Progress& progress,
759 const std::list<CoastRef>& boundingPolygons);
767 void FillLand(Progress& progress,
773 void CalculateHasCellData(Level& level,
774 const std::map<Pixel,std::list<GroundTile> >& cellGroundTileMap)
const;
779 void DumpIndexHeader(FileWriter& writer,
780 std::vector<Level>& levels);
785 void WriteTiles(Progress& progress,
786 const std::map<Pixel,std::list<GroundTile>>& cellGroundTileMap,
Direction direction
The distance^2 between the path point and the intersectionPoint.
Definition: WaterIndexProcessor.h:284
uint32_t GetXStart() const
Definition: WaterIndexProcessor.h:188
State
Definition: WaterIndexProcessor.h:149
uint64_t Id
Definition: OSMScoutTypes.h:41
Definition: WaterIndexProcessor.h:245
std::map< Pixel, std::list< IntersectionRef > > cellIntersections
The points of the coastline.
Definition: WaterIndexProcessor.h:302
bool IsInAbsolute(uint32_t x, uint32_t y) const
Definition: WaterIndexProcessor.h:218
double GetCellHeight() const
Definition: WaterIndexProcessor.h:183
CoastState left
Definition: WaterIndexProcessor.h:140
int64_t OSMId
Definition: OSMScoutTypes.h:34
CoastState right
Definition: WaterIndexProcessor.h:304
uint8_t dataOffsetBytes
Number of bytes per entry in bitmap.
Definition: WaterIndexProcessor.h:253
uint32_t GetYStart() const
Definition: WaterIndexProcessor.h:193
State GetStateAbsolute(uint32_t x, uint32_t y) const
Definition: WaterIndexProcessor.h:227
double distanceSquare
The intersection point.
Definition: WaterIndexProcessor.h:283
Definition: WaterIndexProcessor.h:312
#define OSMSCOUT_IMPORT_API
Definition: ImportImportExport.h:45
Id backNodeId
Definition: WaterIndexProcessor.h:138
std::shared_ptr< CoastlineData > CoastlineDataRef
Definition: WaterIndexProcessor.h:307
uint32_t GetXCount() const
Definition: WaterIndexProcessor.h:208
StateMap stateMap
Index to handle state of cells.
Definition: WaterIndexProcessor.h:257
GeoBox boundingBox
true, if the complete coastline is within one cell
Definition: WaterIndexProcessor.h:299
CoastState
Definition: WaterIndexProcessor.h:116
std::map< Pixel, std::list< size_t > > cellCoastlines
data for each coastline
Definition: WaterIndexProcessor.h:315
OSMId id
Definition: WaterIndexProcessor.h:134
uint32_t level
The actual zoom level.
Definition: WaterIndexProcessor.h:248
std::vector< CoastlineDataRef > coastlines
Definition: WaterIndexProcessor.h:314
bool hasCellData
If true, we have cell data.
Definition: WaterIndexProcessor.h:252
CoastState right
Definition: WaterIndexProcessor.h:141
std::vector< GeoCoord > points
The cell that completely contains the coastline.
Definition: WaterIndexProcessor.h:301
Definition: WaterIndexProcessor.h:160
GeoCoord point
just helper for sorting
Definition: WaterIndexProcessor.h:282
Definition: WaterIndexProcessor.h:132
std::vector< Point > coast
Definition: WaterIndexProcessor.h:139
Definition: WaterIndexProcessor.h:294
FileOffset indexDataOffset
File offset of start cell state data on disk.
Definition: WaterIndexProcessor.h:255
#define CLASS_FINAL
Definition: Compiler.h:26
bool isArea
Definition: WaterIndexProcessor.h:135
Id frontNodeId
Definition: WaterIndexProcessor.h:137
CoastState left
All intersections for each cell.
Definition: WaterIndexProcessor.h:303
Pixel cell
GeoBox from points (already transformed)
Definition: WaterIndexProcessor.h:300
std::map< Pixel, std::list< size_t > > cellCoveredCoastlines
Contains for each cell the list of intersecting coastlines.
Definition: WaterIndexProcessor.h:316
Id id
Definition: WaterIndexProcessor.h:296
uint32_t GetYEnd() const
Definition: WaterIndexProcessor.h:203
bool isArea
The id of the coastline.
Definition: WaterIndexProcessor.h:297
double GetCellWidth() const
Definition: WaterIndexProcessor.h:178
Definition: WaterIndexProcessor.h:277
uint8_t borderIndex
1 in, 0 touch, -1 out
Definition: WaterIndexProcessor.h:285
State defaultCellData
If hasCellData is false, this is the value to be returned for all cells.
Definition: WaterIndexProcessor.h:254
size_t coastline
Definition: WaterIndexProcessor.h:279
bool isCompletelyInCell
true,if the boundary forms an area
Definition: WaterIndexProcessor.h:298
uint64_t FileOffset
Definition: OSMScoutTypes.h:47
uint32_t GetXEnd() const
Definition: WaterIndexProcessor.h:198
std::shared_ptr< Intersection > IntersectionRef
Definition: WaterIndexProcessor.h:288
std::shared_ptr< Coast > CoastRef
Definition: WaterIndexProcessor.h:144
codepoint(*)(const character *, int context) Transform
functor implements desired transformation of the character It has 2 arguments:
Definition: utf8helper.h:49
uint32_t GetYCount() const
Definition: WaterIndexProcessor.h:213
void SetStateAbsolute(uint32_t x, uint32_t y, State state)
Definition: WaterIndexProcessor.h:234
size_t prevWayPointIndex
Running number of the intersecting coastline.
Definition: WaterIndexProcessor.h:280
void WriteGpx(InputIterator begin, InputIterator end, const std::string &name)
Definition: WaterIndexProcessor.h:56
GeoCoord prevPoint
The index of the path point before the intersection.
Definition: WaterIndexProcessor.h:281
Direction
Definition: WaterIndexProcessor.h:267
FileOffset indexEntryOffset
File offset of this entry on disk.
Definition: WaterIndexProcessor.h:249
double sortCriteria
Definition: WaterIndexProcessor.h:136