Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from qgis.utils import iface
- from PyQt4.QtCore import QVariant
- _ID_FIELD = 'RS'
- _NAME_FIELD = 'GEN'
- _PLZ_FIELD = 'plz'
- _NEW_ID_FIELD = 'PARENT_ID'
- _NEW_NAME_FIELD = 'PARENT_NAME'
- Land_layer = iface.mapCanvas().layer(1)
- PLZ_layer = iface.mapCanvas().layer(0)
- # Create 2 new fields in the layer that will hold the list of neighbors and sum
- # of the chosen field.
- #PLZ_layer.startEditing()
- #PLZ_layer.dataProvider().addAttributes(
- # [QgsField(_NEW_ID_FIELD, QVariant.String),
- # QgsField(_NEW_NAME_FIELD, QVariant.Int)])
- #PLZ_layer.updateFields()
- ## Create a dictionary of all features
- PLZ_feature_dict = {f.id(): f for f in PLZ_layer.getFeatures()}
- Land_feature_dict = {f.id(): f for f in Land_layer.getFeatures()}
- # Build a spatial index
- index = QgsSpatialIndex()
- print 'PLZ Layer: %s' % PLZ_layer.name()
- print 'Landkreis Layer: %s' % Land_layer.name()
- for f in Land_feature_dict.values():
- index.insertFeature(f)
- print 'Inserting %s in Landkreis index' % f[_NAME_FIELD]
- for f in PLZ_feature_dict.values():
- print 'Working on %s' % f[_PLZ_FIELD]
- geom = f.geometry()
- intersect_ids = index.intersects(geom.boundingBox())
- for id in intersect_ids:
- tempf = Land_feature_dict[id]
- print 'got parent Landkreis %s' % tempf[_NAME_FIELD]
- intersect_ids = index.intersects(geom.boundingBox())
- Traceback (most recent call last):
- File "<input>", line 1, in <module>
- File "//VAIMUCO9/G114305$/Anwendungsdaten/Desktop/PLZ/ContainerFinder.py", line 34, in <module>
- intersect_ids = index.intersects(geom.boundingBox())
- AttributeError: 'NoneType' object has no attribute 'boundingBox'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement