I need to somehow combine my Spatialpolygons with my depth contour, but not sure how do to so. Maybe create a SpatialPolygonsDataframe?
This is what I've done so far:
> class(subarea0) #This is my area of interest (Eastern Canadian Arctic Sea)
[1] "SpatialPolygons"
attr(,"package")
[1] "sp"
> extent(subarea0)
class : Extent
xmin : -82.21997
xmax : -57.21667
ymin : 60.2
ymax : 78.16666
library(marelac)
data("Bathymetry")#World bathymetric data in library (marelac)
names(Bathymetry);class(Bathymetry);str(Bathymetry)
[1] "x" "y" "z"
[1] "list"
List of 3
$ x: num [1:359] -180 -179 -178 -177 -176 ...
$ y: num [1:180] -89.5 -88.5 -87.5 -86.5 -85.5 ...
$ z: num [1:359, 1:180] 2853 2873 2873 2873 2873 ...
raster_bath<-raster(Bathymetry)#Transformed into a raster layer (not sure if this is the best way to achieve what I want)
extent(raster_bath) <- extent(subarea0)#Transform the extend of my raster to the extend of my SpatialPolygons
v <- extract(raster_bath, subarea0)#Extract data from my Raster Layer for the locations of my SpatialPolygons
v is a list with depth and I am not quiet sure how/under what form to rebind this info with my spatial polygon... Ideas? Other suggestions?
EDITS
I apologize in advance, looks like I've been having a hard time to explain clearly what I was hoping to get. I don't want to summarize my depth info for each of my polygon but rather provide a detailed bathymetry within my area of interest.
I am definitely not sure if what I did up to now is the way to go, but ultimately what I would like to achieve is to end-up with a plot of my polygon with my depth information. Something like this
(thanks to Simbamangu), but without the depth info outside of my polygon. Basically, I just want the bathymetry info comprise in my overall area at the finest scale possible.
Should I first transform my SpatialPolygons into one and then into some grid format to then be able to clip with my raster layer?
Thank you!