[geos-devel] Minimun distance between two polygons

alb.sil.81 at virgilio.it alb.sil.81 at virgilio.it
Fri Jan 20 02:28:51 PST 2017



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).

 

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. 

 

This
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)

 

….

 

/**

  *
GEOSCoordSequence::nearestPoints(GEOSGeometry)

  */

PHP_METHOD(Geometry, nearestPoints)

{

     GEOSGeometry *this;

     GEOSGeometry *other;

     zval *zobj;

     GEOSCoordSequence
*ret;

 

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

 

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

        
&zobj) == FAILURE)

     {

        
RETURN_NULL();

     }

 

     other = getRelay(zobj,
Geometry_ce_ptr);

 

     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);

     setRelay(return_value,
ret);

}

 

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.

 

 AS


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


More information about the geos-devel mailing list