- Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsubset.py
More file actions
Latest commit
20 lines (19 loc) · 667 Bytes
/
Copy pathsubset.py
File metadata and controls
20 lines (19 loc) · 667 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
importshapefile
# Create a reader instance
r=shapefile.Reader("buildingfootprints/Building_Footprint")
# Create a writer instance
w=shapefile.Writer(shapeType=shapefile.POLYGON)
# Copy the fields to the writer
w.fields=list(r.fields)
# Grab the geometry and records from all features
# with the correct county name
selection= []
forrecinenumerate(r.records()):
ifrec[1][1].startswith("Hancock"):
selection.append(rec)
# Add the geometry and records to the writer
forrecinselection:
w._shapes.append(r.shape(rec[0]))
w.records.append(rec[1])
# Save the new shapefile
w.save("buildingfootprints/HancockFootprints")