Skip to content

Instantly share code, notes, and snippets.

@nickjevershed
Created October 22, 2013 02:43
Show Gist options
  • Save nickjevershed/7094418 to your computer and use it in GitHub Desktop.
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
#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