GEOS  3.9.1dev
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
geos::operation::distance::DistanceOp Class Reference

Find two points on two geom::Geometrys which lie within a given distance, or else are the nearest points on the geometries (in which case this also provides the distance between the geometries). More...

#include <DistanceOp.h>

Collaboration diagram for geos::operation::distance::DistanceOp:
[legend]

Public Member Functions

 DistanceOp (const geom::Geometry *g0, const geom::Geometry *g1)
 
 DistanceOp (const geom::Geometry &g0, const geom::Geometry &g1)
 Constructs a DistanceOp that computes the distance and nearest points between the two specified geometries. More...
 
 DistanceOp (const geom::Geometry &g0, const geom::Geometry &g1, double terminateDistance)
 Constructs a DistanceOp that computes the distance and nearest points between the two specified geometries. More...
 
 ~DistanceOp ()=default
 
double distance ()
 
std::unique_ptr< geom::CoordinateSequencenearestPoints ()
 

Static Public Member Functions

static double distance (const geom::Geometry &g0, const geom::Geometry &g1)
 Compute the distance between the nearest points of two geometries. More...
 
static double distance (const geom::Geometry *g0, const geom::Geometry *g1)
 
static bool isWithinDistance (const geom::Geometry &g0, const geom::Geometry &g1, double distance)
 Test whether two geometries lie within a given distance of each other. More...
 
static std::unique_ptr< geom::CoordinateSequencenearestPoints (const geom::Geometry *g0, const geom::Geometry *g1)
 

Private Member Functions

void updateMinDistance (std::array< std::unique_ptr< GeometryLocation >, 2 > &locGeom, bool flip)
 
void computeMinDistance ()
 
void computeContainmentDistance ()
 
void computeInside (std::vector< std::unique_ptr< GeometryLocation >> &locs, const std::vector< const geom::Polygon * > &polys, std::array< std::unique_ptr< GeometryLocation >, 2 > &locPtPoly)
 
void computeFacetDistance ()
 
void computeMinDistanceLines (const std::vector< const geom::LineString * > &lines0, const std::vector< const geom::LineString * > &lines1, std::array< std::unique_ptr< GeometryLocation >, 2 > &locGeom)
 
void computeMinDistancePoints (const std::vector< const geom::Point * > &points0, const std::vector< const geom::Point * > &points1, std::array< std::unique_ptr< GeometryLocation >, 2 > &locGeom)
 
void computeMinDistanceLinesPoints (const std::vector< const geom::LineString * > &lines0, const std::vector< const geom::Point * > &points1, std::array< std::unique_ptr< GeometryLocation >, 2 > &locGeom)
 
void computeMinDistance (const geom::LineString *line0, const geom::LineString *line1, std::array< std::unique_ptr< GeometryLocation >, 2 > &locGeom)
 
void computeMinDistance (const geom::LineString *line, const geom::Point *pt, std::array< std::unique_ptr< GeometryLocation >, 2 > &locGeom)
 

Private Attributes

std::array< geom::Geometry const *, 2 > geom
 
double terminateDistance
 
algorithm::PointLocator ptLocator
 
std::array< std::unique_ptr< GeometryLocation >, 2 > minDistanceLocation
 
double minDistance
 
bool computed = false
 

Detailed Description

Find two points on two geom::Geometrys which lie within a given distance, or else are the nearest points on the geometries (in which case this also provides the distance between the geometries).

The distance computation also finds a pair of points in the input geometries which have the minimum distance between them. If a point lies in the interior of a line segment, the coordinate computed is a close approximation to the exact point.

Empty geometry collection components are ignored.

The algorithms used are straightforward O(n^2) comparisons. This worst-case performance could be improved on by using Voronoi techniques or spatial indexes.

Definition at line 74 of file DistanceOp.h.

Constructor & Destructor Documentation

geos::operation::distance::DistanceOp::DistanceOp ( const geom::Geometry g0,
const geom::Geometry g1 
)
Deprecated:
use the one taking references
geos::operation::distance::DistanceOp::DistanceOp ( const geom::Geometry g0,
const geom::Geometry g1 
)

Constructs a DistanceOp that computes the distance and nearest points between the two specified geometries.

Parameters
g0a Geometry
g1a Geometry
geos::operation::distance::DistanceOp::DistanceOp ( const geom::Geometry g0,
const geom::Geometry g1,
double  terminateDistance 
)

Constructs a DistanceOp that computes the distance and nearest points between the two specified geometries.

Parameters
g0a Geometry
g1a Geometry
terminateDistancethe distance on which to terminate the search
geos::operation::distance::DistanceOp::~DistanceOp ( )
default

Member Function Documentation

void geos::operation::distance::DistanceOp::computeContainmentDistance ( )
private
void geos::operation::distance::DistanceOp::computeFacetDistance ( )
private

Computes distance between facets (lines and points) of input geometries.

void geos::operation::distance::DistanceOp::computeInside ( std::vector< std::unique_ptr< GeometryLocation >> &  locs,
const std::vector< const geom::Polygon * > &  polys,
std::array< std::unique_ptr< GeometryLocation >, 2 > &  locPtPoly 
)
private
void geos::operation::distance::DistanceOp::computeMinDistance ( )
private
void geos::operation::distance::DistanceOp::computeMinDistance ( const geom::LineString line0,
const geom::LineString line1,
std::array< std::unique_ptr< GeometryLocation >, 2 > &  locGeom 
)
private
void geos::operation::distance::DistanceOp::computeMinDistance ( const geom::LineString line,
const geom::Point pt,
std::array< std::unique_ptr< GeometryLocation >, 2 > &  locGeom 
)
private
void geos::operation::distance::DistanceOp::computeMinDistanceLines ( const std::vector< const geom::LineString * > &  lines0,
const std::vector< const geom::LineString * > &  lines1,
std::array< std::unique_ptr< GeometryLocation >, 2 > &  locGeom 
)
private
void geos::operation::distance::DistanceOp::computeMinDistanceLinesPoints ( const std::vector< const geom::LineString * > &  lines0,
const std::vector< const geom::Point * > &  points1,
std::array< std::unique_ptr< GeometryLocation >, 2 > &  locGeom 
)
private
void geos::operation::distance::DistanceOp::computeMinDistancePoints ( const std::vector< const geom::Point * > &  points0,
const std::vector< const geom::Point * > &  points1,
std::array< std::unique_ptr< GeometryLocation >, 2 > &  locGeom 
)
private
static double geos::operation::distance::DistanceOp::distance ( const geom::Geometry g0,
const geom::Geometry g1 
)
static

Compute the distance between the nearest points of two geometries.

Parameters
g0a geom::Geometry
g1another geom::Geometry
Returns
the distance between the geometries
0 if either input geometry is empty
Exceptions
IllegalArgumentExceptionif either input geometry is null
static double geos::operation::distance::DistanceOp::distance ( const geom::Geometry g0,
const geom::Geometry g1 
)
static
Deprecated:
, use the version taking references
double geos::operation::distance::DistanceOp::distance ( )

Report the distance between the closest points on the input geometries.

Returns
the distance between the geometries
static bool geos::operation::distance::DistanceOp::isWithinDistance ( const geom::Geometry g0,
const geom::Geometry g1,
double  distance 
)
static

Test whether two geometries lie within a given distance of each other.

Parameters
g0a geom::Geometry
g1another geom::Geometry
distancethe distance to test
Returns
true if g0.distance(g1) <= distance
static std::unique_ptr<geom::CoordinateSequence> geos::operation::distance::DistanceOp::nearestPoints ( const geom::Geometry g0,
const geom::Geometry g1 
)
static

Compute the the nearest points of two geometries.

The points are presented in the same order as the input Geometries.

Parameters
g0a geom::Geometry
g1another geom::Geometry
Returns
the nearest points in the geometries, ownership to caller. A NULL return means one of the geometries is empty.
std::unique_ptr<geom::CoordinateSequence> geos::operation::distance::DistanceOp::nearestPoints ( )

Report the coordinates of the nearest points in the input geometries. The points are presented in the same order as the input Geometries.

Returns
a pair of geom::Coordinates of the nearest points as a newly allocated object (ownership to caller)
void geos::operation::distance::DistanceOp::updateMinDistance ( std::array< std::unique_ptr< GeometryLocation >, 2 > &  locGeom,
bool  flip 
)
private

Member Data Documentation

bool geos::operation::distance::DistanceOp::computed = false
private

Definition at line 178 of file DistanceOp.h.

std::array<geom::Geometry const*, 2> geos::operation::distance::DistanceOp::geom
private

Definition at line 171 of file DistanceOp.h.

double geos::operation::distance::DistanceOp::minDistance
private

Definition at line 177 of file DistanceOp.h.

std::array<std::unique_ptr<GeometryLocation>, 2> geos::operation::distance::DistanceOp::minDistanceLocation
private

Definition at line 176 of file DistanceOp.h.

algorithm::PointLocator geos::operation::distance::DistanceOp::ptLocator
private

Definition at line 175 of file DistanceOp.h.

double geos::operation::distance::DistanceOp::terminateDistance
private

Definition at line 172 of file DistanceOp.h.


The documentation for this class was generated from the following file: