<div dir="ltr">Hi Gerard,<div><br></div><div>Considering that your points will always be in the heart of your polygons, an ST_Intersects would be faster than ST_Within. 1000 points x 1000 polygons should not be a problem at all in this matter, but you might consider adding a spatial index to the polygons.</div><div>On a side note: if your GUI is a web-site, you may consider using D3 voronoi: <a href="https://github.com/d3/d3-voronoi">https://github.com/d3/d3-voronoi</a> It does exactly what you describe.</div><div><br></div><div>Best, </div><div>  Tom</div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, 2 Mar 2017 at 04:28 Gerard LYNCH <<a href="mailto:gerard.lynch@ericsson.com">gerard.lynch@ericsson.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div lang="EN-US" link="blue" vlink="purple" class="gmail_msg">
<div class="m_-5319100882615132583WordSection1 gmail_msg">
<p class="MsoNormal gmail_msg">Hello,<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">I'm using postgis2.3 and ST_VoronoiPolygons. <u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">I would like to know the best way to do a reverse lookup of sorts to find out which Voronoi polygon maps to which point(s) used in ST_Collect.<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">Currently I'm looping through each of the input points and doing a ST_Within on each of the Voronoi polygons until I get a match. This can be time consuming when there are 1000 points and 1000 voronoi polygons. I could also do the reverse
 and loop through each of the Voronoi polygons and fetch points within the polygon but I am wondering if there is a more efficient approach.<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">Ideally an object that returned something like "Polygon1 => [pointa, pointb], Polygon2 => [pointc]" etc would be preferable.<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">My use case is when someone clicks on a Voronoi polygon in my GUI I would like to be able to provide the user with information on the points used to create that polygon.
<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">Cheers, <u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">Gerard<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></p>
</div>
</div>

_______________________________________________<br class="gmail_msg">
postgis-users mailing list<br class="gmail_msg">
<a href="mailto:postgis-users@lists.osgeo.org" class="gmail_msg" target="_blank">postgis-users@lists.osgeo.org</a><br class="gmail_msg">
<a href="https://lists.osgeo.org/mailman/listinfo/postgis-users" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.osgeo.org/mailman/listinfo/postgis-users</a></blockquote></div>