rsbivand / rgrass

Interpreted interface between the GRASS geographical information system and R
https://rsbivand.github.io/rgrass/
24 stars 8 forks source link

Create GRASS locations from EPSG codes #70

Closed wenzeslaus closed 1 year ago

wenzeslaus commented 1 year ago

As mentioned in #34, it would be nice if rgrass can create GRASS locations (projects?) from EPSG codes.

I used the GRASS executable to do that:

#' Create GRASS GIS location
#'
#' Calls GRASS GIS to create a new GRASS GIS location using either a
#' georeferenced file or EPSG code.
#'
#' @param grassExecutable GRASS GIS executable (full path or command)
#' @param readProjectionFrom A geospatial file with CRS to use
#' @param EPSG EPSG code of a desired CRS
#' @param database Path to GRASS GIS spatial database (directory)
#' @param location Name of newly created location
createGRASSlocation <- function (grassExecutable, readProjectionFrom, EPSG, database, location) {
  locationPath <- file.path(database, location)
  if (missing(EPSG)){
    system(paste("\"", grassExecutable, "\"", " -c ", "\"", readProjectionFrom, "\"", " ", "\"", locationPath, "\"", " -e ", sep = ""))
  }
  else{
    system(paste("\"", grassExecutable, "\"", " -c ", "EPSG:", EPSG, " ", "\"", locationPath, "\"", " -e ", sep = ""))
  }
}
rsbivand commented 1 year ago

Thanks! No roxygen here please (also #71 ). No new functions either, both these should be incorporated into initGRASS(). Both also need care that R is not being run within GRASS, need clear documentation in vignettes/use.Rmd, and in the initGRASS() man page. Creating a "SpatRaster" object with the required CRS is probably easier than adding code, unless you have clear use cases.