1#ifndef OSMSCOUT_IMPORT_WATERINDEXPROCESSOR_H
2#define OSMSCOUT_IMPORT_WATERINDEXPROCESSOR_H
57 template<
typename InputIterator>
58 void WriteGpx(InputIterator begin, InputIterator end,
const std::string &name)
60 std::ofstream gpxFile;
62 gpxFile.open(name.c_str());
63 gpxFile.imbue(std::locale(
"C"));
64 gpxFile.precision(100);
66 gpxFile <<
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
67 gpxFile <<
"<gpx creator=\"osmscout\" version=\"1.1\" xmlns=\"http://www.topografix.com/GPX/1/1\"";
68 gpxFile <<
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"";
69 gpxFile <<
" xsi:schemaLocation=\"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd\">\n";
71 gpxFile <<
" <trk><trkseg>\n";
72 for (InputIterator it=begin; it!=end;it++) {
73 gpxFile <<
"<trkpt lat=\"" << it->GetLat() <<
"\" lon=\"" << it->GetLon() <<
"\"></trkpt>\n";
75 gpxFile <<
" </trkseg></trk>\n</gpx>";
80 extern void WriteGpx(
const std::vector<Point> &path,
const std::string& name);
172 std::vector<uint8_t> area;
221 return x>=cellXStart &&
325 struct IntersectionByPathComparator
329 if (a->prevWayPointIndex==b->prevWayPointIndex) {
330 return a->distanceSquare<b->distanceSquare;
333 return a->prevWayPointIndex<b->prevWayPointIndex;
340 struct IntersectionCWComparator
342 inline bool operator()(
const IntersectionRef& a,
const IntersectionRef& b)
const
344 if (a->borderIndex==b->borderIndex) {
345 switch (a->borderIndex) {
347 if (a->point.GetLon()==b->point.GetLon()){
348 return a->prevPoint.GetLon()<b->prevPoint.GetLon();
350 return a->point.GetLon()<b->point.GetLon();
353 if (a->point.GetLat()==b->point.GetLat()){
354 return a->prevPoint.GetLat()>b->prevPoint.GetLat();
356 return a->point.GetLat()>b->point.GetLat();
359 if (a->point.GetLon()==b->point.GetLon()){
360 return a->prevPoint.GetLon()>b->prevPoint.GetLon();
362 return a->point.GetLon()>b->point.GetLon();
365 if (a->point.GetLat()==b->point.GetLat()){
366 return a->prevPoint.GetLat()<b->prevPoint.GetLat();
368 return a->point.GetLat()<b->point.GetLat();
372 return a->borderIndex<b->borderIndex;
380 struct CellBoundaries
387 using BorderCoords = std::array<GroundTile::Coord, 4>;
388 using BorderPoints = std::array<GeoCoord, 4>;
389 BorderCoords borderCoords;
390 BorderPoints borderPoints;
392 inline CellBoundaries(
const StateMap &stateMap,
const Pixel &cell)
394 lonMin=(stateMap.GetXStart()+cell.x)*stateMap.GetCellWidth()-180.0;
395 lonMax=(stateMap.GetXStart()+cell.x+1)*stateMap.GetCellWidth()-180.0;
396 latMin=(stateMap.GetYStart()+cell.y)*stateMap.GetCellHeight()-90.0;
397 latMax=(stateMap.GetYStart()+cell.y+1)*stateMap.GetCellHeight()-90.0;
399 borderPoints[0]=GeoCoord(latMax,lonMin);
400 borderPoints[1]=GeoCoord(latMax,lonMax);
401 borderPoints[2]=GeoCoord(latMin,lonMax);
402 borderPoints[3]=GeoCoord(latMin,lonMin);
404 borderCoords[0].Set(0,GroundTile::Coord::CELL_MAX,
false);
405 borderCoords[1].Set(GroundTile::Coord::CELL_MAX,GroundTile::Coord::CELL_MAX,
false);
406 borderCoords[2].Set(GroundTile::Coord::CELL_MAX,0,
false);
407 borderCoords[3].Set(0,0,
false);
412 std::string StateToString(State state)
const;
413 std::string TypeToString(GroundTile::Type type)
const;
430 GroundTile::Coord
Transform(
const GeoCoord& point,
431 const StateMap& stateMap,
449 void GetCells(
const StateMap& stateMap,
452 std::set<Pixel>& cellIntersections)
const;
463 void GetCellIntersections(
const StateMap& stateMap,
464 const std::vector<GeoCoord>& points,
466 std::map<Pixel,std::list<IntersectionRef>>& cellIntersections);
471 bool IsCellInBoundingPolygon(
const CellBoundaries& cellBoundary,
472 const std::list<CoastRef>& boundingPolygons);
477 bool ContainsCoord(
const std::list<GroundTile> &tiles,
478 const GroundTile::Coord &coord,
479 GroundTile::Type type);
484 bool ContainsCoord(
const std::list<GroundTile> &tiles,
485 const GroundTile::Coord &coord);
490 bool ContainsWater(
const Pixel &coord,
491 const StateMap &stateMap,
492 const std::map<Pixel,std::list<GroundTile>>& cellGroundTileMap,
493 const GroundTile::Coord &testCoord1,
494 const GroundTile::Coord &testCoord2);
501 void WalkBorderCW(GroundTile& groundTile,
502 const StateMap& stateMap,
505 const IntersectionRef& incoming,
506 const IntersectionRef& outgoing,
507 const CellBoundaries::BorderCoords &borderCoords);
512 IntersectionRef GetNextCW(
const std::list<IntersectionRef>& intersectionsCW,
513 const IntersectionRef& current)
const;
519 void WalkPathBack(GroundTile& groundTile,
520 const StateMap& stateMap,
523 const IntersectionRef& pathStart,
524 const IntersectionRef& pathEnd,
525 const std::vector<GeoCoord>& points,
532 void WalkPathForward(GroundTile& groundTile,
533 const StateMap& stateMap,
536 const IntersectionRef& pathStart,
537 const IntersectionRef& pathEnd,
538 const std::vector<GeoCoord>& points,
547 IntersectionRef FindSiblingIntersection(
const IntersectionRef &intersection,
548 const std::list<IntersectionRef> &intersectionsCW,
561 bool WalkFromTripoint(GroundTile &groundTile,
562 const StateMap& stateMap,
563 const CellBoundaries &cellBoundaries,
564 IntersectionRef &pathStart,
565 IntersectionRef &pathEnd,
567 const std::list<IntersectionRef> &intersectionsCW,
568 const std::vector<size_t> &containingPaths);
574 void WalkPath(GroundTile &groundTile,
575 const StateMap& stateMap,
576 const CellBoundaries &cellBoundaries,
577 const IntersectionRef pathStart,
578 const IntersectionRef pathEnd,
579 CoastlineDataRef coastline);
586 bool WalkBoundaryCW(GroundTile &groundTile,
587 const StateMap &stateMap,
588 const IntersectionRef outIntersection,
589 const std::list<IntersectionRef> &intersectionsCW,
590 std::set<IntersectionRef> &visitedIntersections,
591 const CellBoundaries &cellBoundaries,
593 const std::vector<size_t> &containingPaths);
606 void SynthesizeCoastlines2(Progress& progress,
607 const std::list<CoastRef>& boundingPolygons,
608 const std::list<CoastRef>& coastlines,
609 std::list<CoastRef>& synthesized);
614 void HandleCoastlineCell(Progress& progress,
616 const std::list<size_t>& intersectCoastlines,
617 const StateMap& stateMap,
618 std::map<Pixel,std::list<GroundTile> >& cellGroundTileMap,
621 void TransformCoastlines(Progress& progress,
622 TransPolygon::OptimizeMethod optimizationMethod,
624 double minObjectDimension,
625 const Projection& projection,
626 const std::list<CoastRef>& coastlines,
627 std::vector<CoastlineDataRef> &transformedCoastlines);
629 void FilterIntersectCoastlines(Progress& progress,
630 std::vector<CoastlineDataRef> &transformedCoastlines);
632 void FilterEncapsulatedCoastlines(Progress& progress,
633 std::vector<CoastlineDataRef> &transformedCoastlines);
635 void ComputeCoveredTiles(Progress& progress,
636 const StateMap& stateMap,
638 std::vector<CoastlineDataRef> &transformedCoastlines);
643 static bool CoastlineGeoSizeSorter(
const CoastlineDataRef &a,
const CoastlineDataRef &b);
650 std::list<WaterIndexProcessor::CoastRef>& coastlines);
663 const std::vector<GeoCoord>& points,
664 std::set<Pixel>& cellIntersections)
const;
677 const std::vector<Point>& points,
678 std::set<Pixel>& cellIntersections)
const;
689 std::list<CoastRef>& coastlines,
690 const std::list<CoastRef>& boundingPolygons);
696 TransPolygon::OptimizeMethod optimizationMethod,
698 double minObjectDimension,
701 const std::list<CoastRef>& coastlines,
722 std::map<
Pixel,std::list<GroundTile> >& cellGroundTileMap);
729 std::map<
Pixel,std::list<GroundTile> >& cellGroundTileMap,
741 const std::map<
Pixel,std::list<GroundTile> >& cellGroundTileMap);
748 std::map<
Pixel,std::list<GroundTile> >& cellGroundTileMap,
749 const std::list<CoastRef>& boundingPolygons);
760 const std::list<CoastRef>& boundingPolygons);
775 const std::map<
Pixel,std::list<GroundTile> >& cellGroundTileMap)
const;
781 std::vector<Level>& levels);
787 const std::map<
Pixel,std::list<GroundTile>>& cellGroundTileMap,
#define OSMSCOUT_IMPORT_API
Definition ImportImportExport.h:45
Definition WaterIndexProcessor.h:162
uint32_t GetYStart() const
Definition WaterIndexProcessor.h:194
uint32_t GetXCount() const
Definition WaterIndexProcessor.h:209
uint32_t GetXStart() const
Definition WaterIndexProcessor.h:189
bool IsInAbsolute(uint32_t x, uint32_t y) const
Definition WaterIndexProcessor.h:219
uint32_t GetYCount() const
Definition WaterIndexProcessor.h:214
uint32_t GetYEnd() const
Definition WaterIndexProcessor.h:204
double GetCellHeight() const
Definition WaterIndexProcessor.h:184
double GetCellWidth() const
Definition WaterIndexProcessor.h:179
State GetStateAbsolute(uint32_t x, uint32_t y) const
Definition WaterIndexProcessor.h:228
uint32_t GetXEnd() const
Definition WaterIndexProcessor.h:199
void SetBox(const GeoBox &boundingBox, double cellWidth, double cellHeight)
State GetState(uint32_t x, uint32_t y) const
void SetStateAbsolute(uint32_t x, uint32_t y, State state)
Definition WaterIndexProcessor.h:235
void SetState(uint32_t x, uint32_t y, State state)
void WriteTiles(Progress &progress, const std::map< Pixel, std::list< GroundTile > > &cellGroundTileMap, Level &level, FileWriter &writer)
void CalculateCoastEnvironment(Progress &progress, StateMap &stateMap, const std::map< Pixel, std::list< GroundTile > > &cellGroundTileMap)
void CalculateHasCellData(Level &level, const std::map< Pixel, std::list< GroundTile > > &cellGroundTileMap) const
void FillWaterAroundIsland(Progress &progress, StateMap &stateMap, std::map< Pixel, std::list< GroundTile > > &cellGroundTileMap, const std::list< CoastRef > &boundingPolygons)
State
Definition WaterIndexProcessor.h:151
@ coast
right side of the coast => a water tile
Definition GroundTile.h:52
@ water
left side of the coast => a land tile
Definition GroundTile.h:51
@ unknown
Definition GroundTile.h:49
@ land
We do not know yet.
Definition GroundTile.h:50
void DumpIndexHeader(FileWriter &writer, std::vector< Level > &levels)
void MarkCoastlineCells(Progress &progress, StateMap &stateMap, const Data &data)
void FillWater(Progress &progress, Level &level, size_t tileCount, const std::list< CoastRef > &boundingPolygons)
CoastState
Definition WaterIndexProcessor.h:119
void GetCells(const StateMap &stateMap, const std::vector< GeoCoord > &points, std::set< Pixel > &cellIntersections) const
void FillLand(Progress &progress, StateMap &stateMap)
void HandleAreaCoastlinesCompletelyInACell(Progress &progress, const StateMap &stateMap, Data &data, std::map< Pixel, std::list< GroundTile > > &cellGroundTileMap)
void CalculateCoastlineData(Progress &progress, TransPolygon::OptimizeMethod optimizationMethod, double tolerance, double minObjectDimension, const Projection &projection, const StateMap &stateMap, const std::list< CoastRef > &coastlines, Data &data)
uint32_t x
Definition Pixel.h:48
uint32_t y
Definition Pixel.h:49
void SynthesizeCoastlines(Progress &progress, std::list< CoastRef > &coastlines, const std::list< CoastRef > &boundingPolygons)
Direction
Definition WaterIndexProcessor.h:269
@ touch
Definition WaterIndexProcessor.h:271
@ out
Definition WaterIndexProcessor.h:270
@ in
Definition WaterIndexProcessor.h:272
double cellWidth
Width of cell.
Definition GroundTile.h:97
std::shared_ptr< Intersection > IntersectionRef
Definition WaterIndexProcessor.h:289
bool operator()(const ObjectFileRef &a, const ObjectFileRef &b) const
Definition ObjectRef.h:249
double cellHeight
Height of cell.
Definition GroundTile.h:98
std::shared_ptr< Coast > CoastRef
Definition WaterIndexProcessor.h:145
void MergeCoastlines(Progress &progress, std::list< WaterIndexProcessor::CoastRef > &coastlines)
std::shared_ptr< CoastlineData > CoastlineDataRef
Definition WaterIndexProcessor.h:308
void HandleCoastlinesPartiallyInACell(Progress &progress, const StateMap &stateMap, std::map< Pixel, std::list< GroundTile > > &cellGroundTileMap, Data &data)
RoutableObjectsRef data
Definition DataAgent.h:63
void GetCells(const StateMap &stateMap, const std::vector< Point > &points, std::set< Pixel > &cellIntersections) const
Definition Projection.h:46
uint64_t Id
Definition OSMScoutTypes.h:40
int64_t OSMId
Definition OSMScoutTypes.h:33
uint64_t FileOffset
Definition OSMScoutTypes.h:46
void WriteGpx(InputIterator begin, InputIterator end, const std::string &name)
Definition WaterIndexProcessor.h:58
codepoint(*)(const character *, int context) Transform
functor implements desired transformation of the character It has 2 arguments:
Definition utf8helper.h:49
Definition WaterIndexProcessor.h:135
Id frontNodeId
Id of the first coast node (coords.front().GetId()).
Definition WaterIndexProcessor.h:138
Id backNodeId
Id of the last coast node (coords.back().GetId()).
Definition WaterIndexProcessor.h:139
OSMId id
Definition WaterIndexProcessor.h:136
bool isArea
Definition WaterIndexProcessor.h:137
std::vector< Point > coast
Definition WaterIndexProcessor.h:140
CoastState right
Definition WaterIndexProcessor.h:142
CoastState left
Definition WaterIndexProcessor.h:141
Definition WaterIndexProcessor.h:296
Id id
Definition WaterIndexProcessor.h:297
std::vector< GeoCoord > points
The cell that completely contains the coastline.
Definition WaterIndexProcessor.h:302
std::map< Pixel, std::list< IntersectionRef > > cellIntersections
The points of the coastline.
Definition WaterIndexProcessor.h:303
CoastState right
Definition WaterIndexProcessor.h:305
Pixel cell
GeoBox from points (already transformed).
Definition WaterIndexProcessor.h:301
bool isCompletelyInCell
true,if the boundary forms an area
Definition WaterIndexProcessor.h:299
GeoBox boundingBox
true, if the complete coastline is within one cell
Definition WaterIndexProcessor.h:300
CoastState left
All intersections for each cell.
Definition WaterIndexProcessor.h:304
bool isArea
The id of the coastline.
Definition WaterIndexProcessor.h:298
Definition WaterIndexProcessor.h:314
std::map< Pixel, std::list< size_t > > cellCoastlines
data for each coastline
Definition WaterIndexProcessor.h:316
std::vector< CoastlineDataRef > coastlines
Definition WaterIndexProcessor.h:315
std::map< Pixel, std::list< size_t > > cellCoveredCoastlines
Contains for each cell the list of intersecting coastlines.
Definition WaterIndexProcessor.h:317
Definition WaterIndexProcessor.h:279
double distanceSquare
The intersection point.
Definition WaterIndexProcessor.h:284
GeoCoord point
just helper for sorting
Definition WaterIndexProcessor.h:283
GeoCoord prevPoint
The index of the path point before the intersection.
Definition WaterIndexProcessor.h:282
uint8_t borderIndex
1 in, 0 touch, -1 out
Definition WaterIndexProcessor.h:286
size_t prevWayPointIndex
Running number of the intersecting coastline.
Definition WaterIndexProcessor.h:281
size_t coastline
Definition WaterIndexProcessor.h:280
Direction direction
The distance^2 between the path point and the intersectionPoint.
Definition WaterIndexProcessor.h:285
Definition WaterIndexProcessor.h:247
bool hasCellData
If true, we have cell data.
Definition WaterIndexProcessor.h:253
uint8_t dataOffsetBytes
Number of bytes per entry in bitmap.
Definition WaterIndexProcessor.h:254
FileOffset indexEntryOffset
File offset of this entry on disk.
Definition WaterIndexProcessor.h:250
void SetBox(const GeoBox &boundingBox, double cellWidth, double cellHeight)
State defaultCellData
If hasCellData is false, this is the value to be returned for all cells.
Definition WaterIndexProcessor.h:255
FileOffset indexDataOffset
File offset of start cell state data on disk.
Definition WaterIndexProcessor.h:256
StateMap stateMap
Index to handle state of cells.
Definition WaterIndexProcessor.h:258
uint32_t level
The actual zoom level.
Definition WaterIndexProcessor.h:249