GEOS  3.13.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 #pragma once
20 
21 #include <geos/export.h>
22 #include <geos/geom/Coordinate.h>
23 #include <geos/geom/Geometry.h>
24 #include <geos/linearref/LinearLocation.h>
25 #include <geos/linearref/LocationIndexOfPoint.h>
26 #include <geos/linearref/LocationIndexOfLine.h>
27 #include <geos/util/IllegalArgumentException.h>
28 
29 namespace geos {
30 namespace linearref { // geos::linearref
31 
38 class GEOS_DLL LocationIndexedLine {
39 private:
40  const geom::Geometry* linearGeom;
41 
42  void
43  checkGeometryType()
44  {
45  if(!linearGeom->isLineal()) {
46  throw util::IllegalArgumentException("Input geometry must be linear");
47  }
48  }
49 
50 public:
51 
59  LocationIndexedLine(const geom::Geometry* p_linearGeom)
60  : linearGeom(p_linearGeom)
61  {
62  checkGeometryType();
63  }
64 
79  extractPoint(const LinearLocation& index) const
80  {
81  return index.getCoordinate(linearGeom);
82  }
83 
84 
105  double offsetDistance) const
106  {
107  geom::Coordinate ret;
108  index.getSegment(linearGeom)->pointAlongOffset(
109  index.getSegmentFraction(), offsetDistance, ret
110  );
111  return ret;
112  }
113 
126  std::unique_ptr<geom::Geometry>
127  extractLine(const LinearLocation& startIndex,
128  const LinearLocation& endIndex) const
129  {
130  return ExtractLineByLocation::extract(linearGeom, startIndex, endIndex);
131  }
132 
133 
150  indexOf(const geom::Coordinate& pt) const
151  {
152  return LocationIndexOfPoint::indexOf(linearGeom, pt);
153  }
154 
181  const LinearLocation& minIndex) const
182  {
183  return LocationIndexOfPoint::indexOfAfter(linearGeom, pt, &minIndex);
184  }
185 
198  indicesOf(const geom::Geometry* subLine) const
199  {
200  return LocationIndexOfLine::indicesOf(linearGeom, subLine);
201  }
202 
203 
216  project(const geom::Coordinate& pt) const
217  {
218  return LocationIndexOfPoint::indexOf(linearGeom, pt);
219  }
220 
229  {
230  return LinearLocation();
231  }
232 
240  getEndIndex() const
241  {
242  return LinearLocation::getEndLocation(linearGeom);
243  }
244 
252  bool
253  isValidIndex(const LinearLocation& index) const
254  {
255  return index.isValid(linearGeom);
256  }
257 
258 
267  clampIndex(const LinearLocation& index) const
268  {
269  LinearLocation loc = index;
270  loc.clamp(linearGeom);
271  return loc;
272  }
273 };
274 
275 } // geos::linearref
276 } // geos
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:216
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:186
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.
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.
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.
bool isValid(const geom::Geometry *linearGeom) const
Tests whether this location refers to a valid location on the given linear Geometry.
void clamp(const geom::Geometry *linear)
Ensures the indexes are valid for a given linear Geometry.
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...
static LinearLocation * indicesOf(const geom::Geometry *linearGeom, const geom::Geometry *subLine)
Determines the location of a subline along a linear Geometry.
Supports linear referencing along a linear Geometry using LinearLocations as the index.
Definition: LocationIndexedLine.h:38
bool isValidIndex(const LinearLocation &index) const
Tests whether an index is in the valid index range for the line.
Definition: LocationIndexedLine.h:253
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:267
LinearLocation indexOf(const geom::Coordinate &pt) const
Computes the index for a given point on the line.
Definition: LocationIndexedLine.h:150
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:180
LinearLocation * indicesOf(const geom::Geometry *subLine) const
Computes the indices for a subline of the line.
Definition: LocationIndexedLine.h:198
geom::Coordinate extractPoint(const LinearLocation &index) const
Computes the Coordinate for the point on the line at the given index.
Definition: LocationIndexedLine.h:79
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:104
LinearLocation getStartIndex() const
Returns the index of the start of the line.
Definition: LocationIndexedLine.h:228
LinearLocation getEndIndex() const
Returns the index of the end of the line.
Definition: LocationIndexedLine.h:240
LinearLocation project(const geom::Coordinate &pt) const
Computes the index for the closest point on the line to the given point.
Definition: LocationIndexedLine.h:216
LocationIndexedLine(const geom::Geometry *p_linearGeom)
Constructs an object which allows linear referencing along a given linear Geometry.
Definition: LocationIndexedLine.h:59
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.
Definition: LocationIndexedLine.h:127
Indicates one or more illegal arguments.
Definition: IllegalArgumentException.h:33
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25