Created
May 9, 2014 19:49
-
-
Save oskar456/aaad7bc4b5f4508cf12f to your computer and use it in GitHub Desktop.
KML bounding box
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
#!/usr/bin/env python3 | |
import lxml.etree | |
tree = lxml.etree.parse('pl.kml') | |
root = tree.getroot() | |
ns= 'http://earth.google.com/kml/2.1' | |
pmarks = tree.findall('//{{{0}}}Placemark'.format(ns)) | |
for pmark in pmarks: | |
coor= pmark.find('{{{0}}}Point/{{{0}}}coordinates'.format(ns)) | |
long, lat, alt = (float(x) for x in coor.text.split(',',3)) | |
if long < 20.6 or long > 21.6 or lat < 52 or lat > 52.6: | |
pmark.getparent().remove(pmark) | |
tree.write('pl-warszawa.kml', pretty_print=True, encoding='utf-8', xml_declaration=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment