GEOS  3.9.1dev
LocationIndexedLine.h
Go to the documentation of this file.
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>
29 
30 namespace geos {
31 namespace linearref { // geos::linearref
32 
40 private:
42 
43  void
45  {
46  if(!linearGeom->isLineal()) {
47  throw util::IllegalArgumentException("Input geometry must be linear");
48  }
49  }
50 
51 public:
52 
60  LocationIndexedLine(const geom::Geometry* p_linearGeom)
61  : linearGeom(p_linearGeom)
62  {
63  checkGeometryType();
64  }
65 
80  extractPoint(const LinearLocation& index) const
81  {
82  return index.getCoordinate(linearGeom);
83  }
84 
85 
106  double offsetDistance) const
107  {
108  geom::Coordinate ret;
109  index.getSegment(linearGeom)->pointAlongOffset(
110  index.getSegmentFraction(), offsetDistance, ret
111  );
112  return ret;
113  }
114 
127  std::unique_ptr<geom::Geometry>
128  extractLine(const LinearLocation& startIndex,
129  const LinearLocation& endIndex) const
130  {
131  return ExtractLineByLocation::extract(linearGeom, startIndex, endIndex);
132  }
133 
134 
151  indexOf(const geom::Coordinate& pt) const
152  {
153  return LocationIndexOfPoint::indexOf(linearGeom, pt);
154  }
155 
182  const LinearLocation& minIndex) const
183  {
184  return LocationIndexOfPoint::indexOfAfter(linearGeom, pt, &minIndex);
185  }
186 
199  indicesOf(const geom::Geometry* subLine) const
200  {
201  return LocationIndexOfLine::indicesOf(linearGeom, subLine);
202  }
203 
204 
217  project(const geom::Coordinate& pt) const
218  {
219  return LocationIndexOfPoint::indexOf(linearGeom, pt);
220  }
221 
230  {
231  return LinearLocation();
232  }
233 
241  getEndIndex() const
242  {
243  return LinearLocation::getEndLocation(linearGeom);
244  }
245 
253  bool
254  isValidIndex(const LinearLocation& index) const
255  {
256  return index.isValid(linearGeom);
257  }
258 
259 
268  clampIndex(const LinearLocation& index) const
269  {
270  LinearLocation loc = index;
271  loc.clamp(linearGeom);
272  return loc;
273  }
274 };
275 
276 } // geos::linearref
277 } // geos
278 #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.
#define GEOS_DLL
Definition: export.h:28
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.
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
LinearLocation getStartIndex() const
Returns the index of the start of the line.
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.
static std::unique_ptr< geom::Geometry > extract(const geom::Geometry *line, const LinearLocation &start, const LinearLocation &end)
Computes the subline of a LineString between two LinearLocations on the line.
LinearLocation * indicesOf(const geom::Geometry *subLine) const
Computes the indices for a subline of the line.
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
Indicates one or more illegal arguments.
bool isLineal() const
Definition: Geometry.h:356
static LinearLocation indexOf(const geom::Geometry *linearGeom, const geom::Coordinate &inputPt)
Represents a location along a LineString or MultiLineString.
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 isValidIndex(const LinearLocation &index) const
Tests whether an index is in the valid index range for the line.
static LinearLocation indexOfAfter(const geom::Geometry *linearGeom, const geom::Coordinate &inputPt, const LinearLocation *minIndex)
std::unique_ptr< geom::Geometry > extractLine(const LinearLocation &startIndex, const LinearLocation &endIndex) const
Computes the LineString for the interval on the line between the given indices.
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...
geom::Coordinate extractPoint(const LinearLocation &index) const
Computes the Coordinate for the point on the line at the given index.
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...
Basic namespace for all GEOS functionalities.
LocationIndexedLine(const geom::Geometry *p_linearGeom)
Constructs an object which allows linear referencing along a given 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.
LinearLocation getEndIndex() const
Returns the index of the end of the line.
LinearLocation project(const geom::Coordinate &pt) const
Computes the index for the closest point on the line to the given point.
Supports linear referencing along a linear Geometry using LinearLocations as the index.