<div dir="ltr"><div>Hi all,</div><div>to compare the alternatives, I've run some tests using pgbench, using the full original dataset (36k curved polygons), </div><div>with 32 clients and 4000 transactions each, testing 3 scenarios:</div><div><ul><li>The current query using ST_Intersection as is (returns 2 polygons, wrong result but I'm treating it as the baseline)</li><li>Using && + ST_Distance</li><li>Using && + linearized intersection, with a precision good enough to get the correct result (0.01 meters)</li></ul><div>I find the results surprsing:</div></div><div><br></div><div>> pgbench -U cite helsinki -f baseline.sql -c 32 -t 2000<br>tps = 10227.810087 ((without initial connection time)<br><br>> pgbench -U cite helsinki -f distance.sql -c 32 -t 2000<br>tps = 19989.627257 (without initial connection time)<br><br>> pgbench -U cite helsinki -f linearized.sql -c 32 -t 2000<br>tps = 8984.594159 (without initial connection time)<br><br>So... testing with the distance is twice as fast as the other options? Wow, have we been doing intersection tests wrong all this time? ROFL</div><div>Other possible ideas:</div><div><ul><li>There is something specific to having curves in the mix, and having to pay the cost of linearization makes distance competitive?</li><li>The specific dataset is playing an important role in the result?</li></ul></div><div><br></div><div>Ah, since there seems to be a real issue, I've also opened a ticket in trac: <a href="https://trac.osgeo.org/postgis/ticket/5832#ticket">https://trac.osgeo.org/postgis/ticket/5832#ticket</a></div><div><br></div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><span><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-family:Arial;color:rgb(34,34,34);vertical-align:baseline;white-space:pre-wrap">Regards,</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-family:Arial;color:rgb(34,34,34);vertical-align:baseline;white-space:pre-wrap">Andrea Aime</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-family:Arial;color:rgb(34,34,34);vertical-align:baseline;white-space:pre-wrap"><br></span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-family:Arial;color:rgb(34,34,34);vertical-align:baseline;white-space:pre-wrap">==</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-family:Arial;color:rgb(34,34,34);vertical-align:baseline;white-space:pre-wrap"><br></span><span style="font-family:Arial;color:rgb(34,34,34);vertical-align:baseline;white-space:pre-wrap">GeoServer Professional Services from the experts!</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-family:Arial;color:rgb(34,34,34);vertical-align:baseline;white-space:pre-wrap">Visit </span><a href="http://bit.ly/gs-services-us" target="_blank"><span style="font-family:Arial;color:rgb(17,85,204);vertical-align:baseline;white-space:pre-wrap">http://bit.ly/gs-services-us</span></a><span style="font-family:Arial;color:rgb(34,34,34);vertical-align:baseline;white-space:pre-wrap"> for more information.</span><span style="font-family:Arial;color:rgb(34,34,34);vertical-align:baseline;white-space:pre-wrap"><br></span><span style="font-family:Arial;color:rgb(34,34,34);vertical-align:baseline;white-space:pre-wrap"><br></span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-family:Arial;color:rgb(34,34,34);vertical-align:baseline;white-space:pre-wrap">==</span><span style="font-family:Arial;color:rgb(34,34,34);vertical-align:baseline;white-space:pre-wrap"><br></span><span style="font-family:Arial;color:rgb(34,34,34);vertical-align:baseline;white-space:pre-wrap"><br></span><span style="font-family:Arial;color:rgb(34,34,34);vertical-align:baseline;white-space:pre-wrap">Ing. Andrea Aime </span><span style="font-family:Arial;color:rgb(34,34,34);vertical-align:baseline;white-space:pre-wrap"><br></span><span style="font-family:Arial;color:rgb(34,34,34);vertical-align:baseline;white-space:pre-wrap">@geowolf</span><span style="font-family:Arial;color:rgb(34,34,34);vertical-align:baseline;white-space:pre-wrap"><br></span><span style="font-family:Arial;color:rgb(34,34,34);vertical-align:baseline;white-space:pre-wrap">Technical Lead</span><span style="font-family:Arial;color:rgb(34,34,34);vertical-align:baseline;white-space:pre-wrap"><br><br></span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-family:Arial;color:rgb(34,34,34);vertical-align:baseline;white-space:pre-wrap">GeoSolutions Group</span><span style="font-family:Arial;color:rgb(34,34,34);vertical-align:baseline;white-space:pre-wrap"><br></span><span style="font-family:Arial;color:rgb(34,34,34);vertical-align:baseline;white-space:pre-wrap">phone: +39 0584 962313</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-family:Arial;color:rgb(34,34,34);vertical-align:baseline;white-space:pre-wrap">fax: +39 0584 1660272</span></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-family:Arial;color:rgb(34,34,34);vertical-align:baseline;white-space:pre-wrap">mob: +39 339 8844549</span></p><br><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><a href="https://www.geosolutionsgroup.com/" target="_blank"><span style="font-family:Arial;color:rgb(17,85,204);vertical-align:baseline;white-space:pre-wrap">https://www.geosolutionsgroup.com/</span></a></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><a href="http://twitter.com/geosolutions_it" target="_blank"><span style="font-family:Arial;color:rgb(17,85,204);vertical-align:baseline;white-space:pre-wrap">http://twitter.com/geosolutions_it</span></a></p><p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt"><span style="font-family:Arial;color:rgb(34,34,34);vertical-align:baseline;white-space:pre-wrap">-------------------------------------------------------</span></p><br><span style="font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-wrap">Con riferimento alla normativa sul trattamento dei dati personali (Reg. UE 2016/679 - Regolamento generale sulla protezione dei dati “GDPR”), si precisa che ogni circostanza inerente alla presente email (il suo contenuto, gli eventuali allegati, etc.) è un dato la cui conoscenza è riservata al/i solo/i destinatario/i indicati dallo scrivente. Se il messaggio Le è giunto per errore, è tenuta/o a cancellarlo, ogni altra operazione è illecita. Le sarei comunque grato se potesse darmene notizia.</span><span style="font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-wrap"><br></span><span style="font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-wrap"><br></span><span style="font-family:Arial;color:rgb(0,0,0);background-color:transparent;vertical-align:baseline;white-space:pre-wrap">This email is intended only for the person or entity to which it is addressed and may contain information that is privileged, confidential or otherwise protected from disclosure. We remind that - as provided by European Regulation 2016/679 “GDPR” - copying, dissemination or use of this e-mail or the information herein by anyone other than the intended recipient is prohibited. If you have received this email by mistake, please notify us immediately by telephone or e-mail</span></span><br></div></div></div><br></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Sun, Dec 22, 2024 at 4:44 PM Andrea Aime <<a href="mailto:andrea.aime@geosolutionsgroup.com">andrea.aime@geosolutionsgroup.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div>Hi Paul,</div><div>thanks a lot for following up. Comments inline below.</div><div><br></div></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>These are literally CurvePolygon type? </div></blockquote><div><br></div><div>The column type is just "geometry(Geometry,3879)", while ST_GeometryType returns "multisurface" for both.</div><div>When doing a ST_AsText instead, you'll get something like:</div><div><br></div><div>MULTISURFACE(CURVEPOLYGON(COMPOUNDCURVE((...</div><div><br></div><div>for both.</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"><div>It’s probably getting caught in our lack of full curve support.<div>I would be interested in the ST_Distance between the point and those two CurvePolygons. (Because, for distance, we have a postgis-native implementation that supports curves). </div></div></blockquote><div><br></div><div>=# SELECT ogc_fid, ST_Distance(ST_GeomFromText('POINT (25492818 6677399.98)', 3879), geom) FROM testdata;<br></div><div><br></div><div> ogc_fid | st_distance <br>---------+---------------------<br> 1258 | 0.01234572446598792<br> 12875 | 0<br>(2 rows)<br></div><div><br></div><div>Indeed, the correct answer, 12875 contains the point, while the other polygon is close to it.</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"><div><div>Whereas for intersection, the calculation is delegated to GEOS *after linearizing the inputs*. In that linearization, could sit the logically problem you’re seeing.</div></div></blockquote><div><br></div><div>Let's check with different tolerances... yes, changing the tolerance changes the result:</div><div><br></div><div>=# SELECT ogc_fid FROM testdata WHERE ST_Intersects(ST_CurveToLine(geom, 0.01, 1, 1), ST_GeomFromText('POINT (25492818 6677399.98)', 3879));<br> ogc_fid <br>---------<br> 12875<br>(1 row)<br><br># SELECT ogc_fid FROM testdata WHERE ST_Intersects(ST_CurveToLine(geom, 0.02, 1, 1), ST_GeomFromText('POINT (25492818 6677399.98)', 3879));<br> ogc_fid <br>---------<br> 1258<br>(1 row)</div><div><br></div><div>In the immediate future, I guess I could have the GeoTools PostGIS store use either approach, when knowing curves are involved... </div><div>First using && to perform a first rough filter, and then either use either</div><div>* ST_Distance equals to 0</div><div>* An explicit linearization with a target tolerance (this is an urban application, so I'm guessing they will need centimeter, if not millimeter, precision)</div><div>.</div><div>Is there a clear winner here in terms of performance, or performance of distance vs linearized intersection is more contextual to the geometries involved?</div><div><br></div><div>Cheers</div><div>Andrea</div></div></div>
</blockquote></div>