This is companion code to this guide.
Created
October 31, 2012 15:00
-
-
Save tmcw/3987512 to your computer and use it in GitHub Desktop.
GIS with Python, Shapely, and Fiona Example 1 - CSV Files
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
import csv | |
from shapely.geometry import Point, mapping | |
from fiona import collection | |
schema = { 'geometry': 'Point', 'properties': { 'name': 'str' } } | |
with collection( | |
"some.shp", "w", "ESRI Shapefile", schema) as output: | |
with open('some.csv', 'rb') as f: | |
reader = csv.DictReader(f) | |
for row in reader: | |
point = Point(float(row['lon']), float(row['lat'])) | |
output.write({ | |
'properties': { | |
'name': row['name'] | |
}, | |
'geometry': mapping(point) | |
}) |
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
name | lat | lon | |
---|---|---|---|
Chicago | 41.88 | -87.63 | |
Kansas City | 39.101 | -94.584 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how you create the map of usa ?