Reputation: 45
I'm querying the Wikidata from Apache Jena Fuseki. The objective is to get a monument by its coordinates. The coordinates I locally have are far more accurate. For instance, the monument Q29566893 in Wikidata has the coordinates Point(-3.688916 40.409635), whereas from my data source they are -3.6889160981994342 and 40.40963497841015. The basic query is more or less like this:
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?monumento ?coordenadas ?autor ?tipo
WHERE {
SERVICE <https://query.wikidata.org/sparql> {
?monumento wdt:P31 ?tipo;
wdt:P131 wd:Q2807. # Location, we know for sure the city. This can be deleted
VALUES ?tipo { wd:Q4989906 wd:Q179700 } # Filter by monument and statue
OPTIONAL { ?monumento wdt:P625 ?coordenadas. } # Coordinates (optional)
OPTIONAL { ?monumento wdt:P84 ?autor. } # Author or architect (optional)
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],es". }
}
}
Giving the fact that I already have the coordinates, shouldn't be needed any fancy geospatial query, and anyway GeoSPARQL can't be used because the data is not stored locally. Perhaps is enough to get the latitude and longitude from the pair Point(long, lat) that Wikidata provides, subtract the local coordinate, get the absolute value from the result and check the precision, like this:
FILTER(ABS(?latitud - 40.40963497841015) < 0.001
But how to achieve this with SPARQL and Wikidata?
Upvotes: 2
Views: 51