Does GeoSPARQL provide functionality to calculate the distance between two linestrings? (Edit: I'm using Jena Fuseki with the GeoSPARQL extension.)
The results are not working as expected.
Linestring query, assuming all of the geometries are also linestrings:
prefix geo: <http://www.opengis.net/ont/geosparql#>
prefix geof: <http://www.opengis.net/def/function/geosparql/>
prefix ogis: <http://www.opengis.net/def/uom/OGC/1.0/>
select * where {
?s geo:hasGeometry ?f .
?f geo:asWKT ?wkt.
BIND(geof:distance(?wkt,
"<http://www.opengis.net/def/crs/EPSG/0/27700> LINESTRING(41.8 -87.6,41.8 -87.5)"^^geo:wktLiteral,
ogis:kilometre) as ?distance)
}
ORDER BY asc(abs(?distance))
If instead I calculate distance between points, then this works as expected.
Points, assuming all of the geometries are also points:
prefix geo: <http://www.opengis.net/ont/geosparql#>
prefix geof: <http://www.opengis.net/def/function/geosparql/>
prefix ogis: <http://www.opengis.net/def/uom/OGC/1.0/>
select * where {
?s geo:hasGeometry ?f .
?f geo:asWKT ?wkt .
BIND(geof:distance(?wkt,
"<http://www.opengis.net/def/crs/EPSG/0/27700> POINT(41.8 -87.6)"^^geo:wktLiteral,
ogis:kilometre) as ?distance)
}
ORDER BY asc(abs(?distance))
And what about the distance from a point to line, and vice versa?
Edit: Here are the results for a line to line search given my dataset. The distances are obviously wrong. The lines are typically no closer than a few KMs, but all of these results are shown as less than 1KM. For example, the last result is shown as 0.35KM but it's in Louisiana whereas the original point is in Illinois.
Again, these results are from Jena Fuseki with the GeoSPARQL extension.
select ?wkt ?distance where {
?s a sosa:featureOfInterest .
?s geo:hasGeometry ?f .
?f geo:asWKT ?wkt.
BIND(geof:distance(?wkt,
"<http://www.opengis.net/def/crs/EPSG/0/27700> LINESTRING(41.85003 -87.65005,41.85 -87.65)"^^geo:wktLiteral,
ogis:kilometre) as ?distance) .
}
ORDER BY asc(abs(?distance))
limit 10
index | wkt.value | distance.value |
---|---|---|
0 | <http://www.opengis.net/def/crs/EPSG/0/27700> LINESTRING(46.7082 -89.9785,46.7 -89.9892) | 0.168957e0 |
1 | <http://www.opengis.net/def/crs/EPSG/0/27700> LINESTRING(46.699902 -89.989067,46.669998 -90.046654) | -0.186799e0 |
2 | <http://www.opengis.net/def/crs/EPSG/0/27700> LINESTRING(41.84 -87.607,41.839 -87.605) | 0.205283e0 |
3 | <http://www.opengis.net/def/crs/EPSG/0/27700> LINESTRING(41.865 -87.607,41.863 -87.607) | 0.208798e0 |
4 | <http://www.opengis.net/def/crs/EPSG/0/27700> LINESTRING(46.708 -89.978,46.7096 -89.9749) | 0.246481e0 |
5 | <http://www.opengis.net/def/crs/EPSG/0/27700> LINESTRING(41.894 -87.614,41.894 -87.612) | 0.26358e0 |
6 | <http://www.opengis.net/def/crs/EPSG/0/27700> LINESTRING(41.904 -87.624,41.902 -87.622) | 0.272661e0 |
7 | <http://www.opengis.net/def/crs/EPSG/0/27700> LINESTRING(41.8234 -87.5966,41.8215 -87.595) | 0.278589e0 |
8 | <http://www.opengis.net/def/crs/EPSG/0/27700> LINESTRING(41.924 -87.63,41.914 -87.62) | 0.326035e0 |
9 | <http://www.opengis.net/def/crs/EPSG/0/27700> LINESTRING(29.226625 -90.001852,29.211947 -90.026484) | -0.353463e0 |