R/region2SpatialPolygon.r

Defines functions extent2SpatialPolygon region2SpatialPolygon

Documented in extent2SpatialPolygon region2SpatialPolygon

region2SpatialPolygon <- function(region,v_area=region){
  r <- regions(v_area)
  x <- r$xlim
  y <- r$ylim
  plot(x,y)
  p <- sp::Polygon(cbind(
    c(x,rev(x),x[1]),
    c(y[1],y,rev(y))))
  
  sp <-  sp::SpatialPolygons(list(sp::Polygons(list(p), 1)))
  return(sp)
}


extent2SpatialPolygon <- function(ext){
  coords <- rbind(c(ext[1],ext[3]),
                  c(ext[2],ext[3]),
                  c(ext[2],ext[4]),
                  c(ext[1],ext[4]),
                  c(ext[1],ext[3])
  )
  
  pol <- sp::SpatialPolygons(list(sp::Polygons(list(sp::Polygon(coords)),ID="1")))
  return(pol)
}

Try the oceanmap package in your browser

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

oceanmap documentation built on Nov. 10, 2023, 5:08 p.m.