R/kml_compress.R

Defines functions kml_compress

Documented in kml_compress

kml_compress <- function(file.name, zip = Sys.getenv("R_ZIPCMD", "zip"), files = "", rm = FALSE, ...){

  # Changing the extension to KMZ
  extension <- tools::file_ext(file.name)
  kmz <- stringr::str_replace(file.name, extension, "kmz") # switch the extension to kmz
	
  # use R's zip wrapper
  if(.Platform$OS.type == "windows") {
    try( x <- zip(zipfile = utils::shortPathName(kmz), files= utils::shortPathName(file.name), zip = zip) )
  } else {
    try( x <- zip(zipfile = kmz, files= file.name, zip = zip) )
  }
  # Error handling
  if(is(.Last.value, "try-error")| x==127) {
    if(zip==""|!nzchar(zip)){
       warning("KMZ generation failed. No zip utility has been found.")
  } else {
       warning("KMZ generation failed. Wrong command passed to 'zip = ... option'.")
  }
  }  
  
  # clean-up
  if (file.exists(kmz) & rm==TRUE) {
  	x <- file.remove(file.name, files)
  }

}

# end of script;

Try the plotKML package in your browser

Any scripts or data that you put into this service are public.

plotKML documentation built on June 7, 2022, 5:07 p.m.