I can create a kml polygon (circles for different sites) file using R, but when I open the file in Google Earth, the site names that go with each site are not there. Here is my code to make circles with 15 mile radii surrounding points in South Dakota.
make_GeodesicBuffer <- function(pts, width){
# A) Construct buffers as points at given distance and bearing ---------------
dg <- seq(from = 0, to = 360, by = 1)
# Construct equidistant points defining circle shapes (the "buffer points")
buff.XY <- geosphere::destPoint(p = pts,
b = rep(dg, each = length(pts)),
d = width)
# B) Make SpatialPolygons -------------------------------------------------
# Group (split) "buffer points" by id
buff.XY <- as.data.frame(buff.XY)
id <- rep(1:dim(pts)[1], times = length(dg))
lst <- split(buff.XY, id)
# Make SpatialPolygons out of the list of coordinates
poly <- lapply(lst, sp::Polygon, hole = FALSE)
polys <- lapply(list(poly), sp::Polygons, ID = NA)
spolys <- sp::SpatialPolygons(Srl = polys,
proj4string = CRS(as.character("+proj=longlat +ellps=WGS84
+datum=WGS84")))
# Disaggregate (split in unique polygons)
spolys <- sp::disaggregate(spolys)
return(spolys)}
points = data.frame(id = c('ATRS2','BFMS2','BKMS2'),
lat = c(45.5,44.3,45.4),
lon = c(-103.3,-96.9,-96.8))
# Miles to meters conversion
mile2meter <- function(x){
x * 1609.344}
TO_1to4_buf_15miles <- make_GeodesicBuffer(as.matrix(points), width = mile2meter(15))
raster::KML(TO_1to4_buf_15miles, filename =
'F:\\Siting\\TO_1to4_buf_15miles.kml',overwrite=TRUE)
This works and the circles show up nicely in Google Earth. But how do I get the site names (ATRS2, BFMS2, BKMS2) to show up in Google Earth in the tree structure for each circle in the kml file that gets written out? Thank you.