我正在尝试使用geojsonio包从其他R包中提取的data.frames中编写一些geojson文件。
library(ggplot2)
library(geojsonio)
us_state <- map_data('state')
geojson_write(us_state,
geometry="polygon",
grouping="group",
file="path/file.geojson")
我遇到的问题是geometry=polygon
参数。我收到以下错误:
Error in .subset2(x, i, exact = exact) :
attempt to select less than one element in integerOneIndex
当geometry=point
工作正常时,当然我在geojson文件中只有一百万个单独的点而不是状态多边形。
有什么想法吗?
编辑:
如果先使用file<-geojson_json(data.frame)
,然后geojson_write(file)
答案 0 :(得分:1)
您只需使用正确的参数名称group
,而不是grouping
。由于该函数具有...
,因此可以传入错误的参数名称而不会抛出任何错误/ etc。
library(ggplot2)
library(geojsonio)
us_state <- map_data('state')
geojson_write(us_state,
geometry = "polygon",
group = "group",
file = "file.geojson")
#> {
#> "type": "FeatureCollection",
#>
#> "features": [
#> { "type": "Feature", "id": 0, "properties": { "dummy": 0.000000 }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ -87.462005615234375, 30.389680862426758 ], [ -87.484931945800781, 30.372491836547852 ], [ -87.525032043457031, 30.372491836547852 ], [ -87.53076171875, 30.332386016845703 ], [ -87.570869445800781, 30.326654434204102 ], [ -87.588058471679688, 30.326654434204102 ], [ -87.593788146972656, 30.309467315673828 ], [ -87.593788146972656, 30.286548614501953 ], [ -8
#> ... cutoff