GEOS 3.14.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
88
92 LinearLocation(std::size_t segmentIndex = 0, double segmentFraction = 0.0);
93
94 LinearLocation(std::size_t componentIndex, std::size_t segmentIndex, double segmentFraction);
95
101 void clamp(const geom::Geometry* linear);
102
110 void snapToVertex(const geom::Geometry* linearGeom, double minDistance);
111
119 double getSegmentLength(const geom::Geometry* linearGeom) const;
120
127 void setToEnd(const geom::Geometry* linear);
128
134 std::size_t getComponentIndex() const;
135
141 std::size_t getSegmentIndex() const;
142
148 double getSegmentFraction() const;
149
155 bool isVertex() const;
156
165
173 std::unique_ptr<geom::LineSegment> getSegment(const geom::Geometry* linearGeom) const;
174
182 bool isValid(const geom::Geometry* linearGeom) const;
183
192 int compareTo(const LinearLocation& other) const;
193
203 int compareLocationValues(std::size_t componentIndex1, std::size_t segmentIndex1, double segmentFraction1) const;
204
219 std::size_t componentIndex0, std::size_t segmentIndex0, double segmentFraction0,
220 std::size_t componentIndex1, std::size_t segmentIndex1, double segmentFraction1);
221
229 bool isOnSameSegment(const LinearLocation& loc) const;
230
239 bool isEndpoint(const geom::Geometry& linearGeom) const;
240
241 friend std::ostream& operator<< (std::ostream& out, const LinearLocation& obj);
242
243};
244
245
246} // namespace geos.linearref
247} // namespace geos
248
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:217
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:197
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...
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.
geom::Coordinate getCoordinate(const geom::Geometry *linearGeom) const
Gets the Coordinate along the given linear Geometry which is referenced by this location.
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:39