Ocean
Basemap.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_IO_MAPS_BASEMAP_H
9 #define META_OCEAN_IO_MAPS_BASEMAP_H
10 
11 #include "ocean/io/maps/Maps.h"
12 
14 #include "ocean/cv/PixelPosition.h"
15 
16 #include <vtzero/feature.hpp>
17 #include <vtzero/geometry.hpp>
18 
19 namespace Ocean
20 {
21 
22 namespace IO
23 {
24 
25 namespace Maps
26 {
27 
28 /**
29  * This class implements an parser of basemap data.
30  * @ingroup iomaps
31  */
32 class OCEAN_IO_MAPS_EXPORT Basemap
33 {
34  public:
35 
36  /**
37  * Definition of a location with signed pixel precision.
38  */
40 
41  /**
42  * Definition of a vector holding locations with signed pixel precision.
43  */
45 
46  /**
47  * Definition of groups of pixel positions.
48  */
49  typedef std::vector<PixelPositionsI> PixelPositionGroupsI;
50 
51  /**
52  * This class is the base class for all map objects.
53  * Objects are extracted from layers, layer coordinates are given with pixel precision.
54  */
55  class Object
56  {
57  public:
58 
59  /**
60  * Definition of individual object types.
61  */
62  enum ObjectType : uint32_t
63  {
64  /// The object type is unknown.
65  OT_UNKNOWN = 0u,
66  /// The object is a building.
68  /// The object is a land cover.
70  /// The object is a land use.
72  /// The object is a road.
74  /// The object is a transit.
76  /// The object is a water.
77  OT_WATER
78  };
79 
80  public:
81 
82  /**
83  * Returns the type of this object.
84  * @return The object's type
85  */
86  inline ObjectType objectType() const;
87 
88  /**
89  * Returns the extent of the layer in which this object is defined.
90  * @return The layer's extent, in pixels, with range [1, infinity), 0 if invalid
91  */
92  inline unsigned int layerExtent() const;
93 
94  /**
95  * Converts the coordinate defined in the owning layer of this object to a target domain with individual extent.
96  * @param coordinate The coordinate located in the layer to which this object belongs, with range (-infinity, infinity)x(-infinity, infinity)
97  * @param targetExtent The extent of the target domain, with sub-pixel precision, with range [1, infinity)
98  * @return The resulting converted coordinate
99  */
100  inline Vector2 vectorFromCoordinate(const PixelPositionI& coordinate, const Scalar targetExtent) const;
101 
102  protected:
103 
104  /**
105  * Creates a new object.
106  * @param objectType The type of the new object, must be valid
107  * @param layerExtent The extent of the layer to which this object belongs, in pixel, with range [1, infinity)
108  */
109  inline Object(const ObjectType objectType, const unsigned int layerExtent);
110 
111  protected:
112 
113  /// The object's type.
114  ObjectType objectType_ = OT_UNKNOWN;
115 
116  /// The extent of the layer to which this object belongs, in pixel, with range [1, infinity), 0 if invalid
117  unsigned int layerExtent_ = 0u;
118  };
119 
120  /**
121  * This class implements a road object.
122  */
123  class Road final : public Object
124  {
125  public:
126 
127  /**
128  * Definition of individual road types.
129  */
130  enum RoadType : uint32_t
131  {
132  /// An unknown road type.
133  RT_UNKNOWN = 0u,
134  /// A road to provide access.
136  /// The road is an alley.
138  /// The road is a bridleway (e.g., mainly used by horses).
140  /// The road is a crossing.
142  /// A cycleway.
144  /// The road is a crosswalk.
146  /// The road is a driveway.
148  /// The road is a footway.
150  /// A highway.
152  /// A highway link.
154  /// A link.
156  /// A living street.
158  /// A local street.
160  /// A motorway.
162  /// A motorway link.
164  /// The road is a parking aisle.
166  /// The road is a path.
168  /// A pedestrian road.
170  /// A residential road.
172  /// A primary road.
174  /// A primary link road.
176  /// The road is a raceway.
178  /// A default road.
180  /// A secondary road.
182  /// A secondary link.
184  /// A service road.
186  /// The road is a sidewalk.
188  /// A path/road with steps.
190  /// A tertiary road.
192  /// A tertiary link.
194  /// A track.
196  /// A trunk road.
198  /// A trunk link.
200  /// An unclassified road.
202  /// Exclusive end value.
203  RT_END
204  };
205 
206  /**
207  * Definition of an unordered map mapping road types to road widths.
208  */
209  typedef std::unordered_map<RoadType, float> RoadWidthMap;
210 
211  protected:
212 
213  /**
214  * Definition of an unordered map mapping road type strings to road type values.
215  */
216  typedef std::unordered_map<std::string, RoadType> RoadTypeMap;
217 
218  public:
219 
220  /**
221  * Creates a new road.
222  * @param roadType The type of the new road, must be valid
223  * @param name The name of the road, if known
224  * @param lineStrings The line strings defining the shape of the road, at least one line string
225  * @param layerExtent The extent of the layer to which this road belongs, in pixel, with range [1, infinity)
226  */
227  inline Road(const RoadType roadType, std::string&& name, PixelPositionGroupsI&& lineStrings, const unsigned int layerExtent);
228 
229  /**
230  * Returns the type of this road.
231  * @return The road's type
232  */
233  inline RoadType roadType() const;
234 
235  /**
236  * Returns the line strings defining the shape of the road in the domain of the layer to which this road belongs.
237  * @return The line strings
238  */
239  inline const PixelPositionGroupsI& lineStrings() const;
240 
241  /**
242  * Translates the string of a road type to a value.
243  * @param roadType The string of the road type to translate
244  * @return The resulting value of the road type, RT_UNKNOWN if unknown
245  */
246  static RoadType translateRoadType(const std::string& roadType);
247 
248  /**
249  * Returns the default map for road widths.
250  * The default road width is specified for RT_END.
251  * @return The map mapping road types to road widths, in meter.
252  */
254 
255  protected:
256 
257  /// The type of this road.
259 
260  /// The name of this road, if known.
261  std::string name_;
262 
263  /// The line strings defining the shape of the road in the domain of the layer to which this road belongs.
265  };
266 
267  /**
268  * This class implements a transit object.
269  */
270  class Transit final : public Object
271  {
272  public:
273 
274  /**
275  * Definition of individual transit types.
276  */
277  enum TransitType : uint32_t
278  {
279  /// An unknown transit type.
280  TT_UNKNOWN = 0u,
281  /// Aerial transit way e.g., for planes.
283  /// A ferry.
285  /// A railway.
286  TT_RAILWAY
287  };
288 
289  /**
290  * Creates a new transit object.
291  * @param transitType The type of the new transit object, must be valid
292  * @param name The name of the transit, if known
293  * @param lineStrings The line strings defining the shape of the transit, at least one line string
294  * @param layerExtent The extent of the layer to which this transit belongs, in pixel, with range [1, infinity)
295  */
296  inline Transit(const TransitType transitType, std::string&& name, PixelPositionGroupsI&& lineStrings, const unsigned int layerExtent);
297 
298  /**
299  * Returns the type of this transit.
300  * @return The transit's type
301  */
302  inline TransitType transitType() const;
303 
304  /**
305  * Returns the line strings defining the shape of the transit in the domain of the layer to which this transit belongs.
306  * @return The line strings
307  */
308  inline const PixelPositionGroupsI& lineStrings() const;
309 
310  protected:
311 
312  /// The type of this transit.
314 
315  /// The name of this transit, if known.
316  std::string name_;
317 
318  /// The line strings defining the shape of the transit in the domain of the layer to which this transit belongs.
320  };
321 
322  /**
323  * This class implements an object composed of inner and outer polygons.
324  */
326  {
327  public:
328 
329  /**
330  * Returns the individual outer polygons of this building.
331  * @return The building's outer polygons, can be empty
332  */
333  inline const PixelPositionGroupsI& outerPolygons() const;
334 
335  /**
336  * Returns the individual inner poloyons of this building.
337  * @return The building's inner polygons, can be empty
338  */
339  inline const PixelPositionGroupsI& innerPolygons() const;
340 
341  protected:
342 
343  /**
344  * Creates a new object.
345  * @param objectType The type of the new object, must be valid
346  * @param outerPolygons The building's outer polygons, can be empty
347  * @param innerPolygons The building's inner polygons, can be empty
348  * @param layerExtent The extent of the layer to which this building belongs, in pixel, with range [1, infinity)
349  */
350  inline InnerOuterPolygonsObject(const ObjectType objectType, PixelPositionGroupsI&& outerPolygons, PixelPositionGroupsI&& innerPolygons, const unsigned int layerExtent);
351 
352  protected:
353 
354  /// The individual outer polygons of this building.
356 
357  /// The individual inner pologyons of this building.
359  };
360 
361  /**
362  * This class implements a building object.
363  */
364  class OCEAN_IO_MAPS_EXPORT Building final : public InnerOuterPolygonsObject
365  {
366  public:
367 
368  /**
369  * Creates a new building.
370  * @param outerPolygons The building's outer polygons, can be empty
371  * @param innerPolygons The building's inner polygons, can be empty
372  * @param lineStrings The building's line strings, can be empty
373  * @param height The building's height, in meter, with range [0, infinity), -1 if unknown
374  * @param layerExtent The extent of the layer to which this building belongs, in pixel, with range [1, infinity)
375  */
376  inline Building(PixelPositionGroupsI&& outerPolygons, PixelPositionGroupsI&& innerPolygons, PixelPositionGroupsI&& lineStrings, const Scalar height, const unsigned int layerExtent);
377 
378  /**
379  * Returns the height of the building.
380  * @return The building's height, in meter, with range [0, infinity), -1 if unknown
381  */
382  inline Scalar height() const;
383 
384  /**
385  * The individual line strings of this building.
386  * @return The building's line strings, can be empty
387  */
388  inline const PixelPositionGroupsI& lineStrings() const;
389 
390  /**
391  * Returns the pixel bounding box entirely enclosing this building.
392  * @return The bounding box
393  */
395 
396  protected:
397 
398  /// The height of the bulding in meter, with range [0, infinity), -1 if unknown
400 
401  /// The individual line strings of this building.
403  };
404 
405  /**
406  * This class implements a water object.
407  */
408  class Water final : public InnerOuterPolygonsObject
409  {
410  public:
411 
412  /**
413  * Definition of individual water types.
414  */
415  enum WaterType : uint32_t
416  {
417  /// An unknown water type.
418  WT_UNKNOWN = 0u,
419  /// The water is a canal.
421  /// The water is a dock.
423  /// The water is human made.
425  /// An inland water.
427  /// The water is a lake.
429  /// The water is an ocean.
431  /// The water is a pond.
433  /// The water is a reservoir.
435  /// The water is a river.
437  /// The water is a stream.
439  /// The water without further specification.
441  /// Exclusive end value.
442  WT_END
443  };
444 
445  protected:
446 
447  /**
448  * Definition of an unordered map mapping water type strings to water type values.
449  */
450  typedef std::unordered_map<std::string, WaterType> WaterTypeMap;
451 
452  public:
453 
454  /**
455  * Creates a new water.
456  * @param waterType The type of the water
457  * @param outerPolygons The water's outer polygons, can be empty
458  * @param innerPolygons The water's inner polygons, can be empty
459  * @param layerExtent The extent of the layer to which this water belongs, in pixel, with range [1, infinity)
460  */
461  inline Water(const WaterType waterType, PixelPositionGroupsI&& outerPolygons, PixelPositionGroupsI&& innerPolygons, const unsigned int layerExtent);
462 
463  /**
464  * Returns the type of the water.
465  * @return The water's type
466  */
467  inline WaterType waterType() const;
468 
469  /**
470  * Translates the string of a water type to a value.
471  * @param waterType The string of the water type to translate
472  * @return The resulting value of the water type, WT_UNKNOWN if unknown
473  */
474  static WaterType translateWaterType(const std::string& waterType);
475 
476  protected:
477 
478  /// The type of the water.
479  WaterType waterType_ = WT_UNKNOWN;
480  };
481 
482  /**
483  * This class implements a land use object.
484  */
485  class LandUse final : public InnerOuterPolygonsObject
486  {
487  public:
488 
489  /**
490  * Definition of individual land use types.
491  */
492  enum LandUseType : uint32_t
493  {
494  /// An unknown land use type.
495  LUT_UNKNOWN = 0u,
496  /// The land use is an airport.
498  /// The land is used for amusement.
500  /// The land use is education.
502  /// The land use is a green space.
504  /// The land use is a land.
506  /// The land use is a national park.
508  /// The land use is a plaza.
510  /// The land use is a recreation.
511  LUT_RECREATION
512  };
513 
514  public:
515 
516  /**
517  * Creates a new land use.
518  * @param landUseType The type of the land use
519  * @param outerPolygons The land use's outer polygons, can be empty
520  * @param innerPolygons The land use's inner polygons, can be empty
521  * @param lineStrings The building's line strings, can be empty
522  * @param layerExtent The extent of the layer to which this land use belongs, in pixel, with range [1, infinity)
523  */
524  inline LandUse(const LandUseType landUseType, PixelPositionGroupsI&& outerPolygons, PixelPositionGroupsI&& innerPolygons, PixelPositionGroupsI&& lineStrings, const unsigned int layerExtent);
525 
526  /**
527  * Returns the type of the land use.
528  * @return The land use's type
529  */
530  inline LandUseType landUseType() const;
531 
532  /**
533  * Returns the line strings defining the shape of the transit in the domain of the layer to which this transit belongs.
534  * @return The line strings
535  */
536  inline const PixelPositionGroupsI& lineStrings() const;
537 
538  protected:
539 
540  /// The type of the land use.
541  LandUseType landUseType_ = LUT_UNKNOWN;
542 
543  /// The individual line strings of this building.
545  };
546 
547  /**
548  * This class implements a land use object.
549  */
550  class LandCover final : public InnerOuterPolygonsObject
551  {
552  public:
553 
554  /**
555  * Definition of individual land use types.
556  */
557  enum LandCoverType : uint32_t
558  {
559  /// An unknown land cover type.
560  LCT_UNKNOWN = 0u,
561  /// The land is covered with grass.
563  /// The land is paved.
565  /// The land is coverd with sand.
566  LCT_SAND
567  };
568 
569  public:
570 
571  /**
572  * Creates a new land cover.
573  * @param landCoverType The type of the land cover
574  * @param outerPolygons The land use's outer polygons, can be empty
575  * @param innerPolygons The land use's inner polygons, can be empty
576  * @param lineStrings The building's line strings, can be empty
577  * @param layerExtent The extent of the layer to which this land use belongs, in pixel, with range [1, infinity)
578  */
579  inline LandCover(const LandCoverType landCoverType, PixelPositionGroupsI&& outerPolygons, PixelPositionGroupsI&& innerPolygons, PixelPositionGroupsI&& lineStrings, const unsigned int layerExtent);
580 
581  /**
582  * Returns the type of the land use.
583  * @return The land use's type
584  */
585  inline LandCoverType landCoverType() const;
586 
587  /**
588  * Returns the line strings defining the shape of the transit in the domain of the layer to which this transit belongs.
589  * @return The line strings
590  */
591  inline const PixelPositionGroupsI& lineStrings() const;
592 
593  protected:
594 
595  /// The type of the land cover.
596  LandCoverType landCoverType_ = LCT_UNKNOWN;
597 
598  /// The individual line strings of this building.
600  };
601 
602  /**
603  * Definition of a shared pointer holding an Object.
604  */
605  typedef std::shared_ptr<Object> SharedObject;
606 
607  /**
608  * Definition of a vector holding shared objects.
609  */
610  typedef std::vector<SharedObject> SharedObjects;
611 
612  /// Forward declaration.
613  class TileIndexPair;
614 
615  /**
616  * Definition of a vector holding tile index pairs.
617  */
618  typedef std::vector<TileIndexPair> TileIndexPairs;
619 
620  /**
621  * This class holds the tile indics in latitude and longitude direction.
622  */
624  {
625  public:
626 
627  /**
628  * Default constructor creating an invalid pair of indices.
629  */
630  TileIndexPair() = default;
631 
632  /**
633  * Creates an new tile index pair.
634  * @param latitudeIndex The tile index in latitude direction, with range [0, infinity)
635  * @param longitudeIndex The tile index in longitude direction, with range [0, infinity)
636  */
637  inline TileIndexPair(const unsigned int latitudeIndex, const unsigned int longitudeIndex);
638 
639  /**
640  * Returns the tile index in latitude direction.
641  * @return The tile index in latitude direction, with range [0, infinity)
642  */
643  inline unsigned int latitudeIndex() const;
644 
645  /**
646  * Returns the tile index in longitude direction.
647  * @return The tile index in longitude direction, with range [0, infinty)
648  */
649  inline unsigned int longitudeIndex() const;
650 
651  /**
652  * Returns whether this tile index pair is within the range of a maximal number of tiles.
653  * @param numberTiles The number of tiles in the level in which this tile pair is defined, with range [2, infinity)
654  * @return True, if so
655  */
656  inline bool isInside(const unsigned int numberTiles) const;
657 
658  /**
659  * Returns whether a given location is close to this tile.
660  * The location is defined in a normalized tile fractions for a given tile.
661  * @param tileIndexPair The given tile in which the location is located, can be the same tile as this tile, must be valid
662  * @param latitudeFraction The normalized tile fraction in latitude direction defining the actual location in the `tileIndexPair` tile, with range [0, 1], 0 for the north edge, 1 for the south edge
663  * @param longitudeFraction The normalized tile fraction in longitude direction defining the actual location in the `tileIndexPair` tile, with range [0, 1], 0 for the west edge, 1 for the east edge
664  * @param maxFraction The maximal fraction between the given location and the border of this tile so that the given location counts as close, with range [0, 1], 0 to allow locations at the direct border only, 1 to allow locations with a one-tile distance
665  * @return True, if so
666  */
667  bool isLocationClose(const TileIndexPair& tileIndexPair, const double latitudeFraction, const double longitudeFraction, const double maxFraction = 0.2) const;
668 
669  /**
670  * Returns whether the this object holds valid tile indices.
671  * @return True, if so
672  */
673  inline bool isValid() const;
674 
675  /**
676  * Returns whether two tile index pair objects hold the same indices.
677  * @param other The second tile pair object to compare
678  * @return True, if so
679  */
680  inline bool operator==(const TileIndexPair& other) const;
681 
682  /**
683  * Returns whether two tile index pair objects hold not the same indices.
684  * @param other The second tile pair object to compare
685  * @return True, if so
686  */
687  inline bool operator!=(const TileIndexPair& other) const;
688 
689  /**
690  * Hash function.
691  * @param tileIndexPair Tile index pair for which the hash will be determined
692  * @return The hash value
693  */
694  inline size_t operator()(const TileIndexPair& tileIndexPair) const;
695 
696  /**
697  * Returns the tile index pairs of all neighboring tiles for a given center tile.
698  * @param tileIndexPair The center tile for which the neighboring tiles will be returned, must be valid
699  * @param numberTilesOnLevel The number of tiles in latitude and longitude direction on the tile's detail level, with range [max(tileIndexPair.latitudeIndex_, tileIndexPair.longitudeIndex_), infinity)
700  * @param maxDistance The maximal distance between a neighboring tile and the center tile in latitude or longitude direction so that it counts as neibhoring, 0 returns only the center tile, 1 returns the 9-neighborhood, 2 returns the 25-neighborhood, with range [0, infinity)
701  * @return The tiles in the neighborhood of the given center tile (always including the center tile)
702  */
703  static TileIndexPairs createNeighborhoodTiles(const TileIndexPair& tileIndexPair, const unsigned int numberTilesOnLevel, const unsigned int maxDistance);
704 
705  protected:
706 
707  /// The tile index in latitude direction, with range [0, infinity).
708  unsigned int latitudeIndex_ = (unsigned int)(-1);
709 
710  /// The tile index in longitude direction, with range [0, infinity).
711  unsigned int longitudeIndex_ = (unsigned int)(-1);
712  };
713 
714  /**
715  * Definition of a set holding tile index pairs.
716  */
717  typedef std::unordered_set<TileIndexPair, TileIndexPair> TileIndexPairSet;
718 
719  /**
720  * This class stores the information belonging to one map tile.
721  */
722  class OCEAN_IO_MAPS_EXPORT Tile
723  {
724  public:
725 
726  /**
727  * Default constructor creating an invalid tile.
728  */
729  Tile() = default;
730 
731  /**
732  * Default move constructor.
733  * @param tile Tile to be moved
734  */
735  Tile(Tile&& tile) = default;
736 
737  /**
738  * Creates a new valid tile object.
739  * @param level The detail level, with range [1, 22]
740  * @param tileIndexPair The tile index pair defining the location of this tile, with range [0, numberTiles(level) - 1]x[0, numberTiles(level) - 1]
741  */
742  inline Tile(const unsigned int level, const TileIndexPair& tileIndexPair);
743 
744  /**
745  * Returns the detail level of this tile.
746  * @return The tile's detail level, with range [1, 22], 0 if invalid
747  */
748  inline unsigned int level() const;
749 
750  /**
751  * Returns the tile index pair definining the tile's location.
752  * @return The tile's index pair, with range [0, numberTiles(level()) - 1]x[0, numberTiles(level()) - 1]
753  */
754  inline const TileIndexPair& tileIndexPair() const;
755 
756  /**
757  * Returns all objects of this tile.
758  * @return The tile's objects
759  */
760  inline const SharedObjects& objects() const;
761 
762  /**
763  * Parses a buffer containing the tile information as pbf file.
764  * Previously exsiting map objects will not be removed before the new map objects are added during parsing.
765  * @param data The data of the buffer, must be valid
766  * @param size The size of the buffer, in bytes, with range [1, infinity)
767  * @return True, if succeeded
768  */
769  bool parsePBFData(const void* data, const size_t size);
770 
771  /**
772  * Returns the approximated GPS location of a position in this tile.
773  * @param position The position in this tile, in pixels, with range (-infinity, infinity)x(-infinity, infinity), must be valid
774  * @param layerExtent The extent of the layer in which the position is located, with range [1, infinity)
775  * @param latitude The resulting latitude coordinate of the GPS location of the given tile position, in degree, with range [-90, 90]
776  * @param longitude The resulting latitude coordinate of the GPS location of the given tile position, in degree, with range [-180, 180]
777  */
778  void tileCoordinate2GPSLocation(const PixelPositionI& position, const unsigned int layerExtent, double& latitude, double& longitude) const;
779 
780  /**
781  * Returns the metric extent of this tile.
782  * @param earthRadius The radius of the earth, in meters, with range (0, infinity)
783  * @return The approximated extent of this tile at a tile's latitude, in horizontal and vertical direction, in meter, with range (0, infinity)
784  */
785  double metricExtent(const double earthRadius = 6378135.0) const;
786 
787  /**
788  * Removes all map objects, the level and tile information is untought.
789  */
790  void clear();
791 
792  /**
793  * Returns whether this tile is valid.
794  * @return True, if so
795  */
796  inline bool isValid() const;
797 
798  /**
799  * Default move operator.
800  * @param tile Tile to be moved
801  * @return Reference to this object
802  */
803  Tile& operator=(Tile&& tile) = default;
804 
805  /**
806  * Returns the number of tiles in horizontal and vertical direction for a given detail level.
807  * The number of levels is determined by 2 ^ level .
808  * @param level The detail level, with range [1, 22]
809  * @return The number of tiles in horizontal and vertical direction, with range [2, 4,194,304]
810  */
811  static constexpr inline unsigned int numberTiles(const unsigned int level);
812 
813  /**
814  * Calculates the tile in which a given GPS coordinate is located at a specified detail level.
815  * @param level The detail level, with range [1, 22]
816  * @param latitude The latitude value of the GPS coordinate, in degree, with range [-90, 90]
817  * @param longitude The longitude value of the GPS coordinate, in degree, with range [-180, 180]
818  * @param latitudeTileFraction Optional resulting fraction in latitude direction providing the preceise location within the tile, with range [0, 1), 0 for the north edge of the tile, 1 for the south edege of the tile
819  * @param longitudeTileFraction Optional resulting fraction in longitude direction providing the preceise location within the tile, with range [0, 1), 0 for the west edge of the tile, 1 for the east edege of the tile
820  * @return The resulting tile index pair, with range [0, numberTiles(level) - 1]x[0, numberTiles(level) - 1]
821  */
822  static TileIndexPair calculateTile(const unsigned int level, const double latitude, const double longitude, double* latitudeTileFraction = nullptr, double* longitudeTileFraction = nullptr);
823 
824  /**
825  * Calculates the tile fraction ini latitude and longitude for a given GPS coordinate in relation to a given tile.
826  * @param level The detail level, with range [1, 22]
827  * @param latitude The latitude value of the GPS coordinate, in degree, with range [-90, 90]
828  * @param longitude The longitude value of the GPS coordinate, in degree, with range [-180, 180]
829  * @param tileIndexPair The tile index pair specifying the tile for which the fractions will be determined, must be valid
830  * @param latitudeTileFraction Optional resulting fraction in latitude direction providing the preceise location within the tile, with range [0, 1), 0 for the north edge of the tile, 1 for the south edege of the tile
831  * @param longitudeTileFraction Optional resulting fraction in longitude direction providing the preceise location within the tile, with range [0, 1), 0 for the west edge of the tile, 1 for the east edege of the tile
832  */
833  static void calculateTileFractions(const unsigned int level, const double latitude, const double longitude, const TileIndexPair& tileIndexPair, double& latitudeTileFraction, double& longitudeTileFraction);
834 
835  /**
836  * Returns the approximated GPS location of a position in a tile.
837  * @param level The detail level, with range [1, 22]
838  * @param tileIndexPair The tile index pair defining the tile, must be valid
839  * @param position The position in the tile, in pixels, with range (-infinity, infinity)x(-infinity, infinity), must be valid
840  * @param layerExtent The extent of the layer in which the position is located, with range [1, infinity)
841  * @param latitude The resulting latitude coordinate of the GPS location of the given tile position, in degree, with range [-90, 90]
842  * @param longitude The resulting latitude coordinate of the GPS location of the given tile position, in degree, with range [-180, 180]
843  */
844  static void tileCoordinate2GPSLocation(const unsigned int level, const TileIndexPair& tileIndexPair, const PixelPositionI& position, const unsigned int layerExtent, double& latitude, double& longitude);
845 
846  protected:
847 
848  /**
849  * Calculates the tile in which a given GPS coordinate is located in latitude direction with sub-tile accuracy in normalized tile space.
850  * The actual tile index can be determined by:
851  * <pre>
852  * latitudeTileIndex = floor(latitudeTileNormalized * numberTiles(level))
853  * </pre>
854  * @param latitude The latitude value of the GPS coordinate, in degree, with range [-90, 90]
855  * @return The resulting normalized tile in latitude direction in which the GPS location is located, with range [0, 1)
856  **/
857  static double calculateNormalizedTileLatitude(const double latitude);
858 
859  /**
860  * Calculates the tile in which a given GPS coordinate is located in longitude direction with sub-tile accuracy in normalized tile space.
861  * The actual tile index can be determined by:
862  * <pre>
863  * longitudeTileIndex = floor(longitudeTileNormalized * numberTiles(level))
864  * </pre>
865  * @param longitude The longitude value of the GPS coordinate, in degree, with range [-180, 180]
866  * @return The resulting normalized tile in longitude direction which the GPS locaiton is located, withr ange [0, 1)
867  **/
868  static double calculateNormalizedTileLongitude(const double longitude);
869 
870  protected:
871 
872  /// The detail level of this tile, with range [1, 22], 0 if invalid
873  unsigned int level_ = 0u;
874 
875  /// The tile index pair of the tile in latitude/vertical direction within the detail level, with range [0, numberTiles(level_) - 1]x[0, numberTiles(level_) - 1], otherwise invalid
877 
878  /// The map objects of in this tile.
880  };
881 
882  /**
883  * Definition of a shared pointer holding a Tile.
884  */
885  typedef std::shared_ptr<Tile> SharedTile;
886 
887  protected:
888 
889  /**
890  * Geometry handler for points.
891  */
893  {
894  public:
895 
896  /**
897  * This is called once at the beginning with the number of points.
898  * For a point geometry, this will be 1, for multipoint geometries this will be larger.
899  * @param count The number of points, with range [1, infinity)
900  */
901  void points_begin(uint32_t count);
902 
903  /**
904  * This is called once for each point.
905  * @param point The new point
906  */
907  void points_point(vtzero::point point);
908 
909  /**
910  * This is called once at the end.
911  */
912  void points_end();
913 
914  /**
915  * Resets the handler so that it can be reused.
916  */
917  void reset();
918 
919  public:
920 
921  /// The gathered points of this handler.
923  };
924 
925  /**
926  * Geometry handler for polygons.
927  */
929  {
930  public:
931 
932  /**
933  * This is called at the beginning of each ring with the number of points in this ring.
934  * For a simple polygon with only one outer ring, this function will only be called once, if there are inner rings or if this is a multipolygon, it will be called several times.
935  * @param count The number of points in the next polygon (first and last point are identical), with range [2, infinity)
936  */
937  void ring_begin(uint32_t count);
938 
939  /**
940  * This is called once for each point.
941  * @param point The new point
942  */
943  void ring_point(vtzero::point point);
944 
945  /**
946  * This is called at the end of each ring.
947  * The parameter tells you whether the ring is an outer or inner ring or whether the ring was invalid (if the area is 0).
948  */
949  void ring_end(vtzero::ring_type ringType);
950 
951  /**
952  * Resets the handler so that it can be reused.
953  */
954  void reset();
955 
956  public:
957 
958  /// The points of the current active polygon.
960 
961  /// The individual outer polygons.
963 
964  /// the indvidual inner polygons.
966  };
967 
968  /**
969  * Geometry handler for line strings.
970  */
972  {
973  public:
974 
975  /**
976  * This is called at the beginning of each linestring with the number of points in this linestring.
977  * For a simple linestring this function will only be called once, for a multilinestring it will be called several times.
978  * @param count The number of points in the next line string, with range [1, infinity)
979  */
980  void linestring_begin(uint32_t count);
981 
982  /**
983  * This is called once for each point.
984  * @param point The new point
985  */
986  void linestring_point(vtzero::point point);
987 
988  /**
989  * This is called at the end of each linestring.
990  */
992 
993  /**
994  * Resets the handler so that it can be reused.
995  */
996  void reset();
997 
998  public:
999 
1000  /// The individual line strings.
1002  };
1003 
1004  /**
1005  * Definition of individual layer types.
1006  */
1007  enum LayerType : uint32_t
1008  {
1009  /// The layer type is unknown.
1010  LT_UNKNOWN = 0u,
1011  /// The layer holds information about an airport (point, line, & polygon airport features).
1013  /// The layer holds areas of interest (polygonal areas of interest).
1015  /// The layer holds bathymetry information (depth polygons for oceans).
1017  /// The layer holds buildings (polygonal structures).
1019  /// The layer holds labels of buildings (label point centroid for polygonal structures).
1021  /// The layer holds a border.
1023  /// The layer is an indoor layer (floor plans for meta offices, malls, airports).
1025  /// The layer holds indoor label information (labels for indoor features).
1027  /// The layer holds land cover information (polygons for physical land features).
1029  /// The layer holds land use information (mostly polygons for land usages).
1031  /// The layer holds labels of land use (label point centroid for polygonal land usages).
1033  /// The layer holds landmark point information.
1035  /// The layer holds natural areas.
1037  /// The layer holds labels of natural areas.
1039  /// The layer holds parking information (experimental parking layer, point & polygon).
1041  /// The layer holds labels of places (point features for cities, neighborhoods).
1043  /// The layer holds place labels.
1045  /// The layer holds a point of interest.
1047  /// The layer holds road data (linear features for roads, sidewalks).
1049  /// The layer holds transit information (aerial, rail, ferry; linear features).
1051  /// The layer holds transit point information (aerial, rail, ferry stations).
1053  /// The layer holds tree point information (point features for trees).
1055  /// The layer holds water information (polygonal water features).
1057  /// The layer holds waterway information (linear water features).
1059  /// The layer holds water label information (label point centroid for polygonal water).
1061  /// The layer holds water line information.
1063  /// The layer holds water offset information (polygons used for creating a shadow effect on inland water features).
1065  /// The layer holds wave information (points used to show a wave icon over water).
1067  /// Exclusive end value.
1068  LT_END
1069  };
1070 
1071  /**
1072  * Definition of an unordered map mapping layer type strings to layer type values.
1073  */
1074  typedef std::unordered_map<std::string, LayerType> LayerTypeMap;
1075 
1076  /// The minimal latitude angle, in degree.
1077  static constexpr double minLatitude = -85.05112878;
1078 
1079  /// The maximal latitude angle, in degree.
1080  static constexpr double maxLatitude = 85.05112878;
1081 
1082  public:
1083 
1084  /**
1085  * Creates a new tile based on given PBF data.
1086  * @param level The detail level, with range [1, 22]
1087  * @param tileIndexPair The tile index pair defining the location of the tile, with range [0, numberTiles(level) - 1]x[0, numberTiles(level) - 1]
1088  * @param data The data of the buffer, must be valid
1089  * @param size The size of the buffer, in bytes, with range [1, infinity)
1090  * @return The resulting tile, invalid if the given PBF data could not be parsed
1091  */
1092  static SharedTile newTileFromPBFData(const unsigned int level, const TileIndexPair& tileIndexPair, const void* data, const size_t size);
1093 
1094  /**
1095  * Returns the url for downloading the map style data
1096  * @return The url for downloading the map style data
1097  */
1098  static const std::string& styleUrl();
1099 
1100  /**
1101  * Gets the url template for downloading a map tile.
1102  * @param styleData The style data, must be valid
1103  * @param styleSize The size of the style data buffer, in bytes, with range [1, infinity)
1104  * @param urlTemplate The resulting url template
1105  * @return True, if succeeded
1106  */
1107  static bool extractTileUrlTemplate(const char* styleData, const size_t styleSize, std::string& urlTemplate);
1108 
1109  /**
1110  * Constructs the url for downloading a map tile.
1111  * @param urlTemplate The url template, must be valid
1112  * @param level The detail level, with range [1, 22]
1113  * @param tileIndexPair The tile index pair defining the location of the tile, with range [0, numberTiles(level) - 1]x[0, numberTiles(level) - 1]
1114  * @param url The resulting url
1115  * @return True, if succeeded
1116  */
1117  static bool constructTileUrl(const std::string urlTemplate, const unsigned int level, const TileIndexPair& tileIndexPair, std::string& url);
1118 
1119  protected:
1120 
1121  /**
1122  * Parses a building feature.
1123  * @param vtzeroFeature The building feature, must be valid
1124  * @param outerPolygons The outer polygons of the building, can be empty
1125  * @param innerPolygons The inner polygons of the building, can be empty
1126  * @param lineStrings The line strings of the building, can be empty
1127  * @param layerExtent The extent of the layer in which the building is located, in pixels, with range [1, infinity)
1128  * @return The resulting building object, nullptr if the feature could not be parsed
1129  */
1130  static SharedObject parseBuilding(vtzero::feature& vtzeroFeature, PixelPositionGroupsI&& outerPolygons, PixelPositionGroupsI&& innerPolygons, PixelPositionGroupsI&& lineStrings, const unsigned int layerExtent);
1131 
1132  /**
1133  * Parses a road feature.
1134  * @param vtzeroFeature The building feature, must be valid
1135  * @param lineStrings The line strings of the transit, at least one
1136  * @param layerExtent The extent of the layer in which the transit is located, in pixels, with range [1, infinity)
1137  * @return The resulting road object, nullptr if the feature could not be parsed
1138  */
1139  static SharedObject parseRoad(vtzero::feature& vtzeroFeature, PixelPositionGroupsI&& lineStrings, const unsigned int layerExtent);
1140 
1141  /**
1142  * Parses a transit feature.
1143  * @param vtzeroFeature The building feature, must be valid
1144  * @param lineStrings The line strings of the transit, at least one
1145  * @param layerExtent The extent of the layer in which the transit is located, in pixels, with range [1, infinity)
1146  * @return The resulting transit object, nullptr if the feature could not be parsed
1147  */
1148  static SharedObject parseTransit(vtzero::feature& vtzeroFeature, PixelPositionGroupsI&& lineStrings, const unsigned int layerExtent);
1149 
1150  /**
1151  * Parses a water feature.
1152  * @param vtzeroFeature The building feature, must be valid
1153  * @param outerPolygons The outer polygons of the building, can be empty
1154  * @param innerPolygons The inner polygons of the building, can be empty
1155  * @param layerExtent The extent of the layer in which the building is located, in pixels, with range [1, infinity)
1156  * @return The resulting water object, nullptr if the feature could not be parsed
1157  */
1158  static SharedObject parseWater(vtzero::feature& vtzeroFeature, PixelPositionGroupsI&& outerPolygons, PixelPositionGroupsI&& innerPolygons, const unsigned int layerExtent);
1159 
1160  /**
1161  * Parses a land use feature.
1162  * @param vtzeroFeature The building feature, must be valid
1163  * @param outerPolygons The outer polygons of the building, can be empty
1164  * @param innerPolygons The inner polygons of the building, can be empty
1165  * @param lineStrings The line strings of the building, can be empty
1166  * @param layerExtent The extent of the layer in which the building is located, in pixels, with range [1, infinity)
1167  * @return The resulting land use object, nullptr if the feature could not be parsed
1168  */
1169  static SharedObject parseLandUse(vtzero::feature& vtzeroFeature, PixelPositionGroupsI&& outerPolygons, PixelPositionGroupsI&& innerPolygons, PixelPositionGroupsI&& lineStrings, const unsigned int layerExtent);
1170 
1171  /**
1172  * Parses a land cover feature.
1173  * @param vtzeroFeature The building feature, must be valid
1174  * @param outerPolygons The outer polygons of the building, can be empty
1175  * @param innerPolygons The inner polygons of the building, can be empty
1176  * @param lineStrings The line strings of the building, can be empty
1177  * @param layerExtent The extent of the layer in which the building is located, in pixels, with range [1, infinity)
1178  * @return The resulting land cover object, nullptr if the feature could not be parsed
1179  */
1180  static SharedObject parseLandCover(vtzero::feature& vtzeroFeature, PixelPositionGroupsI&& outerPolygons, PixelPositionGroupsI&& innerPolygons, PixelPositionGroupsI&& lineStrings, const unsigned int layerExtent);
1181 
1182  /**
1183  * Returns the value of a property value as number.
1184  * @param propertyValue The property value from which the number will be extracted
1185  * @param value The resulting number value
1186  * @return True, if succeeded
1187  */
1188  static bool numberFromPropertyValue(const vtzero::property_value& propertyValue, double& value);
1189 
1190  /**
1191  * Translates the name of a layer to the corresponding layer type.
1192  * @param layerName The name of the layer, must be valid
1193  * @return The resulting layer type, LT_UNKNOWN if unknown
1194  */
1195  static LayerType translateLayerName(const std::string& layerName);
1196 };
1197 
1198 inline Basemap::Object::Object(const ObjectType objectType, const unsigned int layerExtent) :
1199  objectType_(objectType),
1200  layerExtent_(layerExtent)
1201 {
1202  ocean_assert(objectType != OT_UNKNOWN);
1203 }
1204 
1205 inline unsigned int Basemap::Object::layerExtent() const
1206 {
1207  return layerExtent_;
1208 }
1209 
1210 inline Vector2 Basemap::Object::vectorFromCoordinate(const PixelPositionI& coordinate, const Scalar targetExtent) const
1211 {
1212  ocean_assert(layerExtent_ >= 1u);
1213  ocean_assert(coordinate.isValid() && targetExtent > Numeric::eps());
1214 
1215  return Vector2(Scalar(coordinate.x()), Scalar(coordinate.y())) * Scalar(targetExtent) / Scalar(layerExtent_);
1216 }
1217 
1219 {
1220  return objectType_;
1221 }
1222 
1223 inline Basemap::Road::Road(const RoadType roadType, std::string&& name, PixelPositionGroupsI&& lineStrings, const unsigned int layerExtent) :
1224  Object(OT_ROAD, layerExtent),
1225  roadType_(roadType),
1226  name_(std::move(name)),
1227  lineStrings_(std::move(lineStrings))
1228 {
1229  ocean_assert(!lineStrings_.empty());
1230 }
1231 
1233 {
1234  return roadType_;
1235 }
1236 
1238 {
1239  return lineStrings_;
1240 }
1241 
1242 inline Basemap::Transit::Transit(const TransitType transitType, std::string&& name, PixelPositionGroupsI&& lineStrings, const unsigned int layerExtent) :
1243  Object(OT_TRANSIT, layerExtent),
1244  transitType_(transitType),
1245  name_(std::move(name)),
1246  lineStrings_(std::move(lineStrings))
1247 {
1248  ocean_assert(!lineStrings_.empty());
1249 }
1250 
1252 {
1253  return transitType_;
1254 }
1255 
1257 {
1258  return lineStrings_;
1259 }
1260 
1261 inline Basemap::InnerOuterPolygonsObject::InnerOuterPolygonsObject(const ObjectType objectType, PixelPositionGroupsI&& outerPolygons, PixelPositionGroupsI&& innerPolygons, const unsigned int layerExtent) :
1262  Object(objectType, layerExtent),
1263  outerPolygons_(std::move(outerPolygons)),
1264  innerPolygons_(std::move(innerPolygons))
1265 {
1266  // nothing to do here
1267 }
1268 
1270 {
1271  return outerPolygons_;
1272 }
1273 
1275 {
1276  return innerPolygons_;
1277 }
1278 
1279 inline Basemap::Building::Building(PixelPositionGroupsI&& outerPolygons, PixelPositionGroupsI&& innerPolygons, PixelPositionGroupsI&& lineStrings, const Scalar height, const unsigned int layerExtent) :
1280  InnerOuterPolygonsObject(OT_BUILDING, std::move(outerPolygons), std::move(innerPolygons), layerExtent),
1281  height_(height),
1282  lineStrings_(std::move(lineStrings))
1283 {
1284  // nothing to do here
1285 }
1286 
1288 {
1289  return height_;
1290 }
1291 
1293 {
1294  return lineStrings_;
1295 }
1296 
1297 inline Basemap::Water::Water(const WaterType waterType, PixelPositionGroupsI&& outerPolygons, PixelPositionGroupsI&& innerPolygons, const unsigned int layerExtent) :
1298  InnerOuterPolygonsObject(OT_WATER, std::move(outerPolygons), std::move(innerPolygons), layerExtent),
1299  waterType_(waterType)
1300 {
1301  // nothing to do here
1302 }
1303 
1305 {
1306  return waterType_;
1307 }
1308 
1309 inline Basemap::LandUse::LandUse(const LandUseType landUseType, PixelPositionGroupsI&& outerPolygons, PixelPositionGroupsI&& innerPolygons, PixelPositionGroupsI&& lineStrings, const unsigned int layerExtent) :
1310  InnerOuterPolygonsObject(OT_LAND_USE, std::move(outerPolygons), std::move(innerPolygons), layerExtent),
1311  landUseType_(landUseType),
1312  lineStrings_(std::move(lineStrings))
1313 {
1314  // nothing to do here
1315 }
1316 
1318 {
1319  return landUseType_;
1320 }
1321 
1323 {
1324  return lineStrings_;
1325 }
1326 
1327 inline Basemap::LandCover::LandCover(const LandCoverType landCoverType, PixelPositionGroupsI&& outerPolygons, PixelPositionGroupsI&& innerPolygons, PixelPositionGroupsI&& lineStrings, const unsigned int layerExtent) :
1328  InnerOuterPolygonsObject(OT_LAND_COVER, std::move(outerPolygons), std::move(innerPolygons), layerExtent),
1329  landCoverType_(landCoverType),
1330  lineStrings_(std::move(lineStrings))
1331 {
1332  // nothing to do here
1333 }
1334 
1336 {
1337  return landCoverType_;
1338 }
1339 
1341 {
1342  return lineStrings_;
1343 }
1344 
1345 inline Basemap::TileIndexPair::TileIndexPair(const unsigned int latitudeIndex, const unsigned int longitudeIndex) :
1346  latitudeIndex_(latitudeIndex),
1347  longitudeIndex_(longitudeIndex)
1348 {
1349  ocean_assert(isValid());
1350 }
1351 
1352 inline unsigned int Basemap::TileIndexPair::latitudeIndex() const
1353 {
1354  return latitudeIndex_;
1355 }
1356 
1357 inline unsigned int Basemap::TileIndexPair::longitudeIndex() const
1358 {
1359  return longitudeIndex_;
1360 }
1361 
1362 inline bool Basemap::TileIndexPair::isInside(const unsigned int numberTiles) const
1363 {
1364  return latitudeIndex_ < numberTiles && longitudeIndex_ < numberTiles;
1365 }
1366 
1368 {
1369  return latitudeIndex_ != (unsigned int)(-1) && longitudeIndex_ != (unsigned int)(-1);
1370 }
1371 
1372 inline bool Basemap::TileIndexPair::operator==(const TileIndexPair& other) const
1373 {
1374  return latitudeIndex_ == other.latitudeIndex_ && longitudeIndex_ == other.longitudeIndex_;
1375 }
1376 
1377 inline bool Basemap::TileIndexPair::operator!=(const TileIndexPair& other) const
1378 {
1379  return !(*this == other);
1380 }
1381 
1382 inline size_t Basemap::TileIndexPair::operator()(const TileIndexPair& tileIndexPair) const
1383 {
1384  return size_t(tileIndexPair.latitudeIndex_) ^ size_t(tileIndexPair.longitudeIndex_);
1385 }
1386 
1387 inline Basemap::Tile::Tile(const unsigned int level, const TileIndexPair& tileIndexPair) :
1388  level_(level),
1389  tileIndexPair_(tileIndexPair)
1390 {
1391  ocean_assert(isValid());
1392 }
1393 
1394 inline unsigned int Basemap::Tile::level() const
1395 {
1396  return level_;
1397 }
1398 
1400 {
1401  return tileIndexPair_;
1402 }
1403 
1405 {
1406  return objects_;
1407 }
1408 
1409 inline bool Basemap::Tile::isValid() const
1410 {
1411  return level_ >= 1u && level_ <= 22u && tileIndexPair_.isValid() && tileIndexPair_.latitudeIndex() < numberTiles(level_) && tileIndexPair_.longitudeIndex() < numberTiles(level_);
1412 }
1413 
1414 constexpr inline unsigned int Basemap::Tile::numberTiles(const unsigned int level)
1415 {
1416  ocean_assert(level >= 1u && level < 22u);
1417 
1418  return 1u << level;
1419 }
1420 
1421 }
1422 
1423 }
1424 
1425 }
1426 
1427 #endif // META_OCEAN_IO_MAPS_BASEMAP_H
This class implements a 2D bounding box with pixel precision.
Definition: PixelBoundingBox.h:57
This class implements a 2D pixel position with pixel precision.
Definition: PixelPosition.h:65
bool isValid() const
Returns whether this pixel position object holds two valid parameters.
T y() const
Returns the vertical coordinate position of this object.
Definition: PixelPosition.h:470
T x() const
Returns the horizontal coordinate position of this object.
Definition: PixelPosition.h:458
This class implements a building object.
Definition: Basemap.h:365
Building(PixelPositionGroupsI &&outerPolygons, PixelPositionGroupsI &&innerPolygons, PixelPositionGroupsI &&lineStrings, const Scalar height, const unsigned int layerExtent)
Creates a new building.
Definition: Basemap.h:1279
Scalar height() const
Returns the height of the building.
Definition: Basemap.h:1287
CV::PixelBoundingBoxI boundingBox() const
Returns the pixel bounding box entirely enclosing this building.
Scalar height_
The height of the bulding in meter, with range [0, infinity), -1 if unknown.
Definition: Basemap.h:399
PixelPositionGroupsI lineStrings_
The individual line strings of this building.
Definition: Basemap.h:402
const PixelPositionGroupsI & lineStrings() const
The individual line strings of this building.
Definition: Basemap.h:1292
Geometry handler for polygons.
Definition: Basemap.h:929
PixelPositionsI intermediatePolygons_
The points of the current active polygon.
Definition: Basemap.h:959
PixelPositionGroupsI outerPolygons_
The individual outer polygons.
Definition: Basemap.h:962
void ring_begin(uint32_t count)
This is called at the beginning of each ring with the number of points in this ring.
void reset()
Resets the handler so that it can be reused.
void ring_end(vtzero::ring_type ringType)
This is called at the end of each ring.
void ring_point(vtzero::point point)
This is called once for each point.
PixelPositionGroupsI innerPolygons_
the indvidual inner polygons.
Definition: Basemap.h:965
Geometry handler for line strings.
Definition: Basemap.h:972
void reset()
Resets the handler so that it can be reused.
PixelPositionGroupsI lineStrings_
The individual line strings.
Definition: Basemap.h:1001
void linestring_end()
This is called at the end of each linestring.
void linestring_point(vtzero::point point)
This is called once for each point.
void linestring_begin(uint32_t count)
This is called at the beginning of each linestring with the number of points in this linestring.
Geometry handler for points.
Definition: Basemap.h:893
void points_end()
This is called once at the end.
void reset()
Resets the handler so that it can be reused.
void points_begin(uint32_t count)
This is called once at the beginning with the number of points.
PixelPositionsI points_
The gathered points of this handler.
Definition: Basemap.h:922
void points_point(vtzero::point point)
This is called once for each point.
This class implements an object composed of inner and outer polygons.
Definition: Basemap.h:326
PixelPositionGroupsI innerPolygons_
The individual inner pologyons of this building.
Definition: Basemap.h:358
PixelPositionGroupsI outerPolygons_
The individual outer polygons of this building.
Definition: Basemap.h:355
const PixelPositionGroupsI & innerPolygons() const
Returns the individual inner poloyons of this building.
Definition: Basemap.h:1274
InnerOuterPolygonsObject(const ObjectType objectType, PixelPositionGroupsI &&outerPolygons, PixelPositionGroupsI &&innerPolygons, const unsigned int layerExtent)
Creates a new object.
Definition: Basemap.h:1261
const PixelPositionGroupsI & outerPolygons() const
Returns the individual outer polygons of this building.
Definition: Basemap.h:1269
This class implements a land use object.
Definition: Basemap.h:551
PixelPositionGroupsI lineStrings_
The individual line strings of this building.
Definition: Basemap.h:599
LandCoverType
Definition of individual land use types.
Definition: Basemap.h:558
@ LCT_GRASS
The land is covered with grass.
Definition: Basemap.h:562
@ LCT_PAVED
The land is paved.
Definition: Basemap.h:564
const PixelPositionGroupsI & lineStrings() const
Returns the line strings defining the shape of the transit in the domain of the layer to which this t...
Definition: Basemap.h:1340
LandCoverType landCoverType() const
Returns the type of the land use.
Definition: Basemap.h:1335
LandCover(const LandCoverType landCoverType, PixelPositionGroupsI &&outerPolygons, PixelPositionGroupsI &&innerPolygons, PixelPositionGroupsI &&lineStrings, const unsigned int layerExtent)
Creates a new land cover.
Definition: Basemap.h:1327
This class implements a land use object.
Definition: Basemap.h:486
LandUseType landUseType() const
Returns the type of the land use.
Definition: Basemap.h:1317
PixelPositionGroupsI lineStrings_
The individual line strings of this building.
Definition: Basemap.h:544
LandUseType
Definition of individual land use types.
Definition: Basemap.h:493
@ LUT_AIRPORT
The land use is an airport.
Definition: Basemap.h:497
@ LUT_PLAZA
The land use is a plaza.
Definition: Basemap.h:509
@ LUT_NATIONAL_PARK
The land use is a national park.
Definition: Basemap.h:507
@ LUT_AMUSEMENT
The land is used for amusement.
Definition: Basemap.h:499
@ LUT_EDUCATION
The land use is education.
Definition: Basemap.h:501
@ LUT_GREENSPACE
The land use is a green space.
Definition: Basemap.h:503
@ LUT_LAND
The land use is a land.
Definition: Basemap.h:505
const PixelPositionGroupsI & lineStrings() const
Returns the line strings defining the shape of the transit in the domain of the layer to which this t...
Definition: Basemap.h:1322
LandUse(const LandUseType landUseType, PixelPositionGroupsI &&outerPolygons, PixelPositionGroupsI &&innerPolygons, PixelPositionGroupsI &&lineStrings, const unsigned int layerExtent)
Creates a new land use.
Definition: Basemap.h:1309
This class is the base class for all map objects.
Definition: Basemap.h:56
ObjectType objectType() const
Returns the type of this object.
Definition: Basemap.h:1218
ObjectType
Definition of individual object types.
Definition: Basemap.h:63
@ OT_UNKNOWN
The object type is unknown.
Definition: Basemap.h:65
@ OT_LAND_COVER
The object is a land cover.
Definition: Basemap.h:69
@ OT_BUILDING
The object is a building.
Definition: Basemap.h:67
@ OT_ROAD
The object is a road.
Definition: Basemap.h:73
@ OT_LAND_USE
The object is a land use.
Definition: Basemap.h:71
@ OT_TRANSIT
The object is a transit.
Definition: Basemap.h:75
unsigned int layerExtent() const
Returns the extent of the layer in which this object is defined.
Definition: Basemap.h:1205
Object(const ObjectType objectType, const unsigned int layerExtent)
Creates a new object.
Definition: Basemap.h:1198
Vector2 vectorFromCoordinate(const PixelPositionI &coordinate, const Scalar targetExtent) const
Converts the coordinate defined in the owning layer of this object to a target domain with individual...
Definition: Basemap.h:1210
This class implements a road object.
Definition: Basemap.h:124
std::unordered_map< std::string, RoadType > RoadTypeMap
Definition of an unordered map mapping road type strings to road type values.
Definition: Basemap.h:216
const PixelPositionGroupsI & lineStrings() const
Returns the line strings defining the shape of the road in the domain of the layer to which this road...
Definition: Basemap.h:1237
static RoadWidthMap defaultRoadWidthMap()
Returns the default map for road widths.
RoadType roadType_
The type of this road.
Definition: Basemap.h:258
std::string name_
The name of this road, if known.
Definition: Basemap.h:261
RoadType
Definition of individual road types.
Definition: Basemap.h:131
@ RT_LOCAL
A local street.
Definition: Basemap.h:159
@ RT_ACCESS
A road to provide access.
Definition: Basemap.h:135
@ RT_STEPS
A path/road with steps.
Definition: Basemap.h:189
@ RT_CROSSING
The road is a crossing.
Definition: Basemap.h:141
@ RT_SIDEWALK
The road is a sidewalk.
Definition: Basemap.h:187
@ RT_PARKING_AISLE
The road is a parking aisle.
Definition: Basemap.h:165
@ RT_DRIVEWAY
The road is a driveway.
Definition: Basemap.h:147
@ RT_LINK
A link.
Definition: Basemap.h:155
@ RT_ROAD
A default road.
Definition: Basemap.h:179
@ RT_SECONDARY
A secondary road.
Definition: Basemap.h:181
@ RT_HIGHWAY_LINK
A highway link.
Definition: Basemap.h:153
@ RT_PEDESTRIAN
A pedestrian road.
Definition: Basemap.h:169
@ RT_CROSSWALK
The road is a crosswalk.
Definition: Basemap.h:145
@ RT_MOTORWAY
A motorway.
Definition: Basemap.h:161
@ RT_TRACK
A track.
Definition: Basemap.h:195
@ RT_LIVING_STREET
A living street.
Definition: Basemap.h:157
@ RT_SERVICE
A service road.
Definition: Basemap.h:185
@ RT_MOTORWAY_LINK
A motorway link.
Definition: Basemap.h:163
@ RT_HIGHWAY
A highway.
Definition: Basemap.h:151
@ RT_RESIDENTIAL
A residential road.
Definition: Basemap.h:171
@ RT_SECONDARY_LINK
A secondary link.
Definition: Basemap.h:183
@ RT_CYCLEWAY
A cycleway.
Definition: Basemap.h:143
@ RT_PRIMARY_LINK
A primary link road.
Definition: Basemap.h:175
@ RT_PATH
The road is a path.
Definition: Basemap.h:167
@ RT_ALLEY
The road is an alley.
Definition: Basemap.h:137
@ RT_UNCLASSIFIED
An unclassified road.
Definition: Basemap.h:201
@ RT_FOOTWAY
The road is a footway.
Definition: Basemap.h:149
@ RT_RACEWAY
The road is a raceway.
Definition: Basemap.h:177
@ RT_TERTIARY
A tertiary road.
Definition: Basemap.h:191
@ RT_TRUNK_LINK
A trunk link.
Definition: Basemap.h:199
@ RT_TRUNK
A trunk road.
Definition: Basemap.h:197
@ RT_PRIMARY
A primary road.
Definition: Basemap.h:173
@ RT_BRIDLEWAY
The road is a bridleway (e.g., mainly used by horses).
Definition: Basemap.h:139
@ RT_TERTIARY_LINK
A tertiary link.
Definition: Basemap.h:193
RoadType roadType() const
Returns the type of this road.
Definition: Basemap.h:1232
static RoadType translateRoadType(const std::string &roadType)
Translates the string of a road type to a value.
std::unordered_map< RoadType, float > RoadWidthMap
Definition of an unordered map mapping road types to road widths.
Definition: Basemap.h:209
Road(const RoadType roadType, std::string &&name, PixelPositionGroupsI &&lineStrings, const unsigned int layerExtent)
Creates a new road.
Definition: Basemap.h:1223
PixelPositionGroupsI lineStrings_
The line strings defining the shape of the road in the domain of the layer to which this road belongs...
Definition: Basemap.h:264
This class stores the information belonging to one map tile.
Definition: Basemap.h:723
TileIndexPair tileIndexPair_
The tile index pair of the tile in latitude/vertical direction within the detail level,...
Definition: Basemap.h:876
static constexpr unsigned int numberTiles(const unsigned int level)
Returns the number of tiles in horizontal and vertical direction for a given detail level.
Definition: Basemap.h:1414
static void tileCoordinate2GPSLocation(const unsigned int level, const TileIndexPair &tileIndexPair, const PixelPositionI &position, const unsigned int layerExtent, double &latitude, double &longitude)
Returns the approximated GPS location of a position in a tile.
void clear()
Removes all map objects, the level and tile information is untought.
Tile & operator=(Tile &&tile)=default
Default move operator.
const TileIndexPair & tileIndexPair() const
Returns the tile index pair definining the tile's location.
Definition: Basemap.h:1399
static TileIndexPair calculateTile(const unsigned int level, const double latitude, const double longitude, double *latitudeTileFraction=nullptr, double *longitudeTileFraction=nullptr)
Calculates the tile in which a given GPS coordinate is located at a specified detail level.
SharedObjects objects_
The map objects of in this tile.
Definition: Basemap.h:879
static void calculateTileFractions(const unsigned int level, const double latitude, const double longitude, const TileIndexPair &tileIndexPair, double &latitudeTileFraction, double &longitudeTileFraction)
Calculates the tile fraction ini latitude and longitude for a given GPS coordinate in relation to a g...
double metricExtent(const double earthRadius=6378135.0) const
Returns the metric extent of this tile.
static double calculateNormalizedTileLongitude(const double longitude)
Calculates the tile in which a given GPS coordinate is located in longitude direction with sub-tile a...
void tileCoordinate2GPSLocation(const PixelPositionI &position, const unsigned int layerExtent, double &latitude, double &longitude) const
Returns the approximated GPS location of a position in this tile.
Tile(Tile &&tile)=default
Default move constructor.
unsigned int level() const
Returns the detail level of this tile.
Definition: Basemap.h:1394
bool parsePBFData(const void *data, const size_t size)
Parses a buffer containing the tile information as pbf file.
static double calculateNormalizedTileLatitude(const double latitude)
Calculates the tile in which a given GPS coordinate is located in latitude direction with sub-tile ac...
const SharedObjects & objects() const
Returns all objects of this tile.
Definition: Basemap.h:1404
Tile()=default
Default constructor creating an invalid tile.
bool isValid() const
Returns whether this tile is valid.
Definition: Basemap.h:1409
This class holds the tile indics in latitude and longitude direction.
Definition: Basemap.h:624
size_t operator()(const TileIndexPair &tileIndexPair) const
Hash function.
Definition: Basemap.h:1382
unsigned int latitudeIndex() const
Returns the tile index in latitude direction.
Definition: Basemap.h:1352
bool isLocationClose(const TileIndexPair &tileIndexPair, const double latitudeFraction, const double longitudeFraction, const double maxFraction=0.2) const
Returns whether a given location is close to this tile.
bool isInside(const unsigned int numberTiles) const
Returns whether this tile index pair is within the range of a maximal number of tiles.
Definition: Basemap.h:1362
static TileIndexPairs createNeighborhoodTiles(const TileIndexPair &tileIndexPair, const unsigned int numberTilesOnLevel, const unsigned int maxDistance)
Returns the tile index pairs of all neighboring tiles for a given center tile.
bool operator!=(const TileIndexPair &other) const
Returns whether two tile index pair objects hold not the same indices.
Definition: Basemap.h:1377
unsigned int longitudeIndex_
The tile index in longitude direction, with range [0, infinity).
Definition: Basemap.h:711
unsigned int longitudeIndex() const
Returns the tile index in longitude direction.
Definition: Basemap.h:1357
unsigned int latitudeIndex_
The tile index in latitude direction, with range [0, infinity).
Definition: Basemap.h:708
TileIndexPair()=default
Default constructor creating an invalid pair of indices.
bool operator==(const TileIndexPair &other) const
Returns whether two tile index pair objects hold the same indices.
Definition: Basemap.h:1372
bool isValid() const
Returns whether the this object holds valid tile indices.
Definition: Basemap.h:1367
This class implements a transit object.
Definition: Basemap.h:271
PixelPositionGroupsI lineStrings_
The line strings defining the shape of the transit in the domain of the layer to which this transit b...
Definition: Basemap.h:319
TransitType
Definition of individual transit types.
Definition: Basemap.h:278
@ TT_FERRY
A ferry.
Definition: Basemap.h:284
@ TT_AERIALWAY
Aerial transit way e.g., for planes.
Definition: Basemap.h:282
TransitType transitType_
The type of this transit.
Definition: Basemap.h:313
std::string name_
The name of this transit, if known.
Definition: Basemap.h:316
const PixelPositionGroupsI & lineStrings() const
Returns the line strings defining the shape of the transit in the domain of the layer to which this t...
Definition: Basemap.h:1256
TransitType transitType() const
Returns the type of this transit.
Definition: Basemap.h:1251
Transit(const TransitType transitType, std::string &&name, PixelPositionGroupsI &&lineStrings, const unsigned int layerExtent)
Creates a new transit object.
Definition: Basemap.h:1242
This class implements a water object.
Definition: Basemap.h:409
Water(const WaterType waterType, PixelPositionGroupsI &&outerPolygons, PixelPositionGroupsI &&innerPolygons, const unsigned int layerExtent)
Creates a new water.
Definition: Basemap.h:1297
std::unordered_map< std::string, WaterType > WaterTypeMap
Definition of an unordered map mapping water type strings to water type values.
Definition: Basemap.h:450
WaterType waterType() const
Returns the type of the water.
Definition: Basemap.h:1304
static WaterType translateWaterType(const std::string &waterType)
Translates the string of a water type to a value.
WaterType
Definition of individual water types.
Definition: Basemap.h:416
@ WT_OCEAN
The water is an ocean.
Definition: Basemap.h:430
@ WT_LAKE
The water is a lake.
Definition: Basemap.h:428
@ WT_HUMAN_MADE
The water is human made.
Definition: Basemap.h:424
@ WT_INLAND
An inland water.
Definition: Basemap.h:426
@ WT_POND
The water is a pond.
Definition: Basemap.h:432
@ WT_CANAL
The water is a canal.
Definition: Basemap.h:420
@ WT_WATER
The water without further specification.
Definition: Basemap.h:440
@ WT_DOCK
The water is a dock.
Definition: Basemap.h:422
@ WT_STREAM
The water is a stream.
Definition: Basemap.h:438
@ WT_RESERVOIR
The water is a reservoir.
Definition: Basemap.h:434
@ WT_RIVER
The water is a river.
Definition: Basemap.h:436
This class implements an parser of basemap data.
Definition: Basemap.h:33
std::vector< PixelPositionsI > PixelPositionGroupsI
Definition of groups of pixel positions.
Definition: Basemap.h:49
LayerType
Definition of individual layer types.
Definition: Basemap.h:1008
@ LT_LAND_USE
The layer holds land use information (mostly polygons for land usages).
Definition: Basemap.h:1030
@ LT_PLACE_LABEL
The layer holds place labels.
Definition: Basemap.h:1044
@ LT_LAND_USE_LABEL
The layer holds labels of land use (label point centroid for polygonal land usages).
Definition: Basemap.h:1032
@ LT_INDOOR_LABEL
The layer holds indoor label information (labels for indoor features).
Definition: Basemap.h:1026
@ LT_WATER_LABEL
The layer holds water label information (label point centroid for polygonal water).
Definition: Basemap.h:1060
@ LT_WATERWAY
The layer holds waterway information (linear water features).
Definition: Basemap.h:1058
@ LT_PARKING
The layer holds parking information (experimental parking layer, point & polygon).
Definition: Basemap.h:1040
@ LT_LANDMARK_POINT
The layer holds landmark point information.
Definition: Basemap.h:1034
@ LT_BUILDING_LABEL
The layer holds labels of buildings (label point centroid for polygonal structures).
Definition: Basemap.h:1020
@ LT_AREA_OF_INTEREST
The layer holds areas of interest (polygonal areas of interest).
Definition: Basemap.h:1014
@ LT_POI
The layer holds a point of interest.
Definition: Basemap.h:1046
@ LT_LAND_COVER
The layer holds land cover information (polygons for physical land features).
Definition: Basemap.h:1028
@ LT_TREE_POINT
The layer holds tree point information (point features for trees).
Definition: Basemap.h:1054
@ LT_WATER_OFFSET
The layer holds water offset information (polygons used for creating a shadow effect on inland water ...
Definition: Basemap.h:1064
@ LT_BORDER
The layer holds a border.
Definition: Basemap.h:1022
@ LT_TRANSIT_POINT
The layer holds transit point information (aerial, rail, ferry stations).
Definition: Basemap.h:1052
@ LT_NATURAL
The layer holds natural areas.
Definition: Basemap.h:1036
@ LT_BUILDING
The layer holds buildings (polygonal structures).
Definition: Basemap.h:1018
@ LT_AIRPORT
The layer holds information about an airport (point, line, & polygon airport features).
Definition: Basemap.h:1012
@ LT_INDOOR
The layer is an indoor layer (floor plans for meta offices, malls, airports).
Definition: Basemap.h:1024
@ LT_WAVE
The layer holds wave information (points used to show a wave icon over water).
Definition: Basemap.h:1066
@ LT_TRANSIT
The layer holds transit information (aerial, rail, ferry; linear features).
Definition: Basemap.h:1050
@ LT_BATHYMETRY
The layer holds bathymetry information (depth polygons for oceans).
Definition: Basemap.h:1016
@ LT_ROAD
The layer holds road data (linear features for roads, sidewalks).
Definition: Basemap.h:1048
@ LT_NATURAL_LABEL
The layer holds labels of natural areas.
Definition: Basemap.h:1038
@ LT_WATER_LINE
The layer holds water line information.
Definition: Basemap.h:1062
@ LT_WATER
The layer holds water information (polygonal water features).
Definition: Basemap.h:1056
@ LT_PLACENAME
The layer holds labels of places (point features for cities, neighborhoods).
Definition: Basemap.h:1042
static SharedTile newTileFromPBFData(const unsigned int level, const TileIndexPair &tileIndexPair, const void *data, const size_t size)
Creates a new tile based on given PBF data.
std::shared_ptr< Tile > SharedTile
Definition of a shared pointer holding a Tile.
Definition: Basemap.h:885
static SharedObject parseLandCover(vtzero::feature &vtzeroFeature, PixelPositionGroupsI &&outerPolygons, PixelPositionGroupsI &&innerPolygons, PixelPositionGroupsI &&lineStrings, const unsigned int layerExtent)
Parses a land cover feature.
static bool numberFromPropertyValue(const vtzero::property_value &propertyValue, double &value)
Returns the value of a property value as number.
static SharedObject parseRoad(vtzero::feature &vtzeroFeature, PixelPositionGroupsI &&lineStrings, const unsigned int layerExtent)
Parses a road feature.
CV::PixelPositionI PixelPositionI
Definition of a location with signed pixel precision.
Definition: Basemap.h:39
std::vector< TileIndexPair > TileIndexPairs
Definition of a vector holding tile index pairs.
Definition: Basemap.h:613
std::unordered_set< TileIndexPair, TileIndexPair > TileIndexPairSet
Definition of a set holding tile index pairs.
Definition: Basemap.h:717
static bool extractTileUrlTemplate(const char *styleData, const size_t styleSize, std::string &urlTemplate)
Gets the url template for downloading a map tile.
static const std::string & styleUrl()
Returns the url for downloading the map style data.
std::unordered_map< std::string, LayerType > LayerTypeMap
Definition of an unordered map mapping layer type strings to layer type values.
Definition: Basemap.h:1074
static SharedObject parseWater(vtzero::feature &vtzeroFeature, PixelPositionGroupsI &&outerPolygons, PixelPositionGroupsI &&innerPolygons, const unsigned int layerExtent)
Parses a water feature.
std::vector< SharedObject > SharedObjects
Definition of a vector holding shared objects.
Definition: Basemap.h:610
static bool constructTileUrl(const std::string urlTemplate, const unsigned int level, const TileIndexPair &tileIndexPair, std::string &url)
Constructs the url for downloading a map tile.
CV::PixelPositionsI PixelPositionsI
Definition of a vector holding locations with signed pixel precision.
Definition: Basemap.h:44
static SharedObject parseBuilding(vtzero::feature &vtzeroFeature, PixelPositionGroupsI &&outerPolygons, PixelPositionGroupsI &&innerPolygons, PixelPositionGroupsI &&lineStrings, const unsigned int layerExtent)
Parses a building feature.
std::shared_ptr< Object > SharedObject
Definition of a shared pointer holding an Object.
Definition: Basemap.h:605
static LayerType translateLayerName(const std::string &layerName)
Translates the name of a layer to the corresponding layer type.
static SharedObject parseLandUse(vtzero::feature &vtzeroFeature, PixelPositionGroupsI &&outerPolygons, PixelPositionGroupsI &&innerPolygons, PixelPositionGroupsI &&lineStrings, const unsigned int layerExtent)
Parses a land use feature.
static SharedObject parseTransit(vtzero::feature &vtzeroFeature, PixelPositionGroupsI &&lineStrings, const unsigned int layerExtent)
Parses a transit feature.
static constexpr T eps()
Returns a small epsilon.
std::vector< PixelPositionI > PixelPositionsI
Definition of a vector holding pixel positions (with positive and negative coordinate values).
Definition: PixelPosition.h:55
float Scalar
Definition of a scalar type.
Definition: Math.h:128
VectorT2< Scalar > Vector2
Definition of a 2D vector.
Definition: Vector2.h:21
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15