0

I want to overlap a species distribution range on the world map which has values, and extract the mean value within the species range. enter image description here

I have 1500+ species distribution range in a gdb file so I try to use R to do all steps.

library(rgdal) 
library (raster)
library(maptools)

#import species distribution range
data(species distribution range map)
test.sp <- readOGR(species distribution range map)
plot(test.sp, main="test.sp")

#import value map
r <- raster(the world map which has values)
#crop two maps and take the overlap range
r2 <- crop(r, extent(test.sp))
r3 <- mask(r2, test.sp)
plot(r3)
plot(test.sp, add=TRUE, lwd=2, main="crop_pic")

#catch the mean value of the overlap range-1
me <- mean(r3) 
me
#failed: no mean value.

#catch the mean value of the overlap range-2
mea <- calc(r3, fun = mean) 
mea
#failed: no mean value
#unable to find an inherited method for function ‘calc’ for signature ‘"RasterLayer", "RasterLayer"


##catch the mean value of the overlap range-3
mean <- extract(r3)
mean

Now I have a problem about mean value: I use three method to extract the mean value, but they all exclude mean value. Here is the result:

class : RasterLayer dimensions : 403, 167, 67301 (nrow, ncol, ncell) resolution : 0.01012254, 0.008160005 (x, y) extent : 127.2908, 128.9813, -0.9966684, 2.291813 (xmin, xmax, ymin, ymax) crs : +proj=longlat +datum=WGS84 +no_defs source : memory names : layer values : 3.954309e-05, 41 (min, max)

How to fix code to solve this?

3
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.
    – Community Bot
    Sep 11, 2021 at 17:16
  • 1
    Welcome to GIS SE. Thank you for taking the Tour, but you seem to have missed the part that emphasized the One question per Question policy. Providing a bullet list of questions is a quick route to closure. Please Edit the Question to focus on your most pressing problem.
    – Vince
    Sep 11, 2021 at 17:43
  • Thanks for the tip! I have edited!
    – CTY
    Sep 12, 2021 at 11:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.