Skip to content

Instantly share code, notes, and snippets.

@ficapy
Created July 2, 2019 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ficapy/100021f84ae94bbdbe3d70671438a130 to your computer and use it in GitHub Desktop.
Save ficapy/100021f84ae94bbdbe3d70671438a130 to your computer and use it in GitHub Desktop.
from shapely.geometry import mapping, Polygon
import fiona
import csv
# Carrefour GZ
gz = Polygon([])
# chengdu 1
cd1 = Polygon([])
# chengdu 2
cd2 = Polygon([])
# kum
km = Polygon([])
hah = ['grid', 'field1']
pro = {i: 'str' if i == 'grid' else 'int' for i in hah}
schema = {
'geometry': 'Polygon',
'properties': pro,
}
with fiona.open('four.shp', 'w', 'ESRI Shapefile', schema) as c, open("file_path", 'r', encoding='utf-8-sig') as f:
r = csv.DictReader(f)
for i in r:
grid = i['grid']
if grid == 'Guangzhou':
poly = gz
if grid == 'Chengdu_1':
poly = cd1
if grid == 'Chengdu_2':
poly = cd2
if grid == 'Kunming':
poly = km
c.write({
'geometry': mapping(poly),
'properties': {**i},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment