我想将sf对象导出为.kml文件,为每个我感兴趣的功能添加标签,这样我就可以在Google Earth中轻松查看数据。我知道你可以点击谷歌地球中的“信息”按钮,但对于数百个多边形来说,这并不理想。
例如,我想使用列NAME来标记下面的每个多边形特征。如何修改下面的st_write调用来标记kml多边形,以便它们出现在Google Earth的侧栏目录中?
library(sf)
library(dplyr)
# sf includes this dataset
county_polygons <- st_read(system.file("shape/nc.shp", package="sf")) %>%
st_transform(4326)
st_write(county_polygons , "test.kml", driver = "kml")下面的图片显示了Google Earth在导入为kml文件时缺少标签的情况:

发布于 2019-08-09 03:57:16
考虑以下代码,使用一个不同的数据集-来自ns.shp的北卡罗来纳州各县的多边形随{sf}包一起提供:
library(sf)
library(dplyr)
# dataset included with sf package
county_polygons <- st_read(system.file("shape/nc.shp", package="sf")) %>%
st_transform(4326) %>% # just because wgs84...
select(Description = NAME) # see https://gdal.org/drivers/vector/kml.html#creation-options
st_write(county_polygons, "test.kml", driver = "kml", delete_dsn = TRUE)它是围绕DescriptionField (在Google Earth中可单击)的KML导出特性构建的,缺省为名为Description的sf列。

如果您希望在侧边栏中显示该特性的名称,则可以在上面的代码中将单词Description替换为Name。
https://stackoverflow.com/questions/57415464
复制相似问题