<div dir="ltr">Could you use a KNN query for this, choosing the 6 nearest neighbours? Might still need to filter on distance to handle edge conditions, though. </div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jul 29, 2021 at 3:26 PM Bruce Rindahl <<a href="mailto:bruce.rindahl@gmail.com">bruce.rindahl@gmail.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>I have a table of points on a regular hexagon grid spacing. I need to create an edge table between every point and the points in its adjacent hexagon. </div><div>Say the table is points with an id field and point geom. I am trying :</div><div><br></div><div>WITH</div><div>p1 as (select * from points),</div><div>p2 as (select * from points)</div><div>SELECT </div><div><a href="http://p1.id" target="_blank">p1.id</a> as src,<br><a href="http://p2.id" target="_blank">p2.id</a> as dest,<br></div><div>st_makeline(p1.geom,p2.geom) as geom,<br></div><div>FROM p1, p2</div><div>WHERE <a href="http://p1.id" target="_blank">p1.id</a> != <a href="http://p2.id" target="_blank">p2.id</a> -- don't link a point to itself<br>and ST_dwithin (p1.geom,p2.geom, 16 * 1.74 ) -- only link to nearest 6 points (spacing 16)<br> and p1.geom > p2.geom -- only link in one direction<br></div><div><br></div><div>This works fine but gets really slow with lots of points. Is there a better way of attacking this problem?</div><div><br></div><div>Thanks</div></div>
_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/postgis-users" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/postgis-users</a><br>
</blockquote></div>