Created
October 29, 2013 19:00
-
-
Save perrygeo/7220600 to your computer and use it in GitHub Desktop.
Csv to Shapefile using arcpy
This file contains 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 | |
import arcpy | |
# empty shapefile must already exist, be of a point geometry type | |
# and have a BIOMASS attribute | |
cursor = arcpy.InsertCursor("try1.shp") | |
# assume a `data.csv` file like: | |
# y,x,biomass | |
# 61.4571,-148.7781,12 | |
# 62.7899,-142.583,13 | |
# 61.0742,-149.3066,14 | |
with open('data.csv', 'rb') as f: | |
reader = csv.DictReader(f) | |
for row in reader: | |
# Create the feature | |
feature = cursor.newRow() | |
# Add the point geometry to the feature | |
vertex = arcpy.CreateObject("Point") | |
vertex.X = row['x'] | |
vertex.Y = row['y'] | |
feature.shape = vertex | |
# Add attributes | |
feature.BIOMASS = row['biomass'] | |
# write to shapefile | |
cursor.insertRow(feature) | |
# clean up | |
del cursor |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment