GEOS  3.8.0dev
LocationIndexedLine.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  *
8  * This is free software; you can redistribute and/or modify it under
9  * the terms of the GNU Lesser General Public Licence as published
10  * by the Free Software Foundation.
11  * See the COPYING file for more information.
12  *
13  **********************************************************************
14  *
15  * Last port: linearref/LocationIndexedLine.java r466
16  *
17  **********************************************************************/
18 
19 #ifndef GEOS_LINEARREF_LOCATIONINDEXEDLINE_H
20 #define GEOS_LINEARREF_LOCATIONINDEXEDLINE_H
21 
22 #include <geos/export.h>
23 #include <geos/geom/Coordinate.h>
24 #include <geos/geom/Geometry.h>
25 #include <geos/geom/Lineal.h>
26 #include <geos/linearref/LinearLocation.h>
27 #include <geos/linearref/LocationIndexOfPoint.h>
28 #include <geos/linearref/LocationIndexOfLine.h>
29 #include <geos/util/IllegalArgumentException.h>
30 
31 namespace geos {
32 namespace linearref { // geos::linearref
33 
40 class GEOS_DLL LocationIndexedLine {
41 private:
42  const geom::Geometry* linearGeom;
43 
44  void
45  checkGeometryType()
46  {
47  if(! dynamic_cast<const geom::Lineal*>(linearGeom)) {
48  throw util::IllegalArgumentException("Input geometry must be linear");
49  }
50  }
51 
52 public:
53 
61  LocationIndexedLine(const geom::Geometry* p_linearGeom)
62  : linearGeom(p_linearGeom)
63  {
64  checkGeometryType();
65  }
66 
81  extractPoint(const LinearLocation& index) const
82  {
83  return index.getCoordinate(linearGeom);
84  }
85 
86 
107  double offsetDistance) const
108  {
109  geom::Coordinate ret;
110  index.getSegment(linearGeom)->pointAlongOffset(
111  index.getSegmentFraction(), offsetDistance, ret
112  );
113  return ret;
114  }
115 
129  extractLine(const LinearLocation& startIndex,
130  const LinearLocation& endIndex) const
131  {
132  return ExtractLineByLocation::extract(linearGeom, startIndex, endIndex);
133  }
134 
135 
152  indexOf(const geom::Coordinate& pt) const
153  {
154  return LocationIndexOfPoint::indexOf(linearGeom, pt);
155  }
156 
183  const LinearLocation& minIndex) const
184  {
185  return LocationIndexOfPoint::indexOfAfter(linearGeom, pt, &minIndex);
186  }
187 
200  indicesOf(const geom::Geometry* subLine) const
201  {
202  return LocationIndexOfLine::indicesOf(linearGeom, subLine);
203  }
204 
205 
218  project(const geom::Coordinate& pt) const
219  {
220  return LocationIndexOfPoint::indexOf(linearGeom, pt);
221  }
222 
231  {
232  return LinearLocation();
233  }
234 
242  getEndIndex() const
243  {
244  return LinearLocation::getEndLocation(linearGeom);
245  }
246 
254  bool
255  isValidIndex(const LinearLocation& index) const
256  {
257  return index.isValid(linearGeom);
258  }
259 
260 
269  clampIndex(const LinearLocation& index) const
270  {
271  LinearLocation loc = index;
272  loc.clamp(linearGeom);
273  return loc;
274  }
275 };
276 
277 } // geos::linearref
278 } // geos
279 #endif
static LinearLocation * indicesOf(const geom::Geometry *linearGeom, const geom::Geometry *subLine)
Determines the location of a subline along a linear Geometry.
LinearLocation indexOf(const geom::Coordinate &pt) const
Computes the index for a given point on the line.
Definition: LocationIndexedLine.h:152
LinearLocation indexOfAfter(const geom::Coordinate &pt, const LinearLocation &minIndex) const
Finds the index for a point on the line which is greater than the given index.
Definition: LocationIndexedLine.h:182
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
static geom::Geometry * extract(const geom::Geometry *line, const LinearLocation &start, const LinearLocation &end)
LinearLocation getStartIndex() const
Returns the index of the start of the line.
Definition: LocationIndexedLine.h:230
double getSegmentFraction() const
geom::Coordinate getCoordinate(const geom::Geometry *linearGeom) const
LinearLocation * indicesOf(const geom::Geometry *subLine) const
Computes the indices for a subline of the line.
Definition: LocationIndexedLine.h:200
void clamp(const geom::Geometry *linear)
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:187
Indicates one or more illegal arguments.
Definition: IllegalArgumentException.h:34
Represents a location along a LineString or MultiLineString.
Definition: LinearLocation.h:43
std::unique_ptr< geom::LineSegment > getSegment(const geom::Geometry *linearGeom) const
bool isValidIndex(const LinearLocation &index) const
Tests whether an index is in the valid index range for the line.
Definition: LocationIndexedLine.h:255
geom::Geometry * extractLine(const LinearLocation &startIndex, const LinearLocation &endIndex) const
Computes the LineString for the interval on the line between the given indices.
Definition: LocationIndexedLine.h:129
geom::Coordinate extractPoint(const LinearLocation &index, double offsetDistance) const
Computes the Coordinate for the point on the line at the given index, offset by the given distance...
Definition: LocationIndexedLine.h:106
geom::Coordinate extractPoint(const LinearLocation &index) const
Computes the Coordinate for the point on the line at the given index.
Definition: LocationIndexedLine.h:81
LinearLocation clampIndex(const LinearLocation &index) const
Computes a valid index for this line by clamping the given index to the valid range of index values...
Definition: LocationIndexedLine.h:269
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
LocationIndexedLine(const geom::Geometry *p_linearGeom)
Constructs an object which allows linear referencing along a given linear Geometry.
Definition: LocationIndexedLine.h:61
bool isValid(const geom::Geometry *linearGeom) const
static LinearLocation getEndLocation(const geom::Geometry *linear)
LinearLocation getEndIndex() const
Returns the index of the end of the line.
Definition: LocationIndexedLine.h:242
LinearLocation project(const geom::Coordinate &pt) const
Computes the index for the closest point on the line to the given point.
Definition: LocationIndexedLine.h:218
Supports linear referencing along a linear Geometry using LinearLocations as the index.
Definition: LocationIndexedLine.h:40