Export KML for use in Google Maps. Here is the code for export (adapted from here ):
t_expkml_c <- function(obj, archivo,
col_nombre, col_desc, col_color,
mapa_colores = "mapa_colores_topaz",
mapa_nombre = "Mapa_TSE", mapa_desc = "Mapa Creado por PE de TSE") {
if (proj4string(obj)!="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0") {
cat("Input SpatialPolygonsDataFrame ",obj," re-projected from ",
proj4string(obj)," to WGS84 longlat\n",sep="")
assign(obj,spTransform(obj,CRS(" +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0")))
}
kmlFile <- file(archivo,
open = "w")
Xout <- sapply(slot(obj,
"polygons"),
function(x) {
maptools::kmlPolygon(x,
name = as(obj, "data.frame")[slot(x, "ID"), col_nombre],
col = mapa_colores[as.numeric(as(obj, "data.frame")[slot(x, "ID"), col_color])],
lwd = 0.5,
border = NA,
visibility = TRUE,
description = as(obj,"data.frame")[slot(x, "ID"), col_desc],
)
}
)
cat(kmlPolygon(kmlname=mapa_nombre,
kmldescription=mapa_desc)$header,
file = kmlFile, sep="\n")
cat(unlist(Xout["style",]),
file = kmlFile, sep="\n")
cat(unlist(Xout["content",]),
file = kmlFile, sep="\n")
cat(kmlPolygon()$footer,
file = kmlFile, sep="\n")
close(kmlFile)
}
This works fine when I have only one column from kmlmap@datadata.frame (object is a class SpatialPolygonsDataFrame). However, I want to export a large data table so that it appears in the description of the Google Maps form.
For example, this is a single column (source export);

If I want to add other descriptors, I modify the data table in Google Maps as follows:

R. description, (.. c("Column2", "Column3") 1:2), HTML ( Google Maps , ).
?