GEOS 3.15.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#pragma once
22
23#include <string>
24#include <memory> // for std::unique_ptr
25
26#include <geos/geom/Coordinate.h>
27#include <geos/geom/Geometry.h>
28#include <geos/geom/LineSegment.h>
29
30namespace geos {
31namespace linearref { // geos::linearref
32
33
44private:
45 std::size_t componentIndex;
46 std::size_t segmentIndex;
47 double segmentFraction;
48
57 void normalize();
58
59public:
68
86 double frac);
87 static geom::CoordinateXYZM pointAlongSegmentByFraction(const geom::CoordinateXYZM& p0, const geom::CoordinateXYZM& p1,
88 double frac);
89
90
94 LinearLocation(std::size_t segmentIndex = 0, double segmentFraction = 0.0);
95
96 LinearLocation(std::size_t componentIndex, std::size_t segmentIndex, double segmentFraction);
97
103 void clamp(const geom::Geometry* linear);
104
112 void snapToVertex(const geom::Geometry* linearGeom, double minDistance);
113
121 double getSegmentLength(const geom::Geometry* linearGeom) const;
122
129 void setToEnd(const geom::Geometry* linear);
130
136 std::size_t getComponentIndex() const;
137
143 std::size_t getSegmentIndex() const;
144
150 double getSegmentFraction() const;
151
157 bool isVertex() const;
158
166 geom::CoordinateXYZM getCoordinate(const geom::Geometry* linearGeom) const;
167
175 std::unique_ptr<geom::LineSegment> getSegment(const geom::Geometry* linearGeom) const;
176
184 bool isValid(const geom::Geometry* linearGeom) const;
185
194 int compareTo(const LinearLocation& other) const;
195
205 int compareLocationValues(std::size_t componentIndex1, std::size_t segmentIndex1, double segmentFraction1) const;
206
221 std::size_t componentIndex0, std::size_t segmentIndex0, double segmentFraction0,
222 std::size_t componentIndex1, std::size_t segmentIndex1, double segmentFraction1);
223
231 bool isOnSameSegment(const LinearLocation& loc) const;
232
241 bool isEndpoint(const geom::Geometry& linearGeom) const;
242
243 friend std::ostream& operator<< (std::ostream& out, const LinearLocation& obj);
244
245};
246
247
248} // namespace geos.linearref
249} // namespace geos
250
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:220
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:196
Represents a location along a LineString or MultiLineString.
Definition LinearLocation.h:43
static LinearLocation getEndLocation(const geom::Geometry *linear)
Gets a location which refers to the end of a linear Geometry.
static int compareLocationValues(std::size_t componentIndex0, std::size_t segmentIndex0, double segmentFraction0, std::size_t componentIndex1, std::size_t segmentIndex1, double segmentFraction1)
Compares two sets of location values for order.
int compareTo(const LinearLocation &other) const
Compares this object with the specified object for order.
bool isEndpoint(const geom::Geometry &linearGeom) const
Tests whether this location is an endpoint of the linear component it refers to.
LinearLocation(std::size_t segmentIndex=0, double segmentFraction=0.0)
Creates a location referring to the start of a linear geometry.
bool isOnSameSegment(const LinearLocation &loc) const
Tests whether two locations are on the same segment in the parent Geometry.
double getSegmentLength(const geom::Geometry *linearGeom) const
Gets the length of the segment in the given Geometry containing this location.
bool isVertex() const
Tests whether this location refers to a vertex.
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...
geom::CoordinateXYZM getCoordinate(const geom::Geometry *linearGeom) const
Gets the Coordinate along the given linear Geometry which is referenced by this location.
std::size_t getSegmentIndex() const
Gets the segment index for this location.
void setToEnd(const geom::Geometry *linear)
Sets the value of this location to refer the end of a linear geometry.
double getSegmentFraction() const
Gets the segment fraction for this location.
int compareLocationValues(std::size_t componentIndex1, std::size_t segmentIndex1, double segmentFraction1) const
Compares this object with the specified index values for order.
bool isValid(const geom::Geometry *linearGeom) const
Tests whether this location refers to a valid location on the given 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,...
void clamp(const geom::Geometry *linear)
Ensures the indexes are valid for a given linear Geometry.
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).
std::size_t getComponentIndex() const
Gets the component index for this location.
Basic namespace for all GEOS functionalities.
Definition geos.h:38