使用 R 创建单列 GeoJSON

问题描述 投票:0回答:1

我正在尝试创建一个 excel 文件,准备在 Power Apps 地理空间功能中使用:https://learn.microsoft.com/en-us/power-apps/maker/canvas-apps/geospatial-map-draw-形状#import-geojson-shapes-into-a-map

这需要一个 excel 文件,其中每一行都是一个单独的功能,其中有一个 GeoJSON 列,它是一个自包含的 GeoJSON 对象。

我不知道如何使用 R 和 R Studio 来做到这一点。我的输入文件是 GeoJSON,但也可以是 shapefile。

我尝试了多种方法,但每次我都在尝试导出功能时遇到困难

r geospatial geojson
1个回答
0
投票

我无权访问 Power Apps Geospatial,因此无法测试最终结果,但是:

library("openxlsx")

bob <- '{"type":"FeatureCollection","properties":{"kind":"state","state":"WA"},"features":[{"type":"Feature","properties":{"kind":"county","name":"Adams","state":"WA"},"geometry":{"type":"MultiPolygon","coordinates":[[[[-118.9503,47.2640],[-117.9590,47.2586],[-117.9699,46.8697],[-118.0466,46.7711],[-118.2109,46.7383],[-119.2132,46.7383],[-119.3720,46.7383],[-119.3665,46.9135],[-118.9832,46.9135],[-118.9777,47.2640]]]]}}]}'

test <- data.frame(
  County = "Adams",
  GeoJson = bob,
  TotalCases =  1689,
  Color = "RGB(184,210,232)"
)

openxlsx::write.xlsx(test, "test.xls")

给出了与您的链接类似的结果。

“奖励”(来自 geojson):

# testing it from a geojson
writeLines(bob, "test.geojson") # create a small geojson

bill <- readLines("test.geojson")

test2 <- data.frame(
  County = "Adams",
  GeoJson = bill,
  Color = "RGB(184,210,232)"
)
# same result
openxlsx::write.xlsx(test2, "test2.xls")
© www.soinside.com 2019 - 2024. All rights reserved.