Created
July 2, 2019 11:24
-
-
Save ficapy/100021f84ae94bbdbe3d70671438a130 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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