<div dir="ltr">Don't forgot to instantiate inFeatA e inFeatB<div><br></div><div><div>inFeatA = QgsFeature()</div><div>inFeatB = QgsFeature()</div></div><div><br></div><div><br></div><div>After <span style="font-family:arial,sans-serif;font-size:13px">vprovider.getFeatures() maybe you need to tests if inFeatB has a valid geometry and if geometry touches the current selected one, something like this:</span></div>
<div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13px">geomB = </span><span style="font-family:arial,sans-serif;font-size:13px">QgsGeometry( inFeatB.geometry() )</span></div>
<div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13px">if geomB.touches(geomA):</span></div><div><span style="font-family:arial,sans-serif;font-size:13px">   # do something</span></div>
<div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13px"><br></span></div><div><a href="http://www.qgis.org/api/classQgsGeometry.html#a6f4183fe331cc77ba3683c9d0d9c7181">http://www.qgis.org/api/classQgsGeometry.html#a6f4183fe331cc77ba3683c9d0d9c7181</a>  [touches method]<span style="font-family:arial,sans-serif;font-size:13px"><br>
</span></div><div><a href="http://www.qgis.org/api/classQgsVectorLayer.html#a33968fa939503a9e3873c88e5f0ea439">http://www.qgis.org/api/classQgsVectorLayer.html#a33968fa939503a9e3873c88e5f0ea439</a>  [selectedFeaturesIds]<br>
</div><div><br></div><div><br></div><div>PS: Sorry for the noise, but I sent the previous email without conclude it. This completes the previous one.</div><div><br></div><div>Hope it helps</div><div><br></div></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Sat, Oct 5, 2013 at 8:45 PM, Daniel <span dir="ltr"><<a href="mailto:danielvaz@gmail.com" target="_blank">danielvaz@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Hi Andreas,<div><br></div><div>First create a spatial index over layer features (I got this code from ftools_utils.py)</div><div><br></div><div><div># Convinience function to create a spatial index for input QgsVectorDataProvider</div>

<div>def createIndex( provider ):</div><div>    feat = QgsFeature()</div><div>    index = QgsSpatialIndex()</div><div>    fit = provider.getFeatures()</div><div>    while fit.nextFeature( feat ):</div><div>        index.insertFeature( feat )</div>

<div>    return index</div></div><div><br></div><div>Let's suppose that you have a vector layer "vlayer"</div><div><br></div><div><br></div><div><br></div><div>get the selected features:</div><div><br></div>

<div># vector data provider</div><div>vprovider = vlayer.dataProvider()<br></div><div><br></div><div># spatial index</div><div>index = createIndex(vprovider)<br></div><div><br></div><div># selected features</div><div><div>

selection = vlayer.selectedFeaturesIds()</div><div><br></div><div><br></div><div>for inFeatA in selection:</div><div>    geomA = QgsGeometry( inFeatA.geometry() )</div><div>    intersects = index.intersects( geomA.boundingBox() )</div>

</div><div>    for feat_id in intersects:</div><div>        # probably you want to discard some intersected feature that has in selection so...</div><div>        if feat_id in selection:</div><div>             continue</div>

<div>        vprovider.getFeatures( QgsFeatureRequest().setFilterFid( int( id ) ) ).nextFeature( inFeatB )</div><div>      </div><div><br></div></div><div class="gmail_extra"><div><div class="h5"><br><br><div class="gmail_quote">
On Fri, Oct 4, 2013 at 11:48 AM, Andreas Neumann <span dir="ltr"><<a href="mailto:a.neumann@carto.net" target="_blank">a.neumann@carto.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
In my little python plugin I would like to do the following:<br>
<br>
In a parcel layer the user can interactively select a street parcel<br>
(typically long parcels). The user could select one or more street parcels.<br>
<br>
My little python script should then select all parcels that touch the<br>
selected parcels, so the touching features are in the same table than<br>
the originally selected features.<br>
<br>
I did not work with spatial operators and selections so far. Does<br>
someone have some code around to start from?<br>
<br>
Thanks a lot!<br>
<br>
Andreas<br>
_______________________________________________<br>
Qgis-developer mailing list<br>
<a href="mailto:Qgis-developer@lists.osgeo.org" target="_blank">Qgis-developer@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/qgis-developer" target="_blank">http://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
</blockquote></div><br><br clear="all"><div><br></div></div></div><span class="HOEnZb"><font color="#888888">-- <br>Daniel Vaz
</font></span></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Daniel Vaz
</div>