GEOS 3.11.1
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#pragma once
18
19#include <geos/geom/LineSegment.h>
20#include <geos/algorithm/locate/PointOnGeometryLocator.h> // inherited
21#include <geos/index/ItemVisitor.h> // inherited
22#include <geos/index/strtree/TemplateSTRtree.h>
23
24#include <memory>
25#include <vector> // composition
26
27namespace geos {
28namespace algorithm {
29class RayCrossingCounter;
30}
31namespace geom {
32class Geometry;
33class Coordinate;
34class CoordinateSequence;
35}
36}
37
38namespace geos {
39namespace algorithm { // geos::algorithm
40namespace locate { // geos::algorithm::locate
41
55private:
56 struct SegmentView {
57 SegmentView(const geom::Coordinate* p_p0, const geom::Coordinate* p_p1) : m_p0(p_p0) {
58 // All GEOS CoordinateSequences store their coordinates sequentially.
59 // Should that ever change, this assert will fail.
60 (void) p_p1;
61 assert(p_p0 + 1 == p_p1);
62 }
63
64 const geom::Coordinate& p0() const {
65 return *m_p0;
66 }
67
68 const geom::Coordinate& p1() const {
69 return *(m_p0 + 1);
70 }
71
72 const geom::Coordinate* m_p0;
73 };
74
75 class IntervalIndexedGeometry {
76 private:
77
78 index::strtree::TemplateSTRtree<SegmentView, index::strtree::IntervalTraits> index;
79
80 void init(const geom::Geometry& g);
81 void addLine(const geom::CoordinateSequence* pts);
82
83 public:
84 IntervalIndexedGeometry(const geom::Geometry& g);
85
86 template<typename Visitor>
87 void query(double min, double max, Visitor&& f) {
88 index.query(index::strtree::Interval(min, max), f);
89 }
90 };
91
92 const geom::Geometry& areaGeom;
93 std::unique_ptr<IntervalIndexedGeometry> index;
94
95 void buildIndex(const geom::Geometry& g);
96
97 // Declare type as noncopyable
99 IndexedPointInAreaLocator& operator=(const IndexedPointInAreaLocator& rhs) = delete;
100
101public:
110
111 const geom::Geometry& getGeometry() const {
112 return areaGeom;
113 }
114
122 geom::Location locate(const geom::Coordinate* /*const*/ p) override;
123
124};
125
126} // geos::algorithm::locate
127} // geos::algorithm
128} // geos
129
Determines the location of Coordinates relative to an areal geometry, using indexing for efficiency.
Definition: IndexedPointInAreaLocator.h:54
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:36
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:44
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:58
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:186
A contiguous portion of 1D-space. Used internally by SIRtree.
Definition: strtree/Interval.h:29
Location
Constants representing the location of a point relative to a geometry.
Definition: Location.h:32
Basic namespace for all GEOS functionalities.
Definition: geos.h:39