I'm using GraphDB and the triple store is spatially indexed.
When I'm using this query, called Q1:
PREFIX geo-pos: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX omgeo: <http://www.ontotext.com/owlim/geo#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
select ?a ?lat ?long
WHERE {
?a omgeo:within(22.92 -142.38 75.23 183.69) .
?a geo-pos:lat ?lat .
?a geo-pos:long ?long .
} limit 5000
It only takes less than a second, omgeo:within(22.92 -142.38 75.23 183.69) is using the spatial index of the triple store.
Also, when I use this query, called Q2:
PREFIX geo-pos: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX omgeo: <http://www.ontotext.com/owlim/geo#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
select ?a ?lat ?long
WHERE {
?a a ?o .
filter(?o = someclass) .
?a geo-pos:long ?long .
} limit 5000
or this query, called Q3:
PREFIX geo-pos: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX omgeo: <http://www.ontotext.com/owlim/geo#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
select ?a ?lat ?long
WHERE {
?a a someclass .
?a geo-pos:lat ?lat .
?a geo-pos:long ?long .
} limit 5000
They return the same results and both take about 1 second.
But if I use this query, called Q4:
PREFIX geo-pos: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX omgeo: <http://www.ontotext.com/owlim/geo#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
select ?a ?lat ?long
WHERE {
?a omgeo:within(22.92 -142.38 75.23 183.69) .
?a a ?o .
filter(?o = someclass) .
?a geo-pos:lat ?lat .
?a geo-pos:long ?long .
} limit 5000
It takes more than 60 seconds. Do you know why this happens? Even if Q2 and Q3 returns 0 result, which means that the someclass I queried about has no instance, Q4 still takes more than 60 seconds. Is there a more efficient way to write Q4?
filter (?var = ...)is always a little suspect.values ?var { ... }may be better, since it's conceptually saying "use these values of this variable" whereas the filter says "get a bunch of solutions and then remove ones that don't match".a good engine should optimize this filter, but it's one area to look into, at least.