R SF:提取嵌套在JSON中的嵌套geoJSON功能

时间:2019-04-02 20:53:26

标签: r json geojson sf geojsonio

我有一个JSON文件,其中嵌套了geoJSON功能集。

是否可以使用type myStruct struct { Key string `json:"key"` Value string `json:"value"` } key, value := gen() data := myStruct{Key: key, Value: value} myJSON, err := json.Marshal(data) err = conn.WriteMessage(websocket.TextMessage, myJSON) 读取JSON文件,提取geoJSON位,然后将结果jsonlite::read_json()转换为list对象?另一种方法是使用sf之类的包将list写回JSON(文本)并读取geoJSON。

这是我的JSON代码如下:

geojsonio

1 个答案:

答案 0 :(得分:1)

也许

x <- '{
  "all": [
    {
      "type": "Feature",
      "geometry": {
        "type": "GeometryCollection",
        "geometries": [
          {
            "type": "Point",
            "coordinates": [
              -75.155727,
              39.956318
            ]
          },{
            "type": "LineString",
            "coordinates": [
              [
                -75.15567895337301,
                39.95653558798881
              ],[
                -75.15575995337292,
                39.95616931624319
              ]
            ]
          },{
            "type": "Point",
            "coordinates": [
              -75.15566,
              39.956432
            ]
          }
        ]
      },
      "properties": null
    }
  ]
}'
sf::st_read(jqr::jq(x, ".all[]"))

(将字符串编辑为有效的JSON)