Geof:distance between two geo:asWKT returns no value

As the topic describes, I have been trying to find the distance between two points as geo:wktLiterals.
I attached the data that is being used for this example.

export(1).trig (1.8 KB)

The query in question:

# GeoDistance
prefix ew: <tag:ew#>
prefix geof: <>
prefix unit: <>
prefix geo: <>

select ?wkt1 ?wkt2 (geof:distance(?wkt1, ?wkt2, unit:Yard) as ?d)where {
	    graph <tag:ew#Signal-sig-1> {
          ?r1 a ew:Reading .
          ?r1 geo:hasGeometry ?geo1 .
          ?geo1 geo:asWKT ?wkt1 .
          ?r2 a ew:Reading .
          ?r2 geo:hasGeometry ?geo2 .
          ?geo2 geo:asWKT ?wkt2

I based the data types and assignments based off the geospatial primer. If remove the distance function from the select statement I will get back the points as expected, and this can be viewed in the attached file. As simple as this query should be, the result I get back from the final query returns no value.

No errors show when executing the query and I have checked that the database's spacial indexing is on. I am hoping there is a detail I missed. The help is appreciated!


Are there any errors or warnings in Stardog.log?

When I attempt to load your exported data, I do see some spatial errors in the logs:

WARN  2018-10-03 07:35:21,857 [stardog-user-29] Failed to parse unknown/malformed shape Point(34.305848 -116.14475): Bad Y value -116.14475 is not in boundary Rect(minX=-180.0,maxX=180.0,minY=-90.0,maxY=90.0)
WARN  2018-10-03 07:35:21,858 [stardog-user-29] Failed to parse unknown/malformed shape Point(34.306891 -116.144696): Bad Y value -116.144696 is not in boundary Rect(minX=-180.0,maxX=180.0,minY=-90.0,maxY=90.0)

It looks like you created your points in the (more sensical, IMO) Point(LAT, LONG) notation, where the spec actually calls for Point(LONG, LAT). That's issue #1.

Issue #2 is that the geof:distance function seems to need a Geometry object where it's supposed to accept WKT Literals too. If you pass ?geo1 and ?geo2 in, you will see bound results. I will investigate this behavior further...

There was no warnings in the log for studio
Here is the updated trig with the LONG LAT Points fixed. So this should remove those warnings.
export.trig (1.8 KB)

I'm just poking around and noticed that if you execute geof:distance with only two arguments it throws an index out of bounds exception but should probably throw an ExpressionEvaluationException.

Caused by: java.lang.IndexOutOfBoundsException: Index: 2, Size: 2

Just to follow up, if you were to use ?geo1 ?geo2 in your query, you will see the proper results. When the blog post says that it accepts Geometries or WKT Literals, it means that it will accept a WKT Literal constant value. It doesn't seem as if variables of the WKT Literal type are supposed to work.

@stephen your explanation solves my problem. The WKT Literal constant vs literal wasn't very obvious to me so thank you!

1 Like

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