Dear R colleagues, Currently, I am working with the vegetation map published by SAGE (http://www.sage.wisc.edu/download/potveg/global_potveg.html). This map is published in netcdf and I can easily load it into R using the package "raster". But I have found another vegetation map (also netcdf, same resolution) which is more realistic to my work region. Thus, what I need to do is overlay the two maps, but using a clip feature (i.e. a shapefile of South America) as a delimiter to this operation, in order to capture the information of the newest map. I am trying to use the "overlay" function of raster package, but apparently it isn't possible (or I am missing something) to use a clip feature to restrain the spatial domain of the operation. Any tips on how to do this? Below is the code I am using. Best wishes, Thiago Veloso. #Loading required packages library(raster) library(maptools) #Loading SAGE vegetation map vegmap<-raster("C:/temp/vegmap_ibis/data/vegtype.nc") #Loading new vegetation map new_vegmap<-raster("C:/temp/vegmap_ibis/data/new_vegtype.nc") #Loading SA shapefile south_america<-readShapePoly("C:/temp/vegmap_ibis/shapes/southamerica.shp") #Replacing the original map with the modified one result<-overlay(vegmap,new_vegmap,fun=function(x){x}) #this is where I stop - I don't know how to use the shapefile as a clip feature in this function...
How to overlay two rasters limiting the spatial domain
2 messages · Thiago V. dos Santos, Robert J. Hijmans
1 day later
Thiago, You can use the 'crop' function. Best, Robert
?Dear R colleagues, ?Currently, I am working with the vegetation map published by SAGE (http://www.sage.wisc.edu/download/potveg/global_potveg.html). This map is published in netcdf and I can easily load it into R using the package "raster". ?But I have found another vegetation map (also netcdf, same resolution) which is more realistic to my work region. Thus, what I need to do is overlay the two maps, but using a clip feature (i.e. a shapefile of South America) as a delimiter to this operation, in order to capture the information of the newest map. ?I am trying to use the "overlay" function of raster package, but apparently it isn't possible (or I am missing something) to use a clip feature to restrain the spatial domain of the operation. ?Any tips on how to do this? Below is the code I am using. ?Best wishes, ?Thiago Veloso. #Loading required packages library(raster) library(maptools) #Loading SAGE vegetation map vegmap<-raster("C:/temp/vegmap_ibis/data/vegtype.nc") #Loading new vegetation map new_vegmap<-raster("C:/temp/vegmap_ibis/data/new_vegtype.nc") #Loading SA shapefile south_america<-readShapePoly("C:/temp/vegmap_ibis/shapes/southamerica.shp") #Replacing the original map with the modified one result<-overlay(vegmap,new_vegmap,fun=function(x){x}) #this is where I stop - I don't know how to use the shapefile as a clip feature in this function...
-- View this message in context: http://r-sig-geo.2731867.n2.nabble.com/How-to-overlay-two-rasters-limiting-the-spatial-domain-tp6372927p6378456.html Sent from the R-sig-geo mailing list archive at Nabble.com.