Saturday, May 25, 2013

Semantic and GeoSPAQRL

I was looking for best practises in using geospatial queries in SPARQL and came across this .
OGC - OpenGeoSpatial Consortium has bought about standards in GeoSpatial queries and represention. For Semantics the suggested nechanism is using
GeoSPARQL queries. GeoSPARQL queries look like
The OGC GeoSPARQL standard supports representing and querying geospatial data on the Semantic Web. GeoSPARQL defines a vocabulary for representing geospatial data in RDF, and it defines an extension to the SPARQL query language for processing geospatial data.
http://www.w3.org/2001/sw/wiki/GeoSPARQL - W3C page for GeoSPARQL.There is also a jena based implementation available at
http://code.google.com/p/geospatialweb/
Sample use case are defined in - http://geosparql.org/
PREFIX co: <http://www.geonames.org/countries/#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> 
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>

SELECT ?link ?name ?pop  ?lat ?lon
WHERE  {
   ?link gs:within(40.157623 -74.855347 41.077281 -73.586426) .  
   ?link gn:name ?name .  
   ?link gn:population ?pop  .
   ?link geo:lat ?lat .
   ?link geo:long ?lon
}

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>  
SELECT ?link ?label ?pop  
WHERE  {   
   ?city gn:name "Bristol" .  
   ?link gs:nearby(?city 30) .  
   ?link gn:name ?label .  
   ?link gn:population ?pop  
   FILTER ( xsd:int(?pop) < 50000)
}
I was looking for a bigdatatm based implementation . However i could not find a native implementation . But i came across useekm a plugin
being developed under opensahara. But using them i have to sacrifice the bigdatatm stack and should use Sail based approach. I was not willing for this
because i was already using NanoSPARQL server for my queries for scalaility. In their case they have implemented a IndexingSail indexer separatly for
improving the performance of GeoSPARQL server. This was done on the SAIL layer and when geosparql data is added they create the extra index. This could improve
the performance. but i was alittle confused.

So i raised to them in forum - And decided to do some tweaks and make use of useekm Geosparql implementation natively in bigdatatm . As my queries where mainly like
?link gs:nearby(?city 30) . Then I started out with getting the src of useekm and finding how they added them to bigdatatm They made use of customFunction in bigdata for
the extra function intergration. When i furthur looked into the implementation i found that the subjects need to be
http://www.opengis.net/ont/geosparql# More details are present in https://dev.opensahara.com/projects/useekm/wiki/IndexingSail.
Sample query supported in useekm
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
SELECT DISTINCT ?result WHERE {
  ?result <http://example.org/geometry> ?geometry.
  FILTER(geof:sfWithin(?geometry, "POLYGON((0 0, 0 1, 2 1, 1 0, 0 0))"^^geo:wktLiteral))
}
Deatils about the supported function in useekm - https://dev.opensahara.com/projects/useekm/wiki/GeoReference .
Internaly in useekm they use - http://www.vividsolutions.com/JTS/JTSHome.htm for doing all spatial computations.