Hi Stefan, <br>your workaround works fine in my case! <br><br>I looked at the QgsSpatialIndex code and I have bad news... It uses the bounding box <br>of the geometries!<br>This means that your workaround can work in a lot of cases but not in all cases, e.g. if <br>
you have more than N geometries (10 considering your workaround), ones inside <br>each other.<br><br>Cheers.<br><br><div class="gmail_quote">On Tue, Oct 26, 2010 at 6:47 PM, Ziegler Stefan <span dir="ltr"><<a href="mailto:Stefan.Ziegler@bd.so.ch" target="_blank">Stefan.Ziegler@bd.so.ch</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Hi Giuseppe<br>
<br>
I wrote a little workaround. Could you please update to 0.0.6 and check it with your test case? Thanks.<br>
<div><br>
regards<br>
Stefan<br>
<br>
mit freundlichem Gruss<br>
Stefan Ziegler<br>
<br>
<br>
----- Originalnachricht -----<br>
</div><div>Von: "Giuseppe Sucameli" <<a href="mailto:sucameli@faunalia.it" target="_blank">sucameli@faunalia.it</a>><br>
Gesendet: Mon, 25.10.2010 14:09<br>
</div><div>An: "Ziegler Stefan" <<a href="mailto:Stefan.Ziegler@bd.so.ch" target="_blank">Stefan.Ziegler@bd.so.ch</a>><br>
</div>Cc: "Jim Hammack" <<a href="mailto:hammack@gotslack.org" target="_blank">hammack@gotslack.org</a>> ; qgis-user <<a href="mailto:qgis-user@lists.osgeo.org" target="_blank">qgis-user@lists.osgeo.org</a>><br>
<div><div></div><div>Betreff: Re: AW: Re: Fwd: [Qgis-user] QGIS "Near"<br>
<br>
Hi all,<br>
<br>
two days ago I wrote a similar plugin for a LD talk in Pisa.<br>
I was unaware of the QgsSpatialIndex class (seems there's no documentation<br>
about it in the online QGis API pages or maybe I missed it) so I wrote a simple<br>
<br>
<br>
loop to find the closest feature.<br>
<br>
Now I tried also the Nearest plugin and they are different behavior!<br>
See the scheenshots [1] [2].<br>
<br>
AFAICS, Nearest select a wrong polygon.<br>
I see the plugin's code and I think it could a QgsSpatialIndex bug, but it could be<br>
<br>
<br>
also the normal behaviour (I didn't found its documentation on the API pages<br>
so I don't know).<br>
<br>
I'm going to add my plugin (ClosestFeatureFinded) to the Faunalia repo so you<br>
can try it and check the different behavior.<br>
<br>
<br>
<br>
I hope this can help to find the bug (if any).<br>
If you confirm it, I'll fill a bug report.<br>
<br>
Cheers.<br>
<br>
[1] <a href="http://img87.imageshack.us/img87/3232/nearest.jpg" target="_blank">http://img87.imageshack.us/img87/3232/nearest.jpg</a><br>
<br>
<br>
[2] <a href="http://img64.imageshack.us/img64/2066/closest.jpg" target="_blank">http://img64.imageshack.us/img64/2066/closest.jpg</a><br>
<br>
On Fri, Oct 22, 2010 at 9:19 AM, Ziegler Stefan <<a href="mailto:Stefan.Ziegler@bd.so.ch" target="_blank">Stefan.Ziegler@bd.so.ch</a>> wrote:<br>
<br>
<br>
there is some strange behaviour when using it with polygon features (at least I think it's a bit strange): sometimes when you click into a polygon I would expect that it selects the polygon I clicked into but it selects an adjacent polygon. This is probably due to the nearestNeighbor method of the spatial index. Since the two neighboring polygons share a common border the distance would be equal but the spatial index does not check if the coordindates of the mouse click lies within one of the two polygons.<br>
<br>
<br>
<br>
<br>
<br>
regards<br>
<br>
Stefan<br>
<br>
<br>
<br>
mit freundlichem Gruss<br>
<br>
Stefan Ziegler<br>
<br>
<br>
<br>
<br>
<br>
----- Originalnachricht -----<br>
<br>
Von: "Jim Hammack" <hammack@GotSlack.org><br>
<br>
Gesendet: Don, 21.10.2010 19:20<br>
<br>
An: "Ziegler Stefan" <<a href="mailto:Stefan.Ziegler@bd.so.ch" target="_blank">Stefan.Ziegler@bd.so.ch</a>><br>
<br>
Cc: qgis-user <<a href="mailto:qgis-user@lists.osgeo.org" target="_blank">qgis-user@lists.osgeo.org</a>><br>
<br>
Betreff: Re: AW: Re: Fwd: [Qgis-user] QGIS "Near"<br>
<br>
<br>
<br>
<br>
<br>
Stefan,<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
I was looking for the same functionality as Zoran so have<br>
<br>
also been working with your "Nearest" plugin. It is exactly<br>
<br>
what I need and seems to work well.<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
Thanks!<br>
<br>
<br>
<br>
Jim<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
On 10/20/2010 01:54 PM, Ziegler Stefan wrote:<br>
<br>
<br>
<br>
<br>
<br>
Hi Zoran<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
I had some time left, took all<br>
<br>
my code snippets and also the one from Carson. Please try<br>
<br>
the plugin "Nearest" that should cover your example 1:<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<a href="http://www.catais.org/qgis/plugins.xml" target="_blank">http://www.catais.org/qgis/plugins.xml</a><br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
regards<br>
<br>
<br>
<br>
Stefan<br>
<br>
<br>
<br>
<br>
<br>
-----Ursprüngliche<br>
<br>
Nachricht-----<br>
<br>
<br>
<br>
Von: Zoran Jankovic [mailto:<a href="mailto:zoran.jankovic@zisis.hr" target="_blank">zoran.jankovic@zisis.hr</a>]<br>
<br>
<br>
<br>
Gesendet am: Mittwoch, 20. Oktober 2010 19:21<br>
<br>
<br>
<br>
An: qgis-user<br>
<br>
<br>
<br>
Betreff: Re: Fwd: [Qgis-user] QGIS "Near"<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
Hi Joe,<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
On Wed, Oct 20, 2010 at 5:06 PM, Joe<br>
<br>
Larson <<a href="mailto:joelarso@gmail.com" target="_blank">joelarso@gmail.com</a>><br>
<br>
wrote:<br>
<br>
<br>
<br>
<br>
<br>
Does the function 'snapWithContext'<br>
<br>
<br>
<br>
<a href="http://doc.qgis.org/head/classQgsVectorLayer.html#733b974dce13d587e05cf3d4fc24f208" target="_blank">http://doc.qgis.org/head/classQgsVectorLayer.html#733b974dce13d587e05cf3d4fc24f208</a><br>
<br>
<br>
<br>
which "Snaps to segment or vertex within given tolerance."<br>
<br>
seem like<br>
<br>
<br>
<br>
what you're looking for? I came across it while trying to<br>
<br>
get Quantum<br>
<br>
<br>
<br>
Navigator working recently...seemed relative, but I'm no<br>
<br>
expert!<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
This is similar to the mentioned solution with<br>
<br>
selecting by radius, or changing the tolerance of ID tool.<br>
<br>
Close, but no cigar. Since this is not very urgent, I've<br>
<br>
decided to continue pursuing that outlined solution Carson<br>
<br>
gave, and write a plugin i Python based on that. Since I<br>
<br>
actually never used Python before, it may take a while,<br>
<br>
but hey, I get to learn sth. new :-).<br>
<br>
<br>
<br>
I never got the word back from Carson, has he developed<br>
<br>
anything along these lines, but I have to presume he<br>
<br>
didn't...<br>
<br>
<br>
<br>
Anyone interested in joning me, or even earning some<br>
<br>
money, is still invited to jump on board. My GIS<br>
<br>
implementation project is well on the way, and it seems<br>
<br>
there'll even be some money involved :-).<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
Zoran<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
~joe<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
On Tue, Oct 19, 2010 at 9:55 AM, Andreas Neumann<br>
<br>
<a.neumann at <a href="http://carto.net" target="_blank">carto.net</a>>wrote:<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
> Hi Zoran,<br>
<br>
<br>
<br>
><br>
<br>
<br>
<br>
> I believe the infrastructure of what you want is<br>
<br>
already wihtin the<br>
<br>
<br>
<br>
> selection and identify tools in QGIS. Isn't this<br>
<br>
almost implemented in the<br>
<br>
<br>
<br>
> current identify tool?<br>
<br>
<br>
<br>
><br>
<br>
<br>
<br>
><br>
<br>
<br>
<br>
It sort of is, but not completely. Identify will ID<br>
<br>
all the features within<br>
<br>
<br>
<br>
certain radios (percentage of extent), but it will ID<br>
<br>
_all_ of the features<br>
<br>
<br>
<br>
within this radius. I only need the nearest, no matter<br>
<br>
how far away... Let<br>
<br>
<br>
<br>
us say it is, for simplicity, within current extent.<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
> The current identify tool selects "near" or<br>
<br>
"close by" features within a<br>
<br>
<br>
<br>
> certain tolerance. This tolerance can be set in<br>
<br>
"Options" --> "Map tools"<br>
<br>
<br>
<br>
> "search radius". I believe it currently only<br>
<br>
effects the identify tool. Do<br>
<br>
<br>
<br>
> you want the same tolerance also be used for the<br>
<br>
click-selection tool?<br>
<br>
<br>
<br>
><br>
<br>
<br>
<br>
><br>
<br>
<br>
<br>
Look above. This could be useful, but it is not the<br>
<br>
functionality I'm<br>
<br>
<br>
<br>
currently looking after.<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
> Are you also aware that in QGIS 1.6 there are new<br>
<br>
selection tools?<br>
<br>
<br>
<br>
><br>
<br>
<br>
<br>
> * by click<br>
<br>
<br>
<br>
> * by rectangle<br>
<br>
<br>
<br>
> * by polygon<br>
<br>
<br>
<br>
> * by freehand<br>
<br>
<br>
<br>
> * by radius<br>
<br>
<br>
<br>
><br>
<br>
<br>
<br>
><br>
<br>
<br>
<br>
Yup, these are great, but they all select _multiple_<br>
<br>
features within radius,<br>
<br>
<br>
<br>
rectangle, etc.<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
> Maybe this also helps to address your needs?<br>
<br>
<br>
<br>
><br>
<br>
<br>
<br>
> Of course you can combine it with previous<br>
<br>
selections by pressing the ctrl<br>
<br>
<br>
<br>
> key.<br>
<br>
<br>
<br>
><br>
<br>
<br>
<br>
><br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
BR,<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
---<br>
<br>
<br>
<br>
Zoran Jankovic<br>
<br>
<br>
<br>
ZIS-Izrada softvera i savjetovanje / ZIS - Software<br>
<br>
Development and<br>
<br>
<br>
<br>
Consulting<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<a href="http://www.zisis.hr" target="_blank">http://www.zisis.hr</a><br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
M: 00 385 98 682 902<br>
<br>
<br>
<br>
T: 00 385 44 683 374<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
A. Senoe 4<br>
<br>
<br>
<br>
44320 Kutina<br>
<br>
<br>
<br>
Croatia<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
<br>
<br>
<br>
Qgis-user mailing list<br>
<br>
<br>
<br>
<a href="mailto:Qgis-user@lists.osgeo.org" target="_blank">Qgis-user@lists.osgeo.org</a><br>
<br>
<br>
<br>
<a href="http://lists.osgeo.org/mailman/listinfo/qgis-user" target="_blank">http://lists.osgeo.org/mailman/listinfo/qgis-user</a><br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
<br>
Qgis-user mailing list<br>
<br>
<a href="mailto:Qgis-user@lists.osgeo.org" target="_blank">Qgis-user@lists.osgeo.org</a><br>
<br>
<a href="http://lists.osgeo.org/mailman/listinfo/qgis-user" target="_blank">http://lists.osgeo.org/mailman/listinfo/qgis-user</a><br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
<br>
Qgis-user mailing list<br>
<br>
<a href="mailto:Qgis-user@lists.osgeo.org" target="_blank">Qgis-user@lists.osgeo.org</a><br>
<br>
<a href="http://lists.osgeo.org/mailman/listinfo/qgis-user" target="_blank">http://lists.osgeo.org/mailman/listinfo/qgis-user</a><br>
<br>
<br>
<br>
--<br>
Giuseppe Sucameli<br>
<br>
<br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Giuseppe Sucameli<br><br>