Last active
September 1, 2016 10:31
-
-
Save alexsparrow/1d84c422e6bda27501955a9479b9396e 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 fastkml import kml | |
k = kml.KML() | |
k.from_string(open("data/48cb6f8ca308484097e6ed4720b27faa_1.kml").read()) | |
# This map will be a dict of borough name -> shapely geometry | |
map = {} | |
doc = list(k.features())[0] | |
for folder in doc.features(): | |
for placemark in folder.features(): | |
# In my KML file, the name of the boundary is in the ExtendedData section | |
# Irritatingly this wasn't exposed as a dict so I am building one here | |
attr = {} | |
for d in placemark.extended_data.elements[0].data: | |
attr[d["name"]] = d["value"] | |
# The KML file I used has this attribute for the borough name | |
map[attr["CTYUA15NM"]] = placemark.geometry |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment