GEOS  3.8.0dev
LinearLocation.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2011 Sandro Santilli <strk@kbt.io>
7  * Copyright (C) 2005-2006 Refractions Research Inc.
8  * Copyright (C) 2001-2002 Vivid Solutions Inc.
9  *
10  * This is free software; you can redistribute and/or modify it under
11  * the terms of the GNU Lesser General Public Licence as published
12  * by the Free Software Foundation.
13  * See the COPYING file for more information.
14  *
15  **********************************************************************
16  *
17  * Last port: linearref/LinearLocation.java r463
18  *
19  **********************************************************************/
20 
21 #ifndef GEOS_LINEARREF_LINEARLOCATION_H
22 #define GEOS_LINEARREF_LINEARLOCATION_H
23 
24 #include <string>
25 #include <memory> // for std::unique_ptr
26 
27 #include <geos/geom/Coordinate.h>
28 #include <geos/geom/Geometry.h>
29 #include <geos/geom/LineSegment.h>
30 
31 namespace geos {
32 namespace linearref { // geos::linearref
33 
34 
45 private:
46  size_t componentIndex;
47  size_t segmentIndex;
48  double segmentFraction;
49 
58  void normalize();
59 
60 public:
68  static LinearLocation getEndLocation(const geom::Geometry* linear);
69 
87  double frac);
88 
89 
93  LinearLocation(size_t segmentIndex = 0, double segmentFraction = 0.0);
94 
95  LinearLocation(size_t componentIndex, size_t segmentIndex, double segmentFraction);
96 
102  void clamp(const geom::Geometry* linear);
103 
111  void snapToVertex(const geom::Geometry* linearGeom, double minDistance);
112 
120  double getSegmentLength(const geom::Geometry* linearGeom) const;
121 
128  void setToEnd(const geom::Geometry* linear);
129 
135  size_t getComponentIndex() const;
136 
142  size_t getSegmentIndex() const;
143 
149  double getSegmentFraction() const;
150 
156  bool isVertex() const;
157 
165  geom::Coordinate getCoordinate(const geom::Geometry* linearGeom) const;
166 
174  std::unique_ptr<geom::LineSegment> getSegment(const geom::Geometry* linearGeom) const;
175 
183  bool isValid(const geom::Geometry* linearGeom) const;
184 
193  int compareTo(const LinearLocation& other) const;
194 
204  int compareLocationValues(size_t componentIndex1, size_t segmentIndex1, double segmentFraction1) const;
205 
219  static int compareLocationValues(
220  size_t componentIndex0, size_t segmentIndex0, double segmentFraction0,
221  size_t componentIndex1, size_t segmentIndex1, double segmentFraction1);
222 
230  bool isOnSameSegment(const LinearLocation& loc) const;
231 
240  bool isEndpoint(const geom::Geometry& linearGeom) const;
241 
242  friend std::ostream& operator<< (std::ostream& out, const LinearLocation& obj);
243 
244 };
245 
246 
247 } // namespace geos.linearref
248 } // namespace geos
249 
250 #endif
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
bool isVertex() const
Tests whether this location refers to a vertex.
double getSegmentFraction() const
Gets the segment fraction for this location.
geom::Coordinate getCoordinate(const geom::Geometry *linearGeom) const
Gets the Coordinate along the given linear Geometry which is referenced by this location.
void clamp(const geom::Geometry *linear)
Ensures the indexes are valid for a given linear Geometry.
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:188
double getSegmentLength(const geom::Geometry *linearGeom) const
Gets the length of the segment in the given Geometry containing this location.
int compareLocationValues(size_t componentIndex1, size_t segmentIndex1, double segmentFraction1) const
Compares this object with the specified index values for order.
size_t getSegmentIndex() const
Gets the segment index for this location.
Represents a location along a LineString or MultiLineString.
Definition: LinearLocation.h:44
std::unique_ptr< geom::LineSegment > getSegment(const geom::Geometry *linearGeom) const
Gets a LineSegment representing the segment of the given linear Geometry which contains this location...
bool isOnSameSegment(const LinearLocation &loc) const
Tests whether two locations are on the same segment in the parent Geometry.
bool isEndpoint(const geom::Geometry &linearGeom) const
Tests whether this location is an endpoint of the linear component it refers to.
static geom::Coordinate pointAlongSegmentByFraction(const geom::Coordinate &p0, const geom::Coordinate &p1, double frac)
Computes the Coordinate of a point a given fraction along the line segment (p0, p1).
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
LinearLocation(size_t segmentIndex=0, double segmentFraction=0.0)
Creates a location referring to the start of a linear geometry.
bool isValid(const geom::Geometry *linearGeom) const
Tests whether this location refers to a valid location on the given linear Geometry.
static LinearLocation getEndLocation(const geom::Geometry *linear)
Gets a location which refers to the end of a linear Geometry.
void setToEnd(const geom::Geometry *linear)
Sets the value of this location to refer the end of a linear geometry.
void snapToVertex(const geom::Geometry *linearGeom, double minDistance)
Snaps the value of this location to the nearest vertex on the given linear Geometry, if the vertex is closer than minDistance.
int compareTo(const LinearLocation &other) const
Compares this object with the specified object for order.
size_t getComponentIndex() const
Gets the component index for this location.