Using GeoSpatial nearby feature

Hi,

I am trying to use the Stardog GeoSpatial nearby feature. My use case is that I have to retrieve latitude and longitude for a number of different locations and should pass them as parameters to the nearby function to find nearby places, such in the following query:

PREFIX : http://api.stardog.com/
PREFIX owl: http://www.w3.org/2002/07/owl#
PREFIX rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
PREFIX rdfs: http://www.w3.org/2000/01/rdf-schema#
PREFIX stardog: tag:stardog:api:
PREFIX xsd: http://www.w3.org/2001/XMLSchema#
prefix wgs84_pos: http://www.w3.org/2003/01/geo/wgs84_pos#
prefix geo: http://www.opengis.net/ont/geosparql#
prefix geof: http://www.opengis.net/def/function/geosparql/
prefix unit: http://qudt.org/vocab/unit#

select * {

GRAPH <graph1> {

?place a :Place;
wgs84_pos:lat ?lat;
wgs84_pos:long ?long.

    ?s  
           geof:nearby (?lat ?long 22 unit:Kilometer);
           wgs84_pos:lat ?pp_lat;
           wgs84_pos:long ?pp_long.   
 }

}

After running the above query, I am getting the error:

Caused by: java.lang.IllegalStateException: Latitude must be a double value between -90 & 90

I also tried the following ways, including binding latitude and longitude directly, e.g.

     BIND(xsd:float("50.173588") AS ?lat).
     BIND(xsd:float("12.12583") AS ?long).

:

PREFIX : http://api.stardog.com/
PREFIX owl: http://www.w3.org/2002/07/owl#
PREFIX rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
PREFIX rdfs: http://www.w3.org/2000/01/rdf-schema#
PREFIX stardog: tag:stardog:api:
PREFIX xsd: http://www.w3.org/2001/XMLSchema#
prefix wgs84_pos: http://www.w3.org/2003/01/geo/wgs84_pos#
prefix geo: http://www.opengis.net/ont/geosparql#
prefix geof: http://www.opengis.net/def/function/geosparql/
prefix unit: http://qudt.org/vocab/unit#

select * {

GRAPH <graph1> {
?place a :Place;
wgs84_pos:lat ?lat;
wgs84_pos:long ?long.
BIND(strdt(concat('Point(', STR(?long), ' ', STR(?lat), ')' ), geo:wktLiteral) as ?location)
?s
geof:nearby (?location 22 unit:Kilometer);
wgs84_pos:lat ?poi_lat;
wgs84_pos:long ?poi_long.
}
}

The above query does not return any result.

The queries that are returning results, but are only for a particular point, i.e. latitude and longitude, respectively, are:

PREFIX : http://api.stardog.com/
PREFIX owl: http://www.w3.org/2002/07/owl#
PREFIX rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
PREFIX rdfs: http://www.w3.org/2000/01/rdf-schema#
PREFIX stardog: tag:stardog:api:
PREFIX xsd: http://www.w3.org/2001/XMLSchema#
prefix wgs84_pos: http://www.w3.org/2003/01/geo/wgs84_pos#
prefix geo: http://www.opengis.net/ont/geosparql#
prefix geof: http://www.opengis.net/def/function/geosparql/
prefix unit: http://qudt.org/vocab/unit#

select * {

GRAPH <graph1> {
?s
geof:nearby ("Point(12.12583 50.173588 )"^^geo:wktLiteral 22 unit:Kilometer);
wgs84_pos:lat ?poi_lat;
wgs84_pos:long ?poi_long.
}
}

and (note the switching between longitude and latitude):

PREFIX : http://api.stardog.com/
PREFIX owl: http://www.w3.org/2002/07/owl#
PREFIX rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
PREFIX rdfs: http://www.w3.org/2000/01/rdf-schema#
PREFIX stardog: tag:stardog:api:
PREFIX xsd: http://www.w3.org/2001/XMLSchema#
prefix wgs84_pos: http://www.w3.org/2003/01/geo/wgs84_pos#
prefix geo: http://www.opengis.net/ont/geosparql#
prefix geof: http://www.opengis.net/def/function/geosparql/
prefix unit: http://qudt.org/vocab/unit#

select * {

GRAPH <graph1> {
?s
geof:nearby (50.173588 12.12583 22 unit:Kilometer);
wgs84_pos:lat ?poi_lat;
wgs84_pos:long ?poi_long.
}
}

I imagine, I am doing something wrong.

Best,

Hi,

any idea on this?

Best,

Do you have spatial.enabled=true on your database? If so and this still isn't working correctly, could you share a minimal data set that we can run this query on to reproduce?

Yes, the spatial.enabled=true is already set, since I am able to use the nearby feature when passing static values.

Here is an example:

@prefix : <http://api.stardog.com/> .
@prefix geo: <http://www.opengis.net/ont/geosparql#> .
@prefix unit: <http://qudt.org/vocab/unit#> .
@prefix geof: <http://www.opengis.net/def/function/geosparql/> .
@prefix wgs84_pos: <http://www.w3.org/2003/01/geo/wgs84_pos#> .

<http://example.com#512fab7de4b00f42967fd020> wgs84_pos:lat "50.173737"^^<http://www.w3.org/2001/XMLSchema#float> ;
wgs84_pos:long "12.128104"^^<http://www.w3.org/2001/XMLSchema#float> .

<http://example.com#513a218de4b08d57cd897e1f>
wgs84_pos:lat "50.173588"^^<http://www.w3.org/2001/XMLSchema#float> ;
wgs84_pos:long "12.12583"^^<http://www.w3.org/2001/XMLSchema#float> .

<http://example.com#5194a048498eeaa61aff2467>
wgs84_pos:lat "50.163685"^^<http://www.w3.org/2001/XMLSchema#float> ;
wgs84_pos:long "12.133927"^^<http://www.w3.org/2001/XMLSchema#float> .

<http://example.com#5283698611d281aae780e010>
wgs84_pos:lat "50.162033"^^<http://www.w3.org/2001/XMLSchema#float> ;
wgs84_pos:long "12.136862"^^<http://www.w3.org/2001/XMLSchema#float> .

<http://example.com#4c57f70f12f0d13adf3208ad>
wgs84_pos:lat "50.177277"^^<http://www.w3.org/2001/XMLSchema#float> ;
wgs84_pos:long "12.137034"^^<http://www.w3.org/2001/XMLSchema#float> .

<http://example.com#4caf305ddb32f04dea39b54d>
wgs84_pos:lat "50.17106"^^<http://www.w3.org/2001/XMLSchema#float> ;
wgs84_pos:long "12.125232"^^<http://www.w3.org/2001/XMLSchema#float> .

<http://example.com#4de005aa8877aab7fe3fd8d1>
wgs84_pos:lat "50.16986"^^<http://www.w3.org/2001/XMLSchema#float> ;
wgs84_pos:long "12.129593"^^<http://www.w3.org/2001/XMLSchema#float> .

<http://example.com#4fdf1c9ae4b08aca4a285b9f>
wgs84_pos:lat "50.171318"^^<http://www.w3.org/2001/XMLSchema#float> ;
wgs84_pos:long "12.131139"^^<http://www.w3.org/2001/XMLSchema#float> .

<http://example.com#5040e589e4b0f300413e2cba>
wgs84_pos:lat "50.176285"^^<http://www.w3.org/2001/XMLSchema#float> ;
wgs84_pos:long "12.13285"^^<http://www.w3.org/2001/XMLSchema#float> .

<http://example.com#5087a8c8e4b089a9f01b1a5e>
wgs84_pos:lat "50.17568"^^<http://www.w3.org/2001/XMLSchema#float> ;
wgs84_pos:long "12.116262"^^<http://www.w3.org/2001/XMLSchema#float> .

<http://example.com#50f5d5d9e4b03e61710cc0d3>
wgs84_pos:lat "50.164627"^^<http://www.w3.org/2001/XMLSchema#float> ;
wgs84_pos:long "12.137802"^^<http://www.w3.org/2001/XMLSchema#float> .

<http://example.com#510b7308e4b0428ec8a7c3c8>
wgs84_pos:lat "50.17561"^^<http://www.w3.org/2001/XMLSchema#float> ;
wgs84_pos:long "12.136623"^^<http://www.w3.org/2001/XMLSchema#float> .

<http://example.com#504d82dbe4b0f7c8cf947745>
wgs84_pos:lat "50.1665"^^<http://www.w3.org/2001/XMLSchema#float> ;
wgs84_pos:long "12.147203"^^<http://www.w3.org/2001/XMLSchema#float> .

<http://example.com#50d335713d7c145df3e86a29>
wgs84_pos:lat "50.167995"^^<http://www.w3.org/2001/XMLSchema#float> ;
wgs84_pos:long "12.12033"^^<http://www.w3.org/2001/XMLSchema#float> .

<http://example.com#511ac86ba629ec8f68cf493c>
wgs84_pos:lat "50.173923"^^<http://www.w3.org/2001/XMLSchema#float> ;
wgs84_pos:long "12.126574"^^<http://www.w3.org/2001/XMLSchema#float> .

Hi,

I have been using with success the nearby function but I have included Geometry instances instead of separate lat and long properties. The Geometry instances have the lat and long properties however.

In the following query, I am getting Geometry instances that are 5 km or less from a chosen Geometry.

select ?prop1Addr ?prop2Addr ?distance
where {
values(?geom1) {(http://www.domain.com/PropertyGeom/ee48fa00c63952a8a48d8e66540aa695)}
?geom1 wgs:lat ?prop1Lat; wgs:long ?prop1Long .
?geom2 geof:nearby (?geom1 5 unit:Kilometer) .
filter (?geom1 != ?geom2)
?prop1 geo:hasGeometry ?geom1; onto:Property-streetAddress ?prop1Addr .
?prop2 geo:hasGeometry ?geom2; onto:Property-streetAddress ?prop2Addr .
bind(geof:distance(?geom1, ?geom2, unit:Meter) as ?distance)
}
order by ?distance

Hi Daniel,

good to know that, thank you for your hint.

I also tried with binding the location as goe:wktLiteral e.g. BIND(strdt(concat('Point(', STR(?long), ' ', STR(?lat), ')' ), geo:wktLiteral) as ?location) , and passing as a parameter, as it shown in the second query above, unfortunately didn't work.

The following query is working fine (after associating ?place with type of :Location), which basically I can adopt for my use case, although the issue with passing directly latitude and longitude remains.

PREFIX : <http://api.stardog.com/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX stardog: <tag:stardog:api:>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
prefix wgs84_pos: <http://www.w3.org/2003/01/geo/wgs84_pos#>
prefix geo: <http://www.opengis.net/ont/geosparql#>
prefix geof: <http://www.opengis.net/def/function/geosparql/>
prefix unit: <http://qudt.org/vocab/unit#>

select * {

GRAPH  <graph1>  {
?place a ?type;
          wgs84_pos:lat ?lat;
          wgs84_pos:long ?long.
          geof:nearby (50.173588 12.12583 2 unit:Kilometer) .
?s
     geof:nearby (?place 2 unit:Kilometer);
     wgs84_pos:lat ?poi_lat;
    wgs84_pos:long ?poi_long.
  }
}

There is a mistake that I was doing, such as the following query:

PREFIX : <http://api.stardog.com/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX stardog: <tag:stardog:api:>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
prefix wgs84_pos: <http://www.w3.org/2003/01/geo/wgs84_pos#>
prefix geo: <http://www.opengis.net/ont/geosparql#>
prefix geof: <http://www.opengis.net/def/function/geosparql/>
prefix unit: <http://qudt.org/vocab/unit#>

select * {

GRAPH  <graph1>  {
?place 
          wgs84_pos:lat ?lat;
          wgs84_pos:long ?long.
          geof:nearby (50.173588 12.12583 2 unit:Kilometer) .
?s
     geof:nearby (?place 2 unit:Kilometer);
     wgs84_pos:lat ?poi_lat;
    wgs84_pos:long ?poi_long.
  }
}

Note the differences between two queries, in the second one, the clause a ?type is missing after the ?place variable, which causes only latitude and longitude to be retrieved.

Thank you for your support.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.