SPARQLing the Highest Point in Every State


In a previous post, I mentioned that it should be pretty easy to use SPARQL to make a map of the highest point in each of the 50 US States. Having written that, I thought I should maybe actually, you know, try it.

The following chunk of code uses ARC2, an rdf/semantic web library for PHP to query the dbpedia endpoint and then put the results on a Google Map.

To try this out, you need to:

  1. Have a functional PHP installation
  2. Download ARC2 into your web path (no setup required)
  3. Set the path to ARC in the code below
  4. Get a Google Maps API Key (free)
  5. Set your API key in the code below
  6. Run
Note that this is a demo and is written to be easy to run - a real application might separate the data logic from the webpage and make more sophisticated use of Javascript/Google Maps API.

//include ARC2 libraries

//instantiate a RemoteStore
$config = array('remote_store_endpoint' => '');
$store = ARC2::getRemoteStore($config);

//build the SPARQL query
$q = '
    PREFIX dbpedia2: <>
    PREFIX skos: <>
    PREFIX geo: <>
    SELECT ?state ?mtn ?lat ?long
    WHERE {
        ?state skos:subject <> .
        ?state dbpedia2:highestpoint ?mtn .
        ?mtn geo:lat ?lat .
        ?mtn geo:long ?long

//process the results
$results = array();
if ($rows = $store->query($q, 'rows')) {
    foreach ($rows as $row) {
        $state = substr($row['state'], strlen(""));
        $mtn = substr($row['mtn'], strlen(""));
        $lat = $row['lat'];
        $lng = $row['long'];
        $results[] = array($state, $mtn, $lat, $lng);
<!DOCTYPE html "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<html xmlns="">
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Google Maps JavaScript API Example</title>
    <script type="text/javascript" src=""></script>
    <script type="text/javascript">
    function initialize() {
        if (GBrowserIsCompatible()) {
            var map = new GMap2(document.getElementById("map_canvas"));
            map.setCenter(new GLatLng(37.4419, -122.1419), 3);
            map.addControl(new GMapTypeControl());
            map.addControl(new GLargeMapControl());
                //populate map with results
                foreach($results as $result) {
                    list($state, $mtn, $lat, $lng) = $result;
                    echo("map.addOverlay(new GMarker(new GLatLng($lat,$lng), {title: '$mtn'}));n");
<body onload="initialize()" onunload="GUnload()">
    <div id="map_canvas" style="width: 100%; height: 100%"></div>