[geos-devel] Minimun distance between two polygons
Paul Ramsey
pramsey at cleverelephant.ca
Fri Jan 20 05:57:21 PST 2017
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.
>
>
>
> 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
>
>
> _______________________________________________
> geos-devel mailing list
> geos-devel at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/geos-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/geos-devel/attachments/20170120/9be62739/attachment-0001.html>
More information about the geos-devel
mailing list