【问题标题】:Reading in a .geojson file with geojsonio, geojsonR使用 geojsonio、geojsonR 读取 .geojson 文件
【发布时间】:2021-08-14 16:03:40
【问题描述】:

我正在尝试在 R 中读取 geojson 文件 (https://www.svz-bw.de/fileadmin/verkehrszentrale/RadNETZ-BW_Daten_GeoJSON_2018-20.zip)。

我尝试了不同的软件包,但我的知识太有限,无法找到错误并解决它们。我对 R 中的空间数据不熟悉,尤其是阅读 geojson 文件格式。 在 stackoverflow 中搜索和搜索没有帮助。

geojsonR::FROM_geojson("../Sonstiges/RadNETZ.geojson")

unlink(x) 出错:文件名转换问题——名称太长?

geojsonR::FROM_GeoJson("../Sonstiges/RadNETZ.geojson")

export_From_geojson(url_file_string, Flatten_Coords, Average_Coordinates, : 无效的 GeoJson 几何对象 --> geom_OBJ() 函数

【问题讨论】:

  • 真的要使用 R 而不是 Qgis?
  • 无论如何我都需要 R 中的数据进行统计分析。只是试图从这些数据中提取联合分布并根据路径的长度(顺便说一句是自行车道)对它们进行加权:)

标签: r dataframe geospatial geojson sf


【解决方案1】:

您的文件不符合当前的 GeoJSON 标准;它使用投影坐标参考系统,这违反了 RFC 7946 - https://www.rfc-editor.org/rfc/rfc7946#page-12

这可能是也可能不是 geojson 特定包难以解释它的原因。

为了处理您的文件,我建议使用 {sf},它 - 通过 GDAL 和 PROJ - 能够消化文件。

library(dplyr)
library(sf)

asdf <- st_read("RadNETZ.geojson") %>% 
  st_transform(4326) # safety of unprojected CRS

plot(st_geometry(asdf))

【讨论】:

  • 感谢您的帮助!我会将此信息转发给发布数据的官方办公室。如果我使用此投影进行计算,路径长度的计算是否准确?
  • “准确”是一个狡猾的术语?为了最大限度地与您可能想要删除 st_transform(4326) 部分的其他结果保持一致。数据的行为不像真正的 GeoJSON,但长度将更符合您的数据输入的预计 CRS。
【解决方案2】:

@Jindra Lacko 提到您的“RadNETZ.geojson”文件不符合 RFC 7946,这就是您收到错误的原因。如果您的操作系统上除了 'sf' 包之外没有安装 GDAL,您可以使用 geojsonR::shiny_from_JSON(它不遵循 RFC,旨在用于闪亮的应用程序),

dat = geojsonR::shiny_from_JSON("../Sonstiges/RadNETZ.geojson")
str(dat)

List of 4
 $ crs     :List of 2
  ..$ properties:List of 1
  .. ..$ name: chr "urn:ogc:def:crs:EPSG::31467"
  ..$ type      : chr "name"
 $ features:List of 70097
  ..$ :List of 3
  .. ..$ geometry  :List of 2
  .. .. ..$ coordinates:List of 6
  .. .. .. ..$ :List of 2
  .. .. .. .. ..$ : num 3563993
  .. .. .. .. ..$ : num 5353055
  .. .. .. ..$ :List of 2
  .. .. .. .. ..$ : num 3564002
  .. .. .. .. ..$ : num 5353070
  .. .. .. ..$ :List of 2
  .. .. .. .. ..$ : num 3564009
  .. .. .. .. ..$ : num 5353087
  .. .. .. ..$ :List of 2
  .. .. .. .. ..$ : num 3564013
  .. .. .. .. ..$ : num 5353103
  .. .. .. ..$ :List of 2
  .. .. .. .. ..$ : num 3564016
  .. .. .. .. ..$ : num 5353109
  .. .. .. ..$ :List of 2
  .. .. .. .. ..$ : num 3564030
  .. .. .. .. ..$ : num 5353121
  .. .. ..$ type       : chr "LineString"
  .. ..$ properties:List of 24
  .....

jsonlite::fromJSON 函数,

dat = jsonlite::fromJSON("../Sonstiges/RadNETZ.geojson")
str(dat)

List of 4
 $ type    : chr "FeatureCollection"
 $ name    : chr "sql_statement"
 $ crs     :List of 2
  ..$ type      : chr "name"
  ..$ properties:List of 1
  .. ..$ name: chr "urn:ogc:def:crs:EPSG::31467"
 $ features:'data.frame':   70097 obs. of  3 variables:
  ..$ type      : chr [1:70097] "Feature" "Feature" "Feature" "Feature" ...
  ..$ properties:'data.frame':  70097 obs. of  24 variables:
  .. ..$ gid     : int [1:70097] 4 15 23 22 45 72 60 74 13072 75 ...
  .. ..$ lrvn_kat: int [1:70097] 3 1 1 3 1 1 3 1 3 1 ...
  .....

为了记录,我是geojsonR 包的作者/维护者

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-17
    • 2018-05-11
    • 1970-01-01
    • 2012-05-09
    • 1970-01-01
    • 1970-01-01
    • 2018-08-27
    • 2016-02-22
    相关资源
    最近更新 更多