Shortest Line Between Two Polygons

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Shortest Line Between Two Polygons

Curtis Jones
I just started using GEOS (C API) yesterday, so I'm probably missing the obvious answer. Given two polygons, I'd like to get a line that connects the two closest points of those polygons; or, more specifically, the point on polygon 2 that is closest to polygon 1.

While trying to find the best way to do this I found that PostGIS has an ST_ShortestLine(<geom1>, <geom2>) function, so I dug into its implementation. It's not a trivial amount of code.

Is there a GEOS-provided method of accomplishing this?

Any help would be appreciated. Thanks.

--
Curtis Jones
[hidden email]

_______________________________________________
geos-devel mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/geos-devel
Reply | Threaded
Open this post in threaded view
|

Re: Shortest Line Between Two Polygons

Chris Hodgson
Alternatively you could look at the distance function in GEOS or Postgis
- it's probably a similarly large amount of code - but it must find the
closest points on the two inputs in order to calculate the distance, all
you need to do is grab those points and put them together as a line.

Chris

On 12-04-19 02:27 PM, Curtis Jones wrote:

> I just started using GEOS (C API) yesterday, so I'm probably missing the obvious answer. Given two polygons, I'd like to get a line that connects the two closest points of those polygons; or, more specifically, the point on polygon 2 that is closest to polygon 1.
>
> While trying to find the best way to do this I found that PostGIS has an ST_ShortestLine(<geom1>,<geom2>) function, so I dug into its implementation. It's not a trivial amount of code.
>
> Is there a GEOS-provided method of accomplishing this?
>
> Any help would be appreciated. Thanks.
>
> --
> Curtis Jones
> [hidden email]
>
> _______________________________________________
> geos-devel mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/geos-devel

_______________________________________________
geos-devel mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/geos-devel