0
votes

I am trying to get the maximum depth (max_depth) for a given lat and lot using this gebco (tiff file attached) and it keeps coming up with NA. In the past, this has worked so im not sure what is going wrong. The site is used to also extract temperature and nutrient data from WOCE files and that works. Is there something that I am missing in my code?

enter image description here

library(raster)
bathy <- raster("gebco0.5.tif") 

site <- cbind(125, -49)
extract(bathy, site)
#      [,1]
# [1,]   NA


show(bathy)
#class      : RasterLayer 
#dimensions : 360, 720, 259200 (nrow, ncol, ncell) 
#resolution : 1, 1 (x, y) 
#extent     : 0, 720, 0, 360 (xmin, xmax, ymin, ymax) 
#crs        : NA 
#source     : gebco0.5.tif
#names      : gebco0.5
1

1 Answers

0
votes

There is no attached file, but your code looks good, and this works

r <- raster("https://i.stack.imgur.com/g8WSo.png")
extent(r) <- c(-180,180,-90,90)
site <- cbind(125, -49)
extract(r, site)
# 0

My guess is that the extent of bathy is not what you expect. Can you show(bathy) to us?

Now that we have show(bathy) we can see that you have an unexpected extent for lon/lat data: 0, 720, 0, 360 (xmin, xmax, ymin, ymax) . Such that you get

r <- raster("https://i.stack.imgur.com/g8WSo.png")
site <- cbind(125, -49)
extract(r, site)
#     [,1]
#[1,]   NA

From what I can see, it appears that you need to do:

extent(r) <- c(-180, 180, -90, 90)

And then things should work (as I already showed above). And if you know whereabouts "site" is, you can visually check that with

plot(r)
points(site)