AustralianAntarcticDivision / SOmap

Southern Ocean round maps
https://australianantarcticdivision.github.io/SOmap/
24 stars 6 forks source link

generic 'addlayer' function #14

Closed Maschette closed 5 years ago

Maschette commented 5 years ago

Much in the way that SOauto_map() reads in data and reprojects it to the polar at the right projection it would be good to have a generic function that works with SOmap() so neophytes (me) can hand it objects (points, shape, raster) and it performs the appropriate transformation and then plots it on top.

SOmap()
SOmap_layer(shiptrack$lat,shiptrack$lon) 
mdsumner commented 5 years ago

I started doing

library(SOmap)
library(reproj)
## we are assuming x[c("lon", "lat")] data frame
reproj.data.frame <- function(x, target, ..., source = NULL) {
  stopifnot(ncol(x) == 2)
  reproj(x, target = target, ..., source = source)
}

SOmap_add <- function(x, ...) {
  if (inherits(x, "data.frame")) {
    points(reproj(x, target = raster::projection(SOmap::Bathy), 
                  source = "+proj=longlat +datum=WGS84"))
    return(invisible(NULL))
  }
  stop(sprintf("adding objects of type %s not yet supported", class(x)[1]))
}

SOmap()
SOmap_add(SOmap_data$)

but it keeps crashing my session - more later

Maschette commented 5 years ago

So unsure whether to close this issue and make a new one about adding functionality to SOplot, or add it here?

SOplot works for points currently but needs to be expanded for other outputs such as lines, polygons and rasters.