<div dir="ltr"><div><div><div><div><div><div><div><div><div><div>Hey,<br></div>I also frequently use the function 1, it would be cool to have it in native efficient C .<br></div><div>Function 2 is especially interesting coupled with pg_pointcloud.<br></div><div><br>I do it with sql (temp table or CTE depending on size) : <br>cluster = St_Dump(St_Union)<br>, then for each geometry, test in which cluster it is.<br>It can be accelerated by creating temp table and indexes on it.<br><br></div>As long as the "interonnected " means spatially overlapsing its fine, <br>but sadly it doesn't work when using multipolygons for instance.<br></div>My workaround was to solve the interconnected problem with plpython and networkx (in network, this is called the connected components problem)..<br></div><div>It can work with any relation (for instance, you want your cluster to be spatial wise and also relating to an attribute).<br></div></div></div></div><br></div>Function 2 is function 1 with either a buffer of X, or use of ST_DWithin instead of intersect for interconnection definition then previous networkx solution.<br></div>It can be greatly accelerated (at some cost) if you are willing to quantize your coordinates (with snaptogrid for instance).<br></div><div>First you snap to grid all points, then use a SELECT DISTINCT on quantized coordinates. This can greatly reduce the number of points.<br></div>Then it is fast to compute cluster either with buffer or networkx.<br><br>Cheers,<br><div><div>Rémi-C <br><div><div><div><div><div><div><br></div></div></div></div></div></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-01-15 13:14 GMT+01:00 Daniel Baston <span dir="ltr"><<a href="mailto:dbaston@gmail.com" target="_blank">dbaston@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div>Hello,<br><br>I'm working on a couple of C-language functions to solve some clustering problems I frequently face in PostGIS. I'm wondering if there may be any level of interest in including such functions in the project? I would be happy to flesh these out to include the error-handling and unit-testing that would be required.<br><br></div>Function #1 takes a GeometryCollection and returns the same geometries, re-aggregated into groups of interconnected geometries (solving a question I posted about at <a href="http://gis.stackexchange.com/q/94203" target="_blank">http://gis.stackexchange.com/q/94203</a> )<br><br></div><div>(Internally this builds an STRtree using GEOS and uses a union-find structure to identify connected components....as an aside, I am wondering if there is some way to take advantage of a database spatial index that may already exist)<br></div><div><br></div></div>Function #2 (not written) would solve a related problem - we want to take a set of points and return a set of MultiPoints, where each point in a MultiPoint is within distance X of some other point in the MultiPoint.<br><br></div>Thanks,<br>Dan<br></div>
<br>_______________________________________________<br>
postgis-devel mailing list<br>
<a href="mailto:postgis-devel@lists.osgeo.org">postgis-devel@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-devel" target="_blank">http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-devel</a><br></blockquote></div><br></div>