Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
47 lines (40 sloc) 1.04 KB
from sys import argv
import psycopg2
import random
from xml.sax import saxutils
conn = psycopg2.connect("dbname=%s user=postgres" % argv[1])
cur = conn.cursor()
COLOURS = ['ff0000', '00ff00', '0000ff', 'ffff00', 'ff00ff', '00ffff']
print '''<kml xmlns="">
<Style id="dot-icon">
# extract railway lines
SELECT ST_ASKML(linestring)
FROM paths
for (kml,) in cur:
print '<Placemark>%s<Style><LineStyle><width>2</width><color>ff%s</color></LineStyle></Style></Placemark>' % (kml, random.choice(COLOURS))
# extract stations with wgs84 lng/lat
SELECT name, ST_ASKML(geom)
FROM stations
for (name, kml) in cur:
print '<Placemark>'
if name:
print '<name>%s</name>' % saxutils.escape(name)
print '<styleUrl>#dot-icon</styleUrl>'
print kml
print '</Placemark>'
print '</Document>'
print '</kml>'