Geospatial Nearby

Not sure if there is a bug ... But I have a list of ports and their lats/longs. I ran the following query:

prefix geof: <http://www.opengis.net/def/function/geosparql/>
prefix geo: <http://www.opengis.net/ont/geosparql#>
prefix unit: <http://qudt.org/vocab/unit#>
prefix wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#> 
SELECT ?name ?lat ?long  {
  ?port a geo:Geometry ; 
        # geof:nearby ("Point(9.933333, 53.550000)"^^geo:wktLiteral 1000 unit:Kilometer) ;
        rdfs:label ?name ;
        wgs:lat ?lat ;
        wgs:long ?long }

And get lots of results. All of the prefixes are defined. The datatype of the ?lat and ?long variables is xsd:decimal.

However, if I remove the comment in front of geof:nearby, then I get an error:

WARN  2020-06-08 13:20:49,765 [stardog-user-8] com.complexible.stardog.protocols.http.server.StardogUndertowErrorHandler:accept(64): Unexpected exception was handled by the server
java.text.ParseException: Expected a number
	at org.locationtech.spatial4j.io.WKTReader$State.nextDouble(WKTReader.java:507) ~[spatial4j-0.7.jar:?]
	at org.locationtech.spatial4j.io.WKTReader.point(WKTReader.java:401) ~[spatial4j-0.7.jar:?]
	at org.locationtech.spatial4j.io.WKTReader.parsePointShape(WKTReader.java:213) ~[spatial4j-0.7.jar:?]
	at org.locationtech.spatial4j.io.WKTReader.parseShapeByType(WKTReader.java:156) ~[spatial4j-0.7.jar:?]
	at org.locationtech.spatial4j.io.WKTReader.parseIfSupported(WKTReader.java:110) ~[spatial4j-0.7.jar:?]
	at org.locationtech.spatial4j.io.WKTReader.parse(WKTReader.java:81) ~[spatial4j-0.7.jar:?]
	at org.locationtech.spatial4j.context.SpatialContext.readShapeFromWkt(SpatialContext.java:258) ~[spatial4j-0.7.jar:?]
	at com.complexible.stardog.spatial.db.query.NearbyPropertyFunction$NearbyOperator.getLocation(NearbyPropertyFunction.java:366) ~[stardog-spatial-core-7.3.1-SNAPSHOT-20200527.jar:?]
...

What is "not a number"?

Andrea

Hi Andrea,

geof:nearby is expecting either a Geometry or a latitude as the first argument. So in this case it's finding a Literal and therefore expecting a number.

To get the results you're looking for, try geof:nearby (9.933333 53.550000 1000 unit:Kilometer) ;

I tried geof:nearby (53.550000 9.933333 1000 unit:Kilometer) ; (lat comes first)

but get no results, which is why I tried using the wktLiteral approach.

If I comment out the geof:nearby, I get all the details back.

Andrea

And, yes, geospatial is enabled on the db.

Andrea

You read my mind!

WKT is fun to deal with, because Point actually accepts (LONG LAT) instead of the way we generally think about it. If you switch the 2 numbers do you see results then?

No. I just updated my reply to indicate that.

Andrea

Can you share a toy dataset that should be producing results?

Trying to create one.

Andrea

I have attached a small file that is a subset of data from NGA's World Port Index.

testNGA.ttl (11.2 KB)

Here is the query that works if geof:nearby is commented out:

prefix geo: <http://www.opengis.net/ont/geosparql#>
prefix unit: <http://qudt.org/vocab/unit#>
prefix wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#> 
prefix : <urn:example:ontology:> 

SELECT ?name ?lat ?long where {
  ?port 
        geof:nearby (53.550000 9.933333 1000 unit:Kilometer) ;
        :label ?name ;
        wgs:lat ?lat ;
        wgs:long ?long .
}

I am running 7.3.1.

Andrea

Hang on ... The query is wrong for the test data. It should have been geof:nearby (64.15 -21.93 1000 unit:Kilometer) ;

I got it to work with the test data. But the difference is that I had reasoning on to get the wgs:lat/long in the first case (from :lat ?lat and :long ?long), but hard-coded it into my data in the sample.

Would that have changed the results?
Andrea

You very well might need wgs:lat and wgs:long explicitly in the database in order to get the Geometry into the spatial index. In fact, I think you do...

I do. Reasoning did not work.

Next question .... How can I get distance to work ... If I do:

prefix geosparql: <http://www.opengis.net/ont/geosparql#>
prefix unit: <http://qudt.org/vocab/unit#>
prefix wgs: <http://www.w3.org/2003/01/geo/wgs84_pos#> 
prefix : <urn:example:ontology:> 

SELECT ?name ?lat ?long ?distance where {
  ?port a geosparql:Geometry ;
        geof:nearby (53.550000 9.933333 50 unit:Kilometer) ;
        :label ?name ;
        wgs:lat ?lat ;
        wgs:long ?long .
  BIND(geof:distance(?port, (53.550000 9.933333), unit:Kilometer) as ?distance)
}

I get the error:

com.complexible.stardog.plan.eval.ExecutionException: Encountered " <DECIMAL> "9.933333 "" at line 13, column 40.
Was expecting one of:
    ")" ...
    "=" ...
    "!=" ...
...

Thanks.
Andrea

Never mind ... I got this to work ...

BIND(geof:distance(?port, ("Point(9.933333 53.55)"^^geosparql:wktLiteral), unit:Kilometer) as ?distance)

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