R/sp/rgdal.R

Defines functions write_grid gridSaveToPoly write_shp_sp

#' @rdname write_shp
#' @export
write_shp_sp <- function(x, file, ...) {
  rgdal::writeOGR(x, file, "shape", driver = "ESRI Shapefile", layer_options = "ENCODING=UTF-8", ...)
}

#' gridSaveToPoly
#'
#' Write spatialPixelDataframe into polygon shpfile for the convenience of
#' checking in google earth.
#'
#' @param grid The spatialPixelDataframe or spatialGridDataframe object.
#' @param file The string of output shapefile name including path.
#' @export
gridSaveToPoly <- function(grid, file) {
  poly <- as(grid, "SpatialPolygonsDataFrame")
  # writePolyShape(poly, file) #, can't write prj info
  rgdal::writeOGR(poly, dsn = file, layer = basename(file), driver = "ESRI Shapefile")
}

#' @export
write_grid <- function(obj, file) {
  rgdal::writeGDAL(obj$grid, file)
}
kongdd/sp2 documentation built on Jan. 15, 2024, 11:31 p.m.