I would like to do a spatial merge of the address nodes of Baton Rouge into their surrounding building footprints. Every building (polygon) should get the properties of the address (point).
Here is an visualization of the task:
I've tried to use the shapely+fiona solution from here. I've only changed it that the polygon shapefile get's written with the point shapefile's properties (before it was the other way round).
import fiona
from shapely.geometry import shape
from copy import deepcopy
with fiona.open("Building_Footprint.shp", "r") as buildings:
with fiona.open("Street_Address.shp", "r") as addresses:
outSchema = deepcopy(buildings.schema)
outSchema['properties'].update(addresses.schema['properties'])
print(outSchema)
with fiona.open ("Joined.shp", "w", buildings.driver, outSchema, buildings.crs) as output:
for address in addresses:
for building in buildings:
# check if point is in polygon and set attribute
if shape(address['geometry']).within(shape(building['geometry'])):
print("yes")
building['properties'] = address['properties']
# write out
output.write({
'properties': building['properties'],
'geometry': building['geometry']
})
But I'm getting ValueError: Record does not match collection schema: odict_keys(['ID', ...]
Why is it failing?

outSchemaafter you dooutSchema['properties'].update(addresses.schema['properties'])– ziggy Oct 09 '18 at 02:40'geometry': 'Polygon'out of the outSchema – ziggy Oct 09 '18 at 17:15