[geos-devel] R: Re: Minimun distance between two polygons

alb.sil.81 at virgilio.it alb.sil.81 at virgilio.it
Thu Jan 26 04:01:35 PST 2017

Hi Paul,
in general speaking you are right. In my case the distances between the polygons are very low, under 2km and the difference between the measure of the lines and the arcs, I suppose, are negligible.
By the way, to follow your suggestion I looked for some tool but I was not able to find them :-/. Can you suggest me a smart way to project the objects in a planar space? 

----Messaggio originale----

Da: "Paul Ramsey" <pramsey at cleverelephant.ca>

Data: 20-gen-2017 13.57

A: "alb.sil.81 at virgilio.it"<alb.sil.81 at virgilio.it>, "GEOS Development List"<geos-devel at lists.osgeo.org>

Ogg: Re: [geos-devel] Minimun distance between two polygons

On Fri, Jan 20, 2017 at 2:28 AM, alb.sil.81 at virgilio.it <alb.sil.81 at virgilio.it> wrote:

Hi everybody,


using GEOS
3.5.0 and PHP my aim is to measure the minimum distance in meters between two polygons
in Google Maps coordinate (Latitude/Longitude WGS84).
Since your inputs are in lon/lat, you're fundamentally out of luck, even if you solve your problem below. The nearest points in lon/lat space are not the actual nearest points, because the lines in lon/lat space are not the same as the great circles that connect points in spherical space. You really need to either project your objects into a planar space first, then use GEOS, or move to some completely different tool set, like a port of s2 (spherical geometry) algorithms into php https://github.com/eelf/s2-geometry-library-php 


Using the “Distance
method” I obtain an angle you can’t convert in meter (with an acceptable error)
without the information about the orientation and the longitude of the two
point (1 grad on latitude is in meter different from 1 grad in longitude).


I find the “nearestPoints
method” that return the nearest Points of two polygons, with this information I
will create a function able to calculate the right distance. 


function isn’t usable from PHP.


In order to
use that method from PHP I tried to modify the php/geos.c file adding the
following code:



PHP_METHOD(Geometry, nearestPoints);




PHP_ME(Geometry, nearestPoints, NULL, 0)







PHP_METHOD(Geometry, nearestPoints)


     GEOSGeometry *this;

     GEOSGeometry *other;

     zval *zobj;



     this =
(GEOSGeometry*)getRelay(getThis(), Geometry_ce_ptr);


(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o",

&zobj) == FAILURE)





     other = getRelay(zobj,


     ret =
GEOSNearestPoints(this, other);

     if ( ! ret )
RETURN_NULL(); /* should get an exception first */


     /* return_value is a
zval */

object_init_ex(return_value, Geometry_ce_ptr);




The result
obtained using this function with PHP is always an empty GEOSGeometry object.


I would like
to ask you:


1)      Is possible to obtain the distance in
meter using the distance method?

2)      Where is the error in the code
above? Some of you find errors in the code above?

3)      Could you suggest me another way to
obtain the minimum distance between two polygon using GEOS :-D ?


Thank you
very much for your help.




geos-devel mailing list

geos-devel at lists.osgeo.org


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/geos-devel/attachments/20170126/e5f6bb96/attachment.html>

More information about the geos-devel mailing list