On 02/08/17 19:58, Ullah, Izhar wrote:
Hi,

I want to write a Jena rule which could deduce the fact that 'Sheep have found in the field'. To do this, I have got only geometries of sheep in the form of GPS coordinates like Point(longitude latitude) e.g. POINT(-3.783065 53.202158). Similarly, I have got the geometries of the field in the same format.

POINT can't be the geometry of a field it's a point. The answer to your problem will depend on what range of geometries you need to support.

My question is how can I match the sheep's geometries with that of field 
geometries and deduce the said fact. In SPARQL, I have done the same task 
through the following SPARQL Query with the help of GeoSPARQL functions and it 
runs succesfully:

If you already have a GeoSPARQL system then just use that, no point in rewriting into Jena Rules.

Query: Are sheep found in the field?

ASK WHERE {

        ?sheep rdf:type enviot:SheepNodeOutput ;
             geosparql:hasGeometry ?sgeo.
         ?sgeo geosparql:asWKT ?swkt.

         ?feature rdf:type enviot:Field;
     geosparql:hasGeometry ?fgeo.
         ?fgeo geosparql:asWKT ?fwkt.

     FILTER(geof:sfIntersects(?swkt, ?fwkt))

    }

By the way, my jsonld data borrows/uses the vocabulary from my ontology which 
uses the GeoSPARQL Ontology as well.

Can someone please give their thoughts/ideas about this issue/challenge? There 
is a built-in primitive in Jena i.e. equal(?x, ?y) but I don't know whether it 
works for comparing geo coordinates like Point(long lat) or not.

In the unlikely case that your fields are just rectangles aligned north-south/east-west. And if you have raw coordinates in your data not just WKT literals then you just compare the lat and long values between the sheep and the left/right and top/bottom field boundaries.

In all other cases you would need a GIS library to decode the WKT literals and to compute the intersection of a point with your polygons. The common one is GeoTools (note LGPL) which you could either just use or, if you really need to do this in Jena rules, then you could create some builtins to do this which call out to GeoTools.

Dave

Reply via email to