GEOS  3.10.0
IndexedPointInAreaLocator.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2006 Refractions Research Inc.
7  * Copyright (C) 2018 Daniel Baston <dbaston@gmail.com>
8  *
9  * This is free software; you can redistribute and/or modify it under
10  * the terms of the GNU Lesser General Public Licence as published
11  * by the Free Software Foundation.
12  * See the COPYING file for more information.
13  *
14  *
15  **********************************************************************/
16 
17 #ifndef GEOS_ALGORITHM_LOCATE_INDEXEDPOINTINAREALOCATOR_H
18 #define GEOS_ALGORITHM_LOCATE_INDEXEDPOINTINAREALOCATOR_H
19 
20 #include <geos/geom/LineSegment.h>
21 #include <geos/algorithm/locate/PointOnGeometryLocator.h> // inherited
22 #include <geos/index/ItemVisitor.h> // inherited
23 #include <geos/index/strtree/TemplateSTRtree.h>
24 
25 #include <memory>
26 #include <vector> // composition
27 
28 namespace geos {
29 namespace algorithm {
30 class RayCrossingCounter;
31 }
32 namespace geom {
33 class Geometry;
34 class Coordinate;
35 class CoordinateSequence;
36 }
37 }
38 
39 namespace geos {
40 namespace algorithm { // geos::algorithm
41 namespace locate { // geos::algorithm::locate
42 
56 private:
57  struct SegmentView {
58  SegmentView(const geom::Coordinate* p_p0, const geom::Coordinate* p_p1) : m_p0(p_p0) {
59  // All GEOS CoordinateSequences store their coordinates sequentially.
60  // Should that ever change, this assert will fail.
61  (void) p_p1;
62  assert(p_p0 + 1 == p_p1);
63  }
64 
65  const geom::Coordinate& p0() const {
66  return *m_p0;
67  }
68 
69  const geom::Coordinate& p1() const {
70  return *(m_p0 + 1);
71  }
72 
73  const geom::Coordinate* m_p0;
74  };
75 
76  class IntervalIndexedGeometry {
77  private:
78 
79  index::strtree::TemplateSTRtree<SegmentView, index::strtree::IntervalTraits> index;
80 
81  void init(const geom::Geometry& g);
82  void addLine(const geom::CoordinateSequence* pts);
83 
84  public:
85  IntervalIndexedGeometry(const geom::Geometry& g);
86 
87  template<typename Visitor>
88  void query(double min, double max, Visitor&& f) {
89  index.query(index::strtree::Interval(min, max), f);
90  }
91  };
92 
93  const geom::Geometry& areaGeom;
94  std::unique_ptr<IntervalIndexedGeometry> index;
95 
96  void buildIndex(const geom::Geometry& g);
97 
98  // Declare type as noncopyable
100  IndexedPointInAreaLocator& operator=(const IndexedPointInAreaLocator& rhs) = delete;
101 
102 public:
111 
112  const geom::Geometry& getGeometry() const {
113  return areaGeom;
114  }
115 
123  geom::Location locate(const geom::Coordinate* /*const*/ p) override;
124 
125 };
126 
127 } // geos::algorithm::locate
128 } // geos::algorithm
129 } // geos
130 
131 #endif // GEOS_ALGORITHM_LOCATE_INDEXEDPOINTINAREALOCATOR_H
Determines the location of Coordinates relative to an areal geometry, using indexing for efficiency.
Definition: IndexedPointInAreaLocator.h:55
IndexedPointInAreaLocator(const geom::Geometry &g)
Creates a new locator for a given Geometry.
geom::Location locate(const geom::Coordinate *p) override
Determines the Location of a point in an areal Geometry.
An interface for classes which determine the Location of points in Polygon or MultiPolygon geometries...
Definition: PointOnGeometryLocator.h:37
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:58
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:188
A contiguous portion of 1D-space. Used internally by SIRtree.
Definition: strtree/Interval.h:30
Location
Constants representing the location of a point relative to a geometry.
Definition: Location.h:34
Basic namespace for all GEOS functionalities.
Definition: Angle.h:26