Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
from shapely.geometry import mapping, shape
import fiona
import csv
record_index = 'grid filed1 filed2'
record_index = record_index.split()
all_record = {}
with open("resut.csv", 'r') as f:
r = csv.DictReader(f)
for i in r:
all_record[i['\ufeffgrid']] = i
with fiona.collection('demo_area.shp', 'r') as polygon:
schema = polygon.schema.copy()
for i in record_index:
if i != 'grid':
schema['properties'][i] = 'int'
schema['grid'] = 'str'
with fiona.collection('test_area.shp', 'w', 'ESRI Shapefile', schema) as output:
polygons = [elem for elem in polygon]
for poly in polygons:
res = {}
ret_pro = {**poly['properties'], **all_record[poly['properties']['grid']]}
del ret_pro['\ufeffgrid']
res['properties'] = ret_pro
res['geometry'] = mapping(shape(poly['geometry']))
output.write(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.