1

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:

Visualization

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?

  • what happens when you print out the outSchema after you do outSchema['properties'].update(addresses.schema['properties']) – ziggy Oct 9 '18 at 2:40
  • {'properties': OrderedDict([('ID', 'int:10'), ('AREA_SQFT', 'float:24.15'), ('HEIGHT_FEE', 'str:80'), ('NUMBER_FLO', 'str:80'), ('YEAR_BUILT', 'str:80'), ('ADDRESS_ID', 'int:10'), ('BUSINESS_N', 'str:99'), ('FULL_ADDRE', 'str:80'), ('CITY', 'str:80'), ('ADDRESS_JU', 'str:80'), ('STATE', 'str:80'), ('ZIP', 'int:10'), ('COUNTRY', 'str:80'), ('ADDRESS_AU', 'str:80'), ('SUBDIVISIO', 'str:80'), ('BUSINESS_I', 'str:80'), ('BUSINESS_1', 'str:80'), ('SERVICE_TY', 'str:80'), ('SERVICE_NA', 'str:80')]), 'geometry': 'Polygon'} – Luis Paganini Oct 9 '18 at 9:32
  • maybe delete the 'geometry': 'Polygon' out of the outSchema – ziggy Oct 9 '18 at 17:15

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.