Transport-for-the-North / caf.space

https://cafspace.readthedocs.io/en/stable/
Other
2 stars 2 forks source link

Transformation fails if column already exists #39

Open CDuncan-TfN opened 4 days ago

CDuncan-TfN commented 4 days ago

Take two zoning systems, annie and brian:

annie = cs.inputs.ZoneSystemInfo(name='annie', id_col='unique_id', shapefile=ANNIE_PATH)
brian = cs.inputs.ZoneSystemInfo(name='brian', id_col='unique_id', shapefile=BRIAN_PATH)

  conf = cs.inputs.ZoningTranslationInputs(zone_1=annie, zone_2=brian)
trans = cs.ZoneTranslation(conf).spatial_translation()

Results in KeyError: "['annie_id'] not in index"

I believe the error occurs because the additional "annie_id" column in brian is being retained, then when the gpd.overlay method is called you get "annie_id_1" and "annie_id_2"

CDuncan-TfN commented 4 days ago

This could be resolved by retaining only the zone_id columns after reading the shapefiles in zone_correspondence.read_zone_shapefiles

isaac-tfn commented 3 days ago

Thanks for raising, I'll take a look soon. Hopefully it will be fixed in a branch soonish if this is blocking anything and then released not too long after.