我有这种格式的数据,在csv文件中,它看起来像这样:
当我用INDRECT
阅读时,就像这样:
read.csv2
我想知道如何将这些数据(在用{"type": "Polygon", "coordinates": [[[5.595422739518895, 46.574661252730515], [5.5868864112024, 46.578124834208275], [5.566460487135743, 46.579404434922125], [5.558571581276076, 46.580572027975954], [5.561819437593718, 46.587949918898076], [5.575191603674612, 46.59190224479517], [5.580673541265257, 46.59754467932337], [5.582347290927083, 46.60141691853218], [5.587289521318402, 46.59292683804338], [5.604997996100999, 46.58938109997026], [5.611508140899815, 46.5826199806949], [5.603671590915408, 46.57586134356789], [5.595422739518895, 46.574661252730515]]]}
读取之后似乎是一个字符串)转换为用传单绘制的内容。
答案 0 :(得分:2)
将数据保存在文本编辑器中* .geojson(在test.geojson下面的示例中)。然后你可以这样做:
library(leaflet)
library(geojsonio)
tst <- geojson_read("/home/ede/test.geojson", what = "sp")
leaflet() %>% addTiles() %>% addPolygons(data = tst)
答案 1 :(得分:0)
将JSON数据作为数据框导入的一种方法是使用jsonlite包:
library(jsonlite)
geojson <- '{"type": "Polygon", "coordinates": [[[5.595422739518895, 46.574661252730515], [5.5868864112024, 46.578124834208275], [5.566460487135743, 46.579404434922125], [5.558571581276076, 46.580572027975954], [5.561819437593718, 46.587949918898076], [5.575191603674612, 46.59190224479517], [5.580673541265257, 46.59754467932337], [5.582347290927083, 46.60141691853218], [5.587289521318402, 46.59292683804338], [5.604997996100999, 46.58938109997026], [5.611508140899815, 46.5826199806949], [5.603671590915408, 46.57586134356789], [5.595422739518895, 46.574661252730515]]]}'
df <- fromJSON(geojson)
注意:这是对XR SC在评论中提出的问题的回答。