Piatra Craiului mashup

A mashup of the OpenStreetMap hiking trails displayed in Google Earth:



I've initially experimented with displaying the actual OSM tiles over Google Earth (that automatically maps them using the terrain's altitude profile) but I obtained mixed results - for one, the tiles overlapped the satellite imagery displayed by GE and, most annoyingly, I didn't manage to find a way to correctly match GE's bounding box request to OSM's discrete zoom levels.
If you're interested in displaying the OSM tiles over GE, check out Markus Bader's OpenStreetMapLayer.kmz

I've instead displayed the vector version of the trails (linestrings and icons) using a Python script that extracts data from my local OSM Postgresql database. The script runs as a CGI and exports a bounding box worth of data to Google Earth using the KML NetworkLink feature.

Hacky code sample follows (builds the KML Placemarks for the OSM tourism points of interest):


def poisFromBBOX(east,west,south,north):
result = ""
conn = psycopg2.connect("dbname=...")
cur = conn.cursor()
stmt = cur.mogrify('select name,tourism, st_astext(transform(way, 4326)) from planet_osm_point where tourism is not null and st_contains(st_transform(ST_SetSRID(ST_MakeBox2D(ST_Point(%s, %s), ST_Point(%s, %s)), 4326), 900913), way)', (east, south, west, north))
cur.execute(stmt)
tl = cur.fetchall()
for item in tl:
name = item[0]
if name == None:
continue
tourism = item[1]
point = item[2]
m = re.search('(?<=POINT\()([0-9.]+) ([0-9.]+)', str(point))
result = result + '<Placemark><styleUrl>#myStyleMap</styleUrl><name>' + escape(str(name)) + '<description>OSM tourism: ' + escape(str(tourism)) + '</description><Point><coordinates>' + str(m.group(1)) + ',' + str(m.group(2)) + ',0</coordinates></Point></Placemark>'
cur.close()
conn.close()
return result