Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

GeoSparql request creation



The SparqlRequest class allows to create SPARQL requests easily without having to write the request "by hand".

See SPARQL request creation for information about crating general requests.

SparqlRequest API for GeoSparql requests

Examples

Geometry example

Suppose that we have an ontology with an Waypoint class. We want to create a request getting the list of Waypoints and their latitude and longitude.

We can do:
   SparqlRequest request = new SparqlRequest("sitac");
   request.addSelect("wpt");
   request.addSelect("lat");
   request.addSelect("lon");
   request.addType("wpt", "Waypoint");
   request.addGeometry("wpt", "lat", "lon", true);
   String query = request.getSPARQL();
We will generate the following query:
   SELECT ?wpt lat ?lon
   WHERE
   {
     ?wpt rdf:type sitac:Waypoint .
     ?wpt sitac:hasExactGeometry ?auto_1 .
     ?auto_1 sitac:asWKT ?auto_2 .
     BIND (xs:decimal(replace( str(?auto_2), "^[^0-9\\.-]*([-]?[0-9\\.]+) .*$", "$1" )) as ?lon)
     BIND (xs:decimal(replace( str(?auto_2), "^.* ([-]?[0-9\\.]+)[^0-9\\.]*$", "$1" )) as ?lat)   
   }      

Distance example

Now we also have an Aircraft individual, and we want to get the distance between each Waypoint and our Aircraft.

We can do:
   SparqlRequest request = new SparqlRequest("sitac");
   request.addSelect("wpt");
   request.addSelect("dist");
   request.addType("wpt", "Waypoint");      
   request.addAdditionalVariable("ac");
   request.addType("ac", "Aircraft");  
   request.addPropertyValue("ac", "Label", "MyAircraft");
   request.addDistance("wpt", "ac", "dist", SparqlRequest.DISTANCE_M, true);
   String query = request.getSPARQL();
   SELECT ?wpt ?dist
   WHERE {
     ?wpt rdf:type sitac:Waypoint .
     ?wpt sitac:hasExactGeometry ?auto_1 .
     ?auto_1 sitac:asWKT ?auto_2 . 
     ?ac rdf:type sitac:Aircraft .
     ?ac sitac:Label "MyAircraft" .       
     ?ac sitac:hasExactGeometry ?auto_3 .
     ?auto_3 sitac:asWKT ?auto_4 .                 
     BIND (geof:distance(?auto_2, ?auto_4, <http://www.opengis.net/def/uom/OGC/1.0/meter>) as ?dist)
  }

See also


Categories: Requestcreation

Copyright 2025 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v3 licence