Created
July 24, 2011 21:20
-
-
Save antoniogarrote/1103113 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function(){ | |
rdfstore.create(function(store) { | |
var myLocLat = 0; | |
var myLocLng = 0; | |
var nearbyRadius = 0.5; // in km | |
// extracts data from remote SPARQL endpoint | |
var queryStr2 = 'PREFIX lgdo:<http://linkedgeodata.org/ontology/>\ | |
CONSTRUCT {\ | |
?s a lgdo:Amenity .\ | |
?s rdfs:label ?l .\ | |
?s geo:geometry ?g }\ | |
FROM <http://linkedgeodata.org>\ | |
WHERE { ?s a lgdo:Amenity .\ | |
?s rdfs:label ?l .\ | |
?s geo:geometry ?g .\ | |
FILTER(bif:st_intersects (?g, bif:st_point (' + myLocLng + ',' + myLocLat + '), ' + nearbyRadius + ')) . }'; | |
var defaultGraph = 'http://linkedgeodata.org'; | |
// we request data in N3 format | |
var queryURLBase = 'http://live.linkedgeodata.org/sparql?default-graph-uri=' + encodeURIComponent(defaultGraph); | |
var format='&format=text%2Frdf%2Bn3'; | |
// queries local endpoint | |
var queryStr1 = 'PREFIX lgdo: <http://linkedgeodata.org/ontology/>\ | |
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>\ | |
PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#>\ | |
SELECT ?s ?l ?g \ | |
WHERE {\ | |
?s a lgdo:Amenity .\ | |
?s rdfs:label ?l . ?s geo:geometry ?g }'; | |
jQuery.get(queryURLBase + '&query=' + queryStr2 + format , function(data, textStatus){ | |
if(data) { | |
// we store the returned triples in the local default graph | |
store.load("text/n3",data,function(success) { | |
if(success) { | |
store.execute(queryStr1, function(success, results) { | |
// results have 5 bindings | |
alert("Found "+results.length); | |
}); | |
} | |
}); | |
} | |
}); | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment