LocationIndexedLine.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2011 Sandro Santilli <strk@kbt.io>
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************
*
* Last port: linearref/LocationIndexedLine.java r466
*
**********************************************************************/
#pragma once
#include <geos/export.h>
#include <geos/geom/Coordinate.h>
#include <geos/geom/Geometry.h>
#include <geos/linearref/ExtractLineByLocation.h>
#include <geos/linearref/LinearLocation.h>
#include <geos/linearref/LocationIndexOfPoint.h>
#include <geos/linearref/LocationIndexOfLine.h>
#include <geos/util/IllegalArgumentException.h>
namespace geos {
namespace linearref { // geos::linearref
class GEOS_DLL LocationIndexedLine {
private:
const geom::Geometry* linearGeom;
void
checkGeometryType()
{
if(!linearGeom->isLineal()) {
throw util::IllegalArgumentException("Input geometry must be linear");
}
}
public:
LocationIndexedLine(const geom::Geometry* p_linearGeom)
: linearGeom(p_linearGeom)
{
checkGeometryType();
}
geom::Coordinate
extractPoint(const LinearLocation& index) const
{
return index.getCoordinate(linearGeom);
}
geom::Coordinate
extractPoint(const LinearLocation& index,
double offsetDistance) const
{
geom::Coordinate ret;
index.getSegment(linearGeom)->pointAlongOffset(
index.getSegmentFraction(), offsetDistance, ret
);
return ret;
}
std::unique_ptr<geom::Geometry>
extractLine(const LinearLocation& startIndex,
const LinearLocation& endIndex) const
{
return ExtractLineByLocation::extract(linearGeom, startIndex, endIndex);
}
LinearLocation
indexOf(const geom::Coordinate& pt) const
{
return LocationIndexOfPoint::indexOf(linearGeom, pt);
}
LinearLocation
indexOfAfter(const geom::Coordinate& pt,
const LinearLocation& minIndex) const
{
return LocationIndexOfPoint::indexOfAfter(linearGeom, pt, &minIndex);
}
LinearLocation*
indicesOf(const geom::Geometry* subLine) const
{
return LocationIndexOfLine::indicesOf(linearGeom, subLine);
}
LinearLocation
project(const geom::Coordinate& pt) const
{
return LocationIndexOfPoint::indexOf(linearGeom, pt);
}
LinearLocation
getStartIndex() const
{
return LinearLocation();
}
LinearLocation
getEndIndex() const
{
return LinearLocation::getEndLocation(linearGeom);
}
bool
isValidIndex(const LinearLocation& index) const
{
return index.isValid(linearGeom);
}
LinearLocation
clampIndex(const LinearLocation& index) const
{
LinearLocation loc = index;
loc.clamp(linearGeom);
return loc;
}
};
} // geos::linearref
} // geos
geos::geom::Coordinate
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:217
geos::geom::Geometry
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:196
geos::linearref::ExtractLineByLocation::extract
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.
geos::linearref::LinearLocation
Represents a location along a LineString or MultiLineString.
Definition LinearLocation.h:43
geos::linearref::LinearLocation::getEndLocation
static LinearLocation getEndLocation(const geom::Geometry *linear)
Gets a location which refers to the end of a linear Geometry.
geos::linearref::LinearLocation::clamp
void clamp(const geom::Geometry *linear)
Ensures the indexes are valid for a given linear Geometry.
geos::linearref::LocationIndexOfLine::indicesOf
static LinearLocation * indicesOf(const geom::Geometry *linearGeom, const geom::Geometry *subLine)
Determines the location of a subline along a linear Geometry.
geos::linearref::LocationIndexedLine::isValidIndex
bool isValidIndex(const LinearLocation &index) const
Tests whether an index is in the valid index range for the line.
Definition LocationIndexedLine.h:254
geos::linearref::LocationIndexedLine::clampIndex
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:268
geos::linearref::LocationIndexedLine::indexOf
LinearLocation indexOf(const geom::Coordinate &pt) const
Computes the index for a given point on the line.
Definition LocationIndexedLine.h:151
geos::linearref::LocationIndexedLine::indexOfAfter
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:181
geos::linearref::LocationIndexedLine::extractPoint
geom::Coordinate extractPoint(const LinearLocation &index) const
Computes the Coordinate for the point on the line at the given index.
Definition LocationIndexedLine.h:80
geos::linearref::LocationIndexedLine::extractPoint
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:105
geos::linearref::LocationIndexedLine::extractLine
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:128
geos::linearref::LocationIndexedLine::getStartIndex
LinearLocation getStartIndex() const
Returns the index of the start of the line.
Definition LocationIndexedLine.h:229
geos::linearref::LocationIndexedLine::getEndIndex
LinearLocation getEndIndex() const
Returns the index of the end of the line.
Definition LocationIndexedLine.h:241
geos::linearref::LocationIndexedLine::indicesOf
LinearLocation * indicesOf(const geom::Geometry *subLine) const
Computes the indices for a subline of the line.
Definition LocationIndexedLine.h:199
geos::linearref::LocationIndexedLine::project
LinearLocation project(const geom::Coordinate &pt) const
Computes the index for the closest point on the line to the given point.
Definition LocationIndexedLine.h:217
geos::linearref::LocationIndexedLine::LocationIndexedLine
LocationIndexedLine(const geom::Geometry *p_linearGeom)
Constructs an object which allows linear referencing along a given linear Geometry.
Definition LocationIndexedLine.h:60
geos::util::IllegalArgumentException
Indicates one or more illegal arguments.
Definition IllegalArgumentException.h:33
geos::index
Provides classes for various kinds of spatial indexes.
Definition CleanCoverage.h:39
geos::linearref
Contains classes and interfaces implementing linear referencing on linear geometries.
Definition ExtractLineByLocation.h:27
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38