Convert GEO tagged RDF into KML

URL:

Tip: Multiple RDF documents can be merged by listing their URLs separated with a "," comma.

Works with vcard: (GoodRelations data!), geo: and georss:.

Try:

• Southampton University Locations: RDF | KML | Google Map
• Oxford University Locations: RDF | KML | Google Map
• W├╝rth Hochenburger (GoodRelations data) RDF | KML | Google Map
I need some more example data! Email me suggestions to cjg@ecs.soton.ac.uk

Drag this geo2kml bookmarklet to your bookmarks to create a quick button for sending your current URL to the geo2kml tool.

geo2kml is powered by Graphite and ARC2 and hosted by ECS at the University of Southampton.

<http://graphite.ecs.soton.ac.uk/rdf2geo/> foaf:maker <http://id.ecs.soton.ac.uk/person/1248> .
<http://id.ecs.soton.ac.uk/person/1248> foaf:name "Christopher Gutteridge" .
ns( "geo","http://www.w3.org/2003/01/geo/wgs84_pos#" ); $graph->ns( "vcard","http://www.w3.org/2006/vcard/ns#" ); $graph->ns( "gr", "http://purl.org/goodrelations/v1#" ); $graph->ns( "georss", "http://www.georss.org/georss" ); foreach( preg_split( "/\s*,\s*/", $uri ) as $auri ) { if( !$graph->load( $auri ) ) { print "Failed to load any triples from $auri. Sorry."; return; } } $doc = $graph->resource( $graph->firstGraphURI ); $desc = ""; $title = "Converted from RDF Document"; if( $doc->hasLabel() ) { $title = $doc->label()." ($title)"; } if( $doc->has("dc:description") ) { $desc.= $doc->get( "dc:description" )->toString()."\n\n"; } $desc .= 'Converted from '.$uri.' via http://graphite.ecs.soton.ac.uk/geo2kml/'; $kml = ""; $kml.= ' '.htmlspecialchars($title).' '.htmlspecialchars($desc).' '; $i=1; $objects = $graph->allSubjects(); $to_sort = array(); foreach( $objects as $thing ) { $title = $thing->toString(); if( $thing->hasLabel() ) { $title = $thing->label(); } elseif( $thing->has( "-gr:hasPOS" ) && $thing->get( "-gr:hasPOS" )->hasLabel() ) { $title = $thing->get( "-gr:hasPOS" )->label(); } $desc=''; $done = array(); foreach( $thing->all("foaf:homepage") as $url ) { if( @$done[$url->toString()] ) { continue; } $desc.="
Homepage
"; $done[$url->toString()] = true; } foreach( $thing->all("foaf:page") as $url ) { if( @$done[$url->toString()] ) { continue; } $desc.="
More Information
"; $done[$url->toString()] = true; } if( $thing->has( "dc:description", "dcterms:description" ) ) { $desc.= htmlspecialchars( $thing->getString( "dc:description" , "dcterms:description")); } $img = 'http://maps.gstatic.com/intl/en_ALL/mapfiles/ms/micons/blue-dot.png'; if ( $thing->has("http://data.totl.net/ns/icon") ) { $img = $thing->getString("http://data.totl.net/ns/icon"); } if ( $thing->has("http://purl.org/openorg/mapIcon") ) { $img = $thing->getString("http://purl.org/openorg/mapIcon"); } $img = htmlspecialchars($img); $title = htmlspecialchars( $title ); $placemark = ""; if( $thing->has( "dct:spatial" ) ) { $placemark = " $title (Polygon) $desc"; foreach( $thing->all( "dct:spatial" ) as $sp ) { $v = $sp->toString(); if( preg_match( '/POLYGON\s*\(\((.*)\)\)/', $v, $bits ) ) { $x = ""; if( @$_GET['height'] ) { $x = "1relativeToGround"; } $placemark.= " $x 1 "; $coords = preg_split( '/\s*,\s*/', trim( $bits[1] ) ); foreach( $coords as $coord ) { $point = preg_split( '/\s+/', $coord ); if(sizeof($point)==2) { if( @$_GET['height'] ) { $point []= $_GET['height']; } else { $point []= "0.000000"; } } $placemark.=join( ",",$point )."\n"; } $placemark.= " "; } } $placemark.= " #stylep$i "; $to_sort[$title." (Polygon)"][] = $placemark; ++$i; } $alt = "0.000000"; $lat = null; $long = null; if( $thing->has( "geo:lat" ) ) { $lat = $thing->getString( "geo:lat" ); } if( $thing->has( "geo:long" ) ) { $long = $thing->getString( "geo:long" ); } if( $thing->has( "geo:alt" ) ) { $alt = $thing->get( "geo:alt" ); } if( $thing->has( "vcard:geo" ) ) { $geo = $thing->get( "vcard:geo" ); if( $geo->has( "vcard:latitude" ) ) { $lat = $geo->getString( "vcard:latitude" ); } if( $geo->has( "vcard:longitude" ) ) { $long = $geo->getString( "vcard:longitude" ); } } if( $thing->has( "georss:point" ) ) { list($lat,$long) = preg_split( '/ /', trim( $thing->get("georss:point" )->toString() ) ); } if( isset( $lat ) && isset( $long ) ) { $placemark = " $title $desc #style$i $long,$lat,$alt "; ++$i; $to_sort[$title][] = $placemark; } } ksort( $to_sort ); foreach( $to_sort as $k=>$v ) { $kml.=join( "", $v ); } $kml.= "
\n"; if( @$_GET[""]=="kmz" ) { header( "application/vnd.google-earth.kmz" ); # don't know how to zip easily print $kml; return; } if( @$_GET["mode"]=="debug" ) { header( "Content-type: text/plain" ); print $kml; return; } header( "Content-type: application/vnd.google-earth.kml+xml"); print $kml; }