估计半径时出现 xsd:decimal 问题
Issue with xsd:decimal when estimating the radius
我想提取位于给定经纬度 20 公里范围内的项目。下面我提供我的查询。它唯一的问题与 ?lat
和 ?long
有关。他们有这样的格式 "41.3823035"^^xsd:decimal
。在 ontology 文件中,纬度和经度的格式为 xsd:float
。
当我 运行 查询时,我得到错误:
Error 500: Infinite or NaN
Fuseki - version 2.4.1 (Build date: 2016-11-04T18:59:20+0000)
如果我将 ?lat
替换为 41.38,并将 ?long
替换为 2.22
,则它有效。
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.test.com/my-ontology.owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX oo: <http://www.w3.org/2002/07/owl#>
PREFIX oa: <http://www.w3.org/ns/oa#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX lfn: <http://www.dotnetrdf.org/leviathan#>
PREFIX fn: <http://www.w3.org/2005/xpath-functions#>
PREFIX afn: <http://jena.hpl.hp.com/ARQ/function#>
SELECT DISTINCT ?id ?kwds ?lat WHERE {
?p owl:id 123 .
?p rdf:type ?service .
?service rdfs:subClassOf ?family .
?otherService rdfs:subClassOf ?family .
?item rdf:type ?otherService .
?item owl:id ?id .
?item owl:latitude ?lat .
?item owl:longitude ?long .
BIND ((lfn:degrees-to-radians(?lat)) AS ?lat1) .
BIND ((lfn:degrees-to-radians(?long)) AS ?lon1) .
BIND ((lfn:degrees-to-radians(41.384697)) AS ?lat2) .
BIND ((lfn:degrees-to-radians(2.150849)) AS ?lon2) .
BIND ((?lon2-?lon1) AS ?dlon) .
BIND ((?lat2-?lat1) AS ?dlat) .
BIND ((lfn:sq(lfn:sin(?dlat/2))+lfn:cos(?lat1)*lfn:cos(?lat2)*lfn:sin(?dlon/2) ) AS ?a) .
BIND ((2*lfn:sin-1(lfn:sqrt(?a))) AS ?c) .
BIND ((xsd:float(fn:round((6371*?c)))) AS ?dist) .
FILTER ( ?dist < 25 ) .
}
更新
问题是由这一行引起的BIND ((2*lfn:sin-1(lfn:sqrt(?a))) AS ?c) .
。对于 lat
和 lon
(0.0) 的某些值,它 returns NaN
.
我通过在 BIND
语句中添加 IF
解决了这个问题:
BIND (IF(?c != "NaN"^^xsd:double,xsd:float(fn:round((6371*?c))),999999) AS ?dist)
我想提取位于给定经纬度 20 公里范围内的项目。下面我提供我的查询。它唯一的问题与 ?lat
和 ?long
有关。他们有这样的格式 "41.3823035"^^xsd:decimal
。在 ontology 文件中,纬度和经度的格式为 xsd:float
。
当我 运行 查询时,我得到错误:
Error 500: Infinite or NaN
Fuseki - version 2.4.1 (Build date: 2016-11-04T18:59:20+0000)
如果我将 ?lat
替换为 41.38,并将 ?long
替换为 2.22
,则它有效。
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.test.com/my-ontology.owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX oo: <http://www.w3.org/2002/07/owl#>
PREFIX oa: <http://www.w3.org/ns/oa#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX lfn: <http://www.dotnetrdf.org/leviathan#>
PREFIX fn: <http://www.w3.org/2005/xpath-functions#>
PREFIX afn: <http://jena.hpl.hp.com/ARQ/function#>
SELECT DISTINCT ?id ?kwds ?lat WHERE {
?p owl:id 123 .
?p rdf:type ?service .
?service rdfs:subClassOf ?family .
?otherService rdfs:subClassOf ?family .
?item rdf:type ?otherService .
?item owl:id ?id .
?item owl:latitude ?lat .
?item owl:longitude ?long .
BIND ((lfn:degrees-to-radians(?lat)) AS ?lat1) .
BIND ((lfn:degrees-to-radians(?long)) AS ?lon1) .
BIND ((lfn:degrees-to-radians(41.384697)) AS ?lat2) .
BIND ((lfn:degrees-to-radians(2.150849)) AS ?lon2) .
BIND ((?lon2-?lon1) AS ?dlon) .
BIND ((?lat2-?lat1) AS ?dlat) .
BIND ((lfn:sq(lfn:sin(?dlat/2))+lfn:cos(?lat1)*lfn:cos(?lat2)*lfn:sin(?dlon/2) ) AS ?a) .
BIND ((2*lfn:sin-1(lfn:sqrt(?a))) AS ?c) .
BIND ((xsd:float(fn:round((6371*?c)))) AS ?dist) .
FILTER ( ?dist < 25 ) .
}
更新
问题是由这一行引起的BIND ((2*lfn:sin-1(lfn:sqrt(?a))) AS ?c) .
。对于 lat
和 lon
(0.0) 的某些值,它 returns NaN
.
我通过在 BIND
语句中添加 IF
解决了这个问题:
BIND (IF(?c != "NaN"^^xsd:double,xsd:float(fn:round((6371*?c))),999999) AS ?dist)