I have created a small ontology in which I have a Class called node. It has data properties associated with it has_latitude
and has_longitude
. I need to execute a query that given a lat, long input I should be able to find nodes within range of 20 meters. So wrote a query using harvesian formula. It works but the query looks really complex. Below is my query
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
PREFIX math: <http://www.w3.org/2005/xpath-functions/math#>
PREFIX leviathan: <http://www.dotnetrdf.org/leviathan#>
PREFIX afn: <http://jena.hpl.hp.com/ARQ/function#>
PREFIX openStreetMapWithData: <http://www.semanticweb.org/yogitas/ontologies/2017/2/openStreetMapWithData.owl#>
PREFIX ont: <http://www.co-ode.org/ontologies/ont.owl#>
PREFIX has_k_recycling: <http://www.semanticweb.org/yogitas/ontologies/2017/2/openStreetMapWithData.owl#
has_k_recycling:>
PREFIX tags: <https://raw.github.com/doroam/planning-do-roam/master/Ontology/tags.owl#>
PREFIX k_addr: <https://raw.github.com/doroam/planning-do-roam/master/Ontology/tags.owl#k_addr:>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX uom: <http://www.opengis.net/def/uom/OGC/1.0/>
select ?lat ?lon ?node ?way ?id
where {
?node openStreetMapWithData:node_has_latitude ?lat .
?node openStreetMapWithData:node_has_longitude ?lon .
filter (
6371 * 2 * math:asin(math:sqrt(
math:pow( math:sin((("48.4321094"^^xsd:double - ?lat)*math:pi()/180)/2),2)
+
math:cos("48.4321094"^^xsd:double * math:pi() /180) * math:cos(?lat * math:pi() / 180) * math:pow( math:sin(("10.0219117"^^xsd:double - ?lon)*math:pi()/180),2))) < 0.02 )
{?node openStreetMapWithData:node_has_id ?id .
?waynode openStreetMapWithData:waynode_has_reference_id ?id .
?way openStreetMapWithData:way_has_part ?waynode .
?waynode rdf:type openStreetMapWithData:way_node .
?way rdf:type openStreetMapWithData:way.}
}
I came across GeoSPARQL and found that it has function geo:distance()
which can be used for the same reason as what I am trying to do above. I am using it in below query to find distance of every node with given input point
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX uom: <http://www.opengis.net/def/uom/OGC/1.0/>
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
select ?node ?lat1 ?lon1
where {
?node1 openStreetMapWithData:node_has_latitude ?lat1 .
?node1 openStreetMapWithData:node_has_longitude ?lon1 .
BIND (geof:distance(?lat1,?lon1, "48.4332423"^^xsd:double, "10.0198943"^^xsd:double,uom:metre) as ?x)
}
It is not giving me any error but does not even give any value. What all changes do I need to do so as to GeoSPARQL? Do I need to make my node class as subClass of some class from GeoSPARQL or so? I could not find any documentation of how to use GeoSPARQL along with your own ontology.
Any help will be greatly appreciated! Thanks.