12

我有兴趣从statistics.gov.scot下载一些边界文件,这是一个官方统计存储库,用于共享利用 SPARQL 查询的统计数据。

背景

Statistics.gov.scot提供对许多行政和统计地理区域的 GeoJSON 边界的访问,例如地方当局行政边界卫生委员会。在我的特殊情况下,我有兴趣下载与数据区域有关的 GeoJSON 边界的数据集。数据区是为在小区域范围内传播生活结果数据而开发的统计地理。通过statistics.gov.scot示例数据区访问时,如下所示:

样本数据区

地理和相关数据可以在这里访问。相应的 GeoJSON 数据可在此处获得。

问题

数据区在两个迭代中可用,一个是在 2004 年生成的,另一个是最近更新的。我想下载2004 年制作的第一次迭代。根据有关统计实体的信息,我起草了以下查询:

PREFIX entity: <http://statistics.data.gov.uk/def/statistical-entity#>
PREFIX boundaries: <http://statistics.gov.scot/boundaries/>

SELECT ?boundary 
    WHERE {
        entity:introduced <http://reference.data.gov.uk/id/day/2004-02-01>
  }

LIMIT 1000

它返回以下错误消息:

Error There was a syntax error in your query: Encountered " "}" "} "" at line 7,
column 3. Was expecting one of: <IRIref> ... <PNAME_NS> ... <PNAME_LN> ...
<BLANK_NODE_LABEL> ... <VAR1> ... <VAR2> ... "true" ... "false" ... <INTEGER> ...
<DECIMAL> ... <DOUBLE> ... <INTEGER_POSITIVE> ... <DECIMAL_POSITIVE> ...
<DOUBLE_POSITIVE> ... <INTEGER_NEGATIVE> ... <DECIMAL_NEGATIVE> ...
<DOUBLE_NEGATIVE> ... <STRING_LITERAL1> ... <STRING_LITERAL2> ...
<STRING_LITERAL_LONG1> ... <STRING_LITERAL_LONG2> ... "(" ... <NIL> ... "[" ...
<ANON> ... "+" ... "*" ... "/" ... "|" ... "?" ...

通过端点测试时: http: //statistics.gov.scot/sparql

注释

理想情况下,我想开发其他查询,使我能够通过使用entity:前缀来获取其他统计地理信息。这应该是可能的,因为entity:它将包含有关可用地理位置的信息(名称、首字母缩写词、创建日期)。


查询:

PREFIX entity: <http://statistics.data.gov.uk/def/statistical-entity#>
PREFIX boundaries: <http://statistics.gov.scot/boundaries/>

SELECT DISTINCT ?boundary ?shape WHERE {
  ?shape entity:firstcode ?boundary
}

LIMIT 1000

让我得到了一些看起来像所需地理位置列表的东西,但我正在努力寻找 GeoJSON 边界。

4

2 回答 2

5

第一个查询缺少主题。SPARQL 查询定义了一组三元组模式 - 主语、谓语和宾语 - 以匹配 RDF 图。要将 WHERE 子句转换为 SPARQL 三元组模式,请尝试:

?boundary entity:introduced <http://reference.data.gov.uk/id/day/2004-02-01>
于 2016-02-26T17:08:38.610 回答
1

statistics.gov.scotstatistics.data.gov.uk都不包含数据区域边界作为WKT或字符串文字。

但是,通过以下查询,可以轻松构建用于资源页面的 GeoJSON 文件的 URL:

PREFIX pref1: <http://statistics.data.gov.uk/def/statistical-entity#>
PREFIX pref2: <http://statistics.gov.scot/id/statistical-entity/>
PREFIX pref3: <http://statistics.data.gov.uk/def/boundary-change/>
PREFIX pref4: <http://reference.data.gov.uk/id/day/>
PREFIX pref5: <http://statistics.data.gov.uk/def/statistical-geography#>
PREFIX pref6: <http://statistics.gov.scot/id/statistical-geography/>
PREFIX pref7: <http://statistics.gov.scot/boundaries/>

SELECT ?zone ?name ?json {
   ?zone pref1:code pref2:S01 .
   ?zone pref3:operativedate pref4:2004-02-01
   OPTIONAL { ?zone pref5:officialname ?name }
   BIND (CONCAT(REPLACE(STR(?zone), STR(pref6:), STR(pref7:)), ".json") AS ?json)
} ORDER BY (!bound(?name)) ASC(?name)

之后,可以使用wget -i类似的东西轻松检索 GeoJSON 文件。

一些解释

您应该使用<http://statistics.data.gov.uk/def/boundary-change/operativedate>而不是<http://statistics.data.gov.uk/def/statistical-entity#introduced>,后一个属性是一个类属性:

SELECT * WHERE {
    ?S <http://statistics.data.gov.uk/def/statistical-entity#introduced> ?date .
    ?S <http://www.w3.org/2000/01/rdf-schema#label> ?label
}

第二代数据区的日期为2014-11-06

SELECT ?date (COUNT(?zone) AS ?count) WHERE {
    ?zone
        <http://statistics.data.gov.uk/def/statistical-entity#code>
            <http://statistics.gov.scot/id/statistical-entity/S01> ;
        <http://statistics.data.gov.uk/def/boundary-change/operativedate>
            ?date 
} GROUP BY ?date

类似地,如果您需要相应 GeoJSON 文件的 URL,您的查询应该是:

SELECT ?zone ?name ?json {
   ?zone pref1:code pref2:S01 .
   ?zone pref3:operativedate pref4:2014-11-06 .
   ?zone pref5:officialname ?name 
   BIND (CONCAT(REPLACE(STR(?zone), STR(pref6:), STR(pref7:)), ".json") AS ?json)
} ORDER BY ASC(?name)

您不需要OPTIONAL,因为所有第二代数据区都有“官方名称”。


data.gov.uk上的这个页面可能会让您感兴趣。 还存在opendata.stackexchange.com,用于解答与开放数据相关的问题。

更新

截至 2018 年 5 月,可以将数据区域边界检索为 WKT:

PREFIX pref1: <http://statistics.data.gov.uk/def/statistical-entity#>
PREFIX pref2: <http://statistics.gov.scot/id/statistical-entity/>
PREFIX pref3: <http://statistics.data.gov.uk/def/boundary-change/>
PREFIX pref4: <http://reference.data.gov.uk/id/day/>
PREFIX pref5: <http://statistics.data.gov.uk/def/statistical-geography#>
PREFIX pref6: <http://www.opengis.net/ont/geosparql#>


SELECT ?zone ?name ?geometry {
   ?zone pref1:code pref2:S01 .
   ?zone pref3:operativedate pref4:2014-11-06 .
   ?zone pref5:officialname ?name .
   ?zone pref6:hasGeometry/pref6:asWKT ?geometry .
} ORDER BY ASC(?name)
于 2017-10-10T11:07:43.063 回答