Created
October 22, 2013 02:43
-
-
Save nickjevershed/7094418 to your computer and use it in GitHub Desktop.
Gets latest polygons of fires from RFS site, converts to KML for mapping
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
#NOTE: please do not DDoS the RFS site with a bunch of automated queries | |
import lxml.etree | |
import simplekml | |
import urllib2 | |
import datetime | |
kml = simplekml.Kml() | |
date_string = datetime.datetime.now().strftime("%d-%m-%Y-%H-%M") | |
#open latest feed | |
fires = urllib2.urlopen('http://www.rfs.nsw.gov.au/feeds/majorIncidents.xml').read() | |
#parse xml and convert each polygon to own kml object | |
parser = lxml.etree.XMLParser(recover=True) | |
root = lxml.etree.XML(fires, parser) | |
items = root.findall('.//item') | |
for item in items: | |
print item.find('title').text | |
try: | |
polygons = item.findall('{*}polygon') | |
for i, polygon in enumerate(polygons): | |
print i | |
polygon = polygon.text.split(' ') | |
evens = polygon[0:][::2] | |
odds = polygon[1:][::2] | |
coords = zip(odds, evens) | |
print coords | |
pol = kml.newpolygon(name=item.find('title').text) | |
pol.outerboundaryis = coords | |
except: | |
print "No polygon" | |
#save kml with timestamp | |
kml.save("fires-poly" + date_string + ".kml") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment