-
Notifications
You must be signed in to change notification settings - Fork 1
/
shape.py
28 lines (25 loc) · 828 Bytes
/
shape.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from osgeo import ogr
import os
import sys
def save(shapePath, feature):
'Save points in the given shapePath'
# Get driver
driver = ogr.GetDriverByName('ESRI Shapefile')
# Create shapeData
if os.path.exists(shapePath):
os.remove(shapePath)
shapeData = driver.CreateDataSource(shapePath)
# Create spatialReference
spatialReference = layer.GetSpatialRef()
# Create layer
layerName = shapePath
newlayer = shapeData.CreateLayer(layerName, spatialReference, ogr.wkbPolygon)
newlayer.CreateFeature(feature)
shapeData.Destroy()
shapefile = ogr.Open("counties/counties.shp")
layer = shapefile.GetLayer(0)
for i in range(layer.GetFeatureCount()):
feature = layer.GetFeature(i)
name = feature.GetField("GEOID")
if name == sys.argv[1]:
save(name, feature)