Skip to content

Instantly share code, notes, and snippets.

@oskar456
Created May 9, 2014 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oskar456/aaad7bc4b5f4508cf12f to your computer and use it in GitHub Desktop.
Save oskar456/aaad7bc4b5f4508cf12f to your computer and use it in GitHub Desktop.
KML bounding box
#!/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