2

I have multiple layers, with multiple features, where I am interested in extracting information from a given feature within a rectangle. I am able to achieve this using the following filter,

currLayer.SetSpatialFilterRect(minx, miny, maxx, maxy)

This works very nicely when the feature has a single geometry associated with it. However, some of the features contain multiple geometries, which is evident when calling

feat.DumpReadable()

where some features contain POLYGON entries with 2+ geometries. And since the filter intersects one (or more) of the geometries, all are returned.

I was therfore wondering, is it possible to apply the filter to a given features geometries? Instead of to the POLYGON entry of the feature itself.

Additional information: Below is a link to an image showing the issues. The green bounding box is the applied spatial filter, where two objects are correctly selected and indicated by X. And since the box intersects two of the blue areas, they are also included. However, all the defined geometries within the blue areas are neither intersected or included within the green box. But due to being part of the overall feature, they are not filtered.

Image of filtering issues

ar = []

currLayer = ds.GetLayerByName("layername")
currLayer.SetSpatialFilterRect(minx, miny, maxx, maxy)
currLayer.GetFeatureCount()
for feat in currLayer:
    multi_geom = feat.GetGeometryRef()
    for iPnt in range(multi_geom.GetGeometryCount()):
        pnt = multi_geom.GetGeometryRef(iPnt)
        ar.append(pnt.GetPoints())

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.