I don't think you actually have to deal with the magic number. <div><br></div><div>Something like </div><div>select * from foo where st_within(st_extent(st_knnbox(geoma,geomb,10),geoma)) order by st_distance(geoma,geomb) limit 10</div>
<div><br></div><div>would still be able to use the KNN index to find the magic extent that will include all the features that are possible to be in the closest 10 as from the furthest extent of the 10 closest boxes will certainly include all of the "actual" 10 closest.</div>
<div><br><br><div class="gmail_quote">On Mon, Sep 26, 2011 at 4:40 PM, Paul Ramsey <span dir="ltr"><<a href="mailto:pramsey@opengeo.org">pramsey@opengeo.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Trade-offs abound.<br>
centroid-vs-centroid has the advantage of ease of understanding<br>
box-vs-box has the advantage of being over-determined. you could at<br>
least theoretically do an index-assisted knn pull wrapped as a<br>
subquery inside a standard st_distance test. however, that goes back<br>
to magic numbers again (how many items should one pull in the indexed<br>
query) so...<br>
There don't seem to be any great soln's here.<br>
<font color="#888888">P.<br>
</font><div><div></div><div class="h5"><br>
On Mon, Sep 26, 2011 at 2:35 PM, Paragon Corporation <<a href="mailto:lr@pcorp.us">lr@pcorp.us</a>> wrote:<br>
> Okay I get the issue now forgot it was for order by stuff. I guess from my<br>
> perspective bounding box would be better though that's not ideal either.<br>
> for long linestrings which is what I'm usually dealing with centroid is<br>
> useless and for small polygons the bounding box is a better approximation<br>
> than centroid<br>
> for thumbnail check.<br>
><br>
> It's ST_Distance BTW -- get with the program Paul. Your beloved distance is<br>
> gone. No more. history vamush. :)<br>
><br>
> Thanks,<br>
> Regina<br>
><br>
><br>
>> -----Original Message-----<br>
>> From: <a href="mailto:postgis-devel-bounces@postgis.refractions.net">postgis-devel-bounces@postgis.refractions.net</a><br>
>> [mailto:<a href="mailto:postgis-devel-bounces@postgis.refractions.net">postgis-devel-bounces@postgis.refractions.net</a>] On<br>
>> Behalf Of Paul Ramsey<br>
>> Sent: Monday, September 26, 2011 4:25 PM<br>
>> To: PostGIS Development Discussion<br>
>> Subject: Re: [postgis-devel] KNN and Semantics<br>
>><br>
>> KNNGist walks the index tree to provide ordered results.<br>
>> Great.<br>
>> But it's walking the tree, so the results have to be based on boxes.<br>
>> In the case of points, the box == the point, so the ambiguity<br>
>> collapses.<br>
>> In the case of everything else, it does not.<br>
>><br>
>> So, when someone does<br>
>><br>
>> select * from mytable order by geom <-> 'polygon()'::geometry;<br>
>><br>
>> what should they get back to provide the minimum surprise?<br>
>> Because they *will* get back results that differ from<br>
>><br>
>> select * from mytable order by distance(geom, 'polygon()'::geometry);<br>
>><br>
>> sometimes substantially.<br>
>><br>
>> P.<br>
>><br>
>> On Mon, Sep 26, 2011 at 1:19 PM, Paragon Corporation<br>
>> <<a href="mailto:lr@pcorp.us">lr@pcorp.us</a>> wrote:<br>
>> ><br>
>> >> So, here's the deal, the KNN search works exclusively against the<br>
>> >> index. So, it only has boxes available to make decisions (not<br>
>> >> entirely true, it actually has the full geometry of the query key,<br>
>> >> but not of the index keys). That means it can return an<br>
>> exact answer<br>
>> >> for point-on-point queries, but for everything else it'll be a box<br>
>> >> approximation. So the n-nearest-boxes.<br>
>> >><br>
>> >> There are lots of ways to attack the problem... we can do pure<br>
>> >> nearest-boxes. We could also convert all the boxes to<br>
>> points, and do<br>
>> >> nearest-centroids. This might be easiest to explain,<br>
>> potentially. The<br>
>> >> trouble is, we're going to be returning an approximation for<br>
>> >> everything except points, so the question is (in my mind) which<br>
>> >> approximation is easiest to visualize and work with?<br>
>> >><br>
>> ><br>
>> > Not sure I understand your question Paul? I don't see how nearest<br>
>> > centroids helps much when you are talking about largish<br>
>> polygons. I<br>
>> > was thinking this would just make the ST_Expand like stuff<br>
>> faster? Oh<br>
>> > perhaps I misunderstood that.<br>
>> ><br>
>> > Thanks,<br>
>> > Regina<br>
>> ><br>
>> ><br>
>> ><br>
>> > _______________________________________________<br>
>> > postgis-devel mailing list<br>
>> > <a href="mailto:postgis-devel@postgis.refractions.net">postgis-devel@postgis.refractions.net</a><br>
>> > <a href="http://postgis.refractions.net/mailman/listinfo/postgis-devel" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-devel</a><br>
>> ><br>
>> _______________________________________________<br>
>> postgis-devel mailing list<br>
>> <a href="mailto:postgis-devel@postgis.refractions.net">postgis-devel@postgis.refractions.net</a><br>
>> <a href="http://postgis.refractions.net/mailman/listinfo/postgis-devel" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-devel</a><br>
>><br>
><br>
><br>
> _______________________________________________<br>
> postgis-devel mailing list<br>
> <a href="mailto:postgis-devel@postgis.refractions.net">postgis-devel@postgis.refractions.net</a><br>
> <a href="http://postgis.refractions.net/mailman/listinfo/postgis-devel" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-devel</a><br>
><br>
_______________________________________________<br>
postgis-devel mailing list<br>
<a href="mailto:postgis-devel@postgis.refractions.net">postgis-devel@postgis.refractions.net</a><br>
<a href="http://postgis.refractions.net/mailman/listinfo/postgis-devel" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-devel</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>************************************<br>David William Bitner<br>
</div>