使用OS Open Data / SPARQL进行Lat / long到邮政编码

时间:2014-09-16 16:58:54

标签: geolocation sparql

我有以下内容,它在给定邮政编码时检索纬度/经度。 如何在SPARQL中执行反向(给出lat / long,检索邮政编码)?

PREFIX pc: <http://data.ordnancesurvey.co.uk/ontology/postcode/>
PREFIX pos: <http://www.w3.org/2003/01/geo/wgs84_pos#>

SELECT ?lat ?long
WHERE {
  <http://data.ordnancesurvey.co.uk/id/postcodeunit/S24SU> pos:lat ?lat .
  <http://data.ordnancesurvey.co.uk/id/postcodeunit/S24SU> pos:long ?long .
}
enter code here

http://data.ordnancesurvey.co.uk/datasets/os-linked-data

1 个答案:

答案 0 :(得分:3)

SPARQL就是图形模式匹配。在您现有的查询中,?lat和?long是变量,您正在为它们寻找值。如果您已经拥有纬度和经度,则可以将它们放入查询中并用变量替换该位置。 E.g:

PREFIX pc: <http://data.ordnancesurvey.co.uk/ontology/postcode/>
PREFIX pos: <http://www.w3.org/2003/01/geo/wgs84_pos#>

SELECT ?place
WHERE {
  ?place pos:lat <your-lat-here> .
  ?place pos:long <your-long-here> .
}

您只需将⟨your-lat-here⟩和⟨your-long-here⟩替换为原始查询的结果值。