Piotrek Hryciuk
Piotrek Hryciuk

Reputation: 805

How is distance between two LineStrings calculated?

I am working on my university project, and I use GeoTools library. My task is to implement AGNES (agglomerative nesting) algorithm that considers spatial data. To do this I need to calculate distances between spatial objects e.g. points, curves, polygons.

LineString which can be converted to Curve is a GeoTools class that inherits Geometry methods including distance(). My question is how is the distance between two LineString objects calculated? Is it the shortest line segment connecting both curves? Also, I am curious how similar is done with polygons.

Upvotes: 0

Views: 2509

Answers (1)

eguaio
eguaio

Reputation: 3954

An algorithm with an explanation can be found in the answer of this question find-shortest-path-from-one-geometry-to-other-on-shapely. The distance is not necessarily achieved in two vertex.

The algorithm basically computes the distance between each pair of edges, including the case where the distance is achieved in the interior of the edge (by projecting vertex points of one edge to the other edge).

The code is in python, but the geometric library it uses is shapely, that is based on GEOS library, which in turn is a ported version of JTS.

Upvotes: 0

Related Questions