R/write_shp.R

Defines functions write_shp read_polyline

Documented in write_shp

#' @importFrom sf as_Spatial st_crs
#' @export
read_polyline <- function(file, lwd = 0.5, ...) {
  if (file.exists(file)) {
    shp <- read_sf(file) %>% as_Spatial()
    st_crs(shp) <- 4326
    # suppressWarnings(shp <- readShapeLines(file))
    list("sp.lines", shp, first = FALSE, lwd = lwd, ...) # china poly
  }
}


#' write and read ESRI Shapefile
#'
#' @param x Spatial* Object from sp package
#' @param file The path of ESRI shapefile
#' @param ... other parameters to [sf::write_sf()]
#' 
#' @export
write_shp <- function(x, file, ...) {
  write_sf(sf::st_as_sf(x), file, layer_options = "ENCODING=UTF-8", ...)
}
kongdd/sp2 documentation built on Jan. 15, 2024, 11:31 p.m.