<div>Hi Paul,</div><div><br></div><div>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.</div><div><br></div><div>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? </div><div><br></div><div>Thanks,</div><div><br></div><div>AS</div><br>
<br>
<blockquote>
----Messaggio originale----<br>
Da: "Paul Ramsey" <pramsey@cleverelephant.ca><br>
Data: 20-gen-2017 13.57<br>
A: "alb.sil.81@virgilio.it"<alb.sil.81@virgilio.it>, "GEOS Development List"<geos-devel@lists.osgeo.org><br>
Ogg: Re: [geos-devel] Minimun distance between two polygons<br>
<br>
<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 20, 2017 at 2:28 AM, <a href="mailto:alb.sil.81@virgilio.it">alb.sil.81@virgilio.it</a> <span dir="ltr"><<a href="mailto:alb.sil.81@virgilio.it" target="_blank">alb.sil.81@virgilio.it</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div></div>
<p style="margin:0px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3">Hi everybody,</font></span></p>
<p style="margin:0px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> </font></span></p>
<p style="margin:0px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3">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).</font></span></p></blockquote><div><br></div><div>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 <a href="https://github.com/eelf/s2-geometry-library-php">https://github.com/eelf/s2-geometry-library-php</a></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<p style="margin:0px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> </font></span></p>
<p style="margin:0px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3">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).</font></span></p>
<p style="margin:0px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> </font></span></p>
<p style="margin:0px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3">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. </font></span></p>
<p style="margin:0px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> </font></span></p>
<p style="margin:0px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3">This
function isn’t usable from PHP.</font></span></p>
<p style="margin:0px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> </font></span></p>
<p style="margin:0px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3">In order to
use that method from PHP I tried to modify the php/geos.c file adding the
following code:</font></span></p>
<p style="margin:0px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> </font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3">….</font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3">PHP_METHOD(Geometry, nearestPoints);</font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> </font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3">….</font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> </font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3">PHP_ME(Geometry, nearestPoints, NULL, 0)</font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> </font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3">….</font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> </font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3">/**</font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> *
GEOSCoordSequence::<wbr>nearestPoints(GEOSGeometry)</font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> */</font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3">PHP_METHOD(Geometry, nearestPoints)</font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3">{</font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> GEOSGeometry *this;</font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> GEOSGeometry *other;</font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> zval *zobj;</font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> GEOSCoordSequence
*ret;</font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> </font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> this =
(GEOSGeometry*)getRelay(<wbr>getThis(), Geometry_ce_ptr);</font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> </font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> if
(zend_parse_parameters(ZEND_<wbr>NUM_ARGS() TSRMLS_CC, "o",</font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3">
&zobj) == FAILURE)</font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> {</font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3">
RETURN_NULL();</font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> }</font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> </font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> other = getRelay(zobj,
Geometry_ce_ptr);</font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> </font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> ret =
GEOSNearestPoints(this, other);</font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> if ( ! ret )
RETURN_NULL(); /* should get an exception first */</font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> </font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> /* return_value is a
zval */</font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3">
object_init_ex(return_value, Geometry_ce_ptr);</font></span></p>
<p style="margin:0px 0px 0px 47px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> </font></span><font color="#000000" face="Calibri" size="3">setRelay(return_value,
ret);</font></p>
<p style="margin:0px 0px 0px 47px"><font color="#000000" face="Calibri" size="3">}</font></p>
<p style="margin:0px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> </font></span></p>
<p style="margin:0px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3">The result
obtained using this function with PHP is always an empty GEOSGeometry object.</font></span></p>
<p style="margin:0px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> </font></span></p>
<p style="margin:0px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3">I would like
to ask you:</font></span></p>
<p style="margin:0px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> </font></span></p>
<p style="margin:0px 0px 0px 48px"><span lang="EN-US" style="margin:0px"><span style="margin:0px"><font color="#000000" face="Calibri" size="3">1)</font><span style='font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;font-family:"times new roman";margin:0px;font-stretch:normal'><font color="#000000"> </font></span></span></span><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3">Is possible to obtain the distance in
meter using the distance method?</font></span></p>
<p style="margin:0px 0px 0px 48px"><span lang="EN-US" style="margin:0px"><span style="margin:0px"><font color="#000000" face="Calibri" size="3">2)</font><span style='font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;font-family:"times new roman";margin:0px;font-stretch:normal'><font color="#000000"> </font></span></span></span><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3">Where is the error in the code
above? Some of you find errors in the code above?</font></span></p>
<p style="margin:0px 0px 0px 48px"><span lang="EN-US" style="margin:0px"><span style="margin:0px"><font color="#000000" face="Calibri" size="3">3)</font><span style='font-style:normal;font-variant:normal;font-weight:normal;font-size:7pt;line-height:normal;font-family:"times new roman";margin:0px;font-stretch:normal'><font color="#000000"> </font></span></span></span><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3">Could you suggest me another way to
obtain the minimum distance between two polygon using GEOS :-D ?</font></span></p>
<p style="margin:0px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> </font></span></p>
<p style="margin:0px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3">Thank you
very much for your help.</font></span></p><span class="gmail-HOEnZb"><font color="#888888">
<p style="margin:0px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> </font></span></p>
<p style="margin:0px"><span lang="EN-US" style="margin:0px"><font color="#000000" face="Calibri" size="3"> AS</font></span></p>
<font size="3"></font><br></font></span><br>______________________________<wbr>_________________<br>
geos-devel mailing list<br>
<a href="mailto:geos-devel@lists.osgeo.org">geos-devel@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/geos-devel" target="_blank" rel="noreferrer">https://lists.osgeo.org/<wbr>mailman/listinfo/geos-devel</a><br></blockquote></div><br></div></div>
<br>
</blockquote><br>