TransWikia.com

GDAL/Python intersection does not include fields from method layer

Geographic Information Systems Asked by wowohweewah on March 5, 2021

As stated in title. I’m intersecting two layers and expecting fields from both input and intersect/method layers in the result. This is the behavior as describe in API docs (https://gdal.org/python/osgeo.ogr.Layer-class.html#Intersection). The resultant geometries/features are correct, but only the attributes from the input layer exist.

The field names are not the same and being overwritten. I’ve also tried it with Identity but no difference.

Code really boils down to: input_layer.Intersection(intersect_layer, output_layer)

I could write some manual code to do this by iterating through features and spatial joining to the method layer, but it adds quite a bit of script time. If there’s a way to get Intersection to work as I need, that would be most efficient.

Python v3.7.7 and GDAL/Py from GIS Internals release-1911 gdal-3.1.3

FIXED: This was my mistake. The output layer needs to be created as passed as ogr.Layer. If there is no field/attribute schema in this dataset, then GDAL puts attributes of both layers. I had used a shortcut helper function that creates an empty copy of the input layer (so as to automatically set same SRS and such). But while devoid of features, it was copying the field schema, thus overriding default behavior of function.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP