I have one point layer and one polygon layer with a common identifier attribute field called "N", same objects amounts but Feature IDs (FID) are different.

I have to iterate on the first one and what I want is to get the FID from the second using an attribute join (access to FID from the polygon using the specific field value of "N" as a bridge between both layers.

for feature in pointsLayer
    bridge = feature.GetField('N')

    # Here I want to select my feature from my other layer 
    # which has the same attribute value "N"

As I read for now, I have 2 solutions, SQL request or create a matching table N-idPolygon?

Any hint what would be more efficient? We talk about 10000 features max in each layer.

  • It is an exercise or a personal work ? If it is a personal work, look at Problem intersecting shapefiles with OGR in Python. It is much easier to work with Fiona (only Python dictionaries and your problem is easy to resolve without SQL or matching table)
    – gene
    Jan 15, 2016 at 16:24
  • Ty @gene, actually it's a little bit of both, since I like to achieve this operation in a QGIS plugin. Ty for the Fiona tipp, I'll keep it for later use since I do not want to use many more librairies than the ones that are installed on a QGIS 2.2 standard desktop installation. I was actually surprised that there were no simple query function in ogr to get directly a feature from it's field value.
    – Nono
    Jan 17, 2016 at 10:51


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.