I am using sparql in a spring boot project.
I created a query that will calculate the distance and then filter if the distance is less than x.
However, I have a very long processing time (around 2 seconds, sometimes +). On my computer I have 32GB of ram, on my production server much less (1GB of ram), but the time is always the same.
query1
PREFIX (...)
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
prefix sf: <http://www.opengis.net/ont/sf>
PREFIX uom: <http://www.opengis.net/def/uom/OGC/1.0/>
SELECT
?url ?contactUri ?email ?id ?descri_courte ?geo ?lon ?lat ?x ?geom ?lattype ?wkt ?xr ?longitude
WHERE {
?url :isLocatedAt ?place.
?place schema:geo ?geo.## ?place a pour coordonnées géographiques ?geo
?geo schema:longitude ?longitude; ## ?geo a pour longitude ?longitude
schema:latitude ?latitude.
BIND (STRDT(CONCAT("POINT(",str(?longitude), " ", str(?latitude), ")"),geo:wktLiteral) as ?wkt)
BIND (STRDT(CONCAT("POINT(",str(10.9999), " ", str(52.9999), ")"),geo:wktLiteral) as ?wp2)
BIND (geof:distance(?wkt, ?wp2,uom:metre) as ?xr)
FILTER(?xr < 2000)
?url <https://www.datatourisme.gouv.fr/ontology/core#hasContact> ?contactUri.
?contactUri a <https://www.datatourisme.gouv.fr/ontology/core#Agent>.
optional {
?contactUri schema:email ?email.
}
?url dc:identifier ?id.
Optional { ?url rdfs:label ?descri_courte }
Optional { ?place schema:geo ?geo }
Optional { ?geo schema:longitude ?lon; schema:latitude ?lat. }
Optional {?geo rdf:type ?lattype}
Optional {?geo <https://www.datatourisme.gouv.fr/ontology/core#latlon> ?x. }
}
on the other hand, to make a count, the processing time is clearly faster
query2:
PREFIX (...)
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
prefix sf: <http://www.opengis.net/ont/sf>
PREFIX uom: <http://www.opengis.net/def/uom/OGC/1.0/>
SELECT
(count(*) as ?resultat)
WHERE {
?url :isLocatedAt ?place.
?place schema:geo ?geo.## ?place a pour coordonnées géographiques ?geo
?geo schema:longitude ?longitude; ## ?geo a pour longitude ?longitude
schema:latitude ?latitude.
BIND (STRDT(CONCAT("POINT(",str(?longitude), " ", str(?latitude), ")"),geo:wktLiteral) as ?wkt)
BIND (STRDT(CONCAT("POINT(",str(10.9999), " ", str(52.9999), ")"),geo:wktLiteral) as ?wp2)
BIND (geof:distance(?wkt, ?wp2,uom:metre) as ?xr)
FILTER(?xr < 2000)
}
I use Jena. I have already tried to shorten query 1 but I feel the processing time does not change ... could you please help me improve the performance of my query1?
thanking you