同事和我正在使用RDF数据集和RDF4J的内存存储库,我们试图在使用WKT格式的几何数据的同时执行GeoSparql查询,如下所示:
@prefix geo: <http://www.opengis.net/ont/geosparql#> .
@prefix sf: <http://www.opengis.net/ont/sf> .
@prefix ex: <http://example.org/> .
@prefix geof: <http://www.opengis.net/def/function/geosparql/>.
ex:eiffelTower a ex:Landmark ;
geo:hasGeometry ex:coordinates-et.
ex:coordinates-et a sf:Point;
geo:asWKT "POINT(2.2945 48.8584)"^^geo:wktLiteral .
ex:towerBridge a ex:Landmark ;
geo:hasGeometry ex:coordinates-tb.
ex:coordinates-tb a sf:Point;
geo:asWKT "POINT(-0.0754 51.5055)"^^geo:wktLiteral .场景-1:到目前为止,我们成功地使用了geof:distance函数,例如查询及其结果如下所示。目的是计算两个地标坐标之间的距离。
SELECT *
WHERE {
?lmA a ex:Landmark ;
geo:hasGeometry [ geo:asWKT ?coord1 ].
?lmB a ex:Landmark ;
geo:hasGeometry [ geo:asWKT ?coord2 ].
BIND((geof:distance(?coord1, ?coord2, uom:metre)/1000) as ?dist) .
FILTER (str(?lmA) < str(?lmB))
}场景的结果-1:
lmA => ex:eiffelTower
coord1 => "POINT(2.2945 48.8584)"
lmB => ex:towerBridge
coord2 => "POINT(-0.0754 51.5055)"
dist => "339.2412973915987"场景2:当我们尝试使用其他函数(例如geof:sfWithin、geof:sfContains )时,我们遇到了一些奇怪的行为。下面显示了带有geof:sfWithin示例的查询及其结果。其目的是获取所有位于给定多边形内的点。
SELECT *
WHERE {
?lmA a ex:Landmark ;
geo:hasGeometry ?Geom.
?Geom geo:asWKT ?WKT.
FILTER(geof:sfWithin(?WKT, '''
<http://www.opengis.net/def/crs/OGC/1.3/CRS84>
Polygon ((80.0 80.0, -80.0 80.0, -80.0 -80.0, 80.0 -80.0, 80.0 80.0))
'''^^geo:wktLiteral))
}结果: -empty表-
我们的问题做错了吗?我们的依赖关系:
rdf4j-storage 3.6.0rdf4j-queryalgebra-geosparql 3.6.1发布于 2021-03-22 03:37:24
我认为问题在于您的多边形wkt文字的语法。你有:
<http://www.opengis.net/def/crs/OGC/1.3/CRS84>
Polygon ((80.0 80.0, -80.0 80.0, -80.0 -80.0, 80.0 -80.0, 80.0 80.0))我不知道第一行的URI是从哪里来的(我并不是GeoSPARQL专家),但在我看来,这并不是一个合适的WKT文字。我试过你的查询
Polygon ((80.0 80.0, -80.0 80.0, -80.0 -80.0, 80.0 -80.0, 80.0 80.0))相反,得到了以下两个结果:
lmA=http://example.org/eiffelTower
WKT="POINT(2.2945 48.8584)"^^<http://www.opengis.net/ont/geosparql#wktLiteral>
Geom=http://example.org/coordinates-et
lmA=http://example.org/towerBridge
WKT="POINT(-0.0754 51.5055)"^^<http://www.opengis.net/ont/geosparql#wktLiteral>
Geom=http://example.org/coordinates-tb不可否认,查询无声失败而不是产生一些“无法处理WKT文字”的错误或警告是令人困惑的。
更新:
再看一看(也请参阅注释),这实际上是RDF4J中的一个bug。正如GeoSPARQL规范中的8.5节所指出的,引用系统的前缀URI不是WKT规范本身的一部分,而是WKT文字定义中特定于GeoSPARQL的补充。因此,RDF4J需要在将其交给底层WKTReader之前负责预处理。作为https://github.com/eclipse/rdf4j/issues/2935创建的Bug票据。
作为解决办法,您仍然可以删除URI,因为CRS84实际上是默认的引用系统。
https://stackoverflow.com/questions/66735844
复制相似问题