1

I am modelling the response of a bird (skylark) to various climatic and topographical variables in the program R. Using the predict function I predicted the abundance per pixel (see below for code). I would now like to export my three rasters into ArcGIS 10.2? How do I do that?

Can i add the ref coords. using ArcGis or is it easy to do in R? Is there a faster way predict the density? (I am happy to map on density without the errors initially?

library(raster)
 # Load the raster layers of the predictors for the entire landscape as a stack.
nsw.stack <- stack(list.files(pattern="tif$", full.names=FALSE))
names(nsw.stack) <- c("riv","lake","ndvi","temp","prec","dem")
summary(nsw.stack)
class : RasterStack 
dimensions : 2129, 1905, 4055745, 6 (nrow, ncol, ncell, nlayers)
resolution : 0.008926991, 0.008926991 (x, y)
extent : 55.99709, 73.003, 43.99541, 63.00097 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
names : riv, lake, ndvi, temp, prec, dem 

Then I used the predict function to map the data using my best ranked model (t5)

skylark.psi <- predict(t5, type="state", newdata=nsw.stack)
plot(skylark.psi, ylab="psi - GLM")
> skylark.psi
class : RasterStack 
dimensions : 2129, 1905, 4055745, 4 (nrow, ncol, ncell, nlayers)
resolution : 0.008926991, 0.008926991 (x, y)
extent : 55.99709, 73.003, 43.99541, 63.00097 (xmin, xmax, ymin, ymax)
coord. ref. : NA 
names : Predicted, SE, lower, upper 
min values : 2.987641e-05, 1.275741e-05, 1.293780e-05, 6.899167e-05 
max values : 779.48502, 85.93247, 675.88093, 898.97033 
radouxju
50.2k2 gold badges72 silver badges144 bronze badges
asked Jun 10, 2016 at 11:27

2 Answers 2

1

you can write your raster object to a file using writeRaster from the raster package. Most file formats will be supported by ArcGIS, personnally I use tif a lot.

writeRaster(skylark.psi, file="skylark.tif")

This will create a multiband raster. You can use bylayer=TRUE for multiple single band raster outputs .

Your projection could be specified afterwards using Define projection in ArcGIS when you add it to the dataframe (or you can use "proj4string" in R).

proj4string(skylark.psi) <- CRS("+init=epsg:4326") 

note that 4326 is the epsg code for your WGS84 CRS. See spatialreference.org to get PROJ4 or epsg code for your CRS.

answered Jun 10, 2016 at 12:18
4
  • Do I have to unstack the raster object prior to using writeRaster? Or could I write code like this: writeRaster(skylark.psi$Predicted, file="skylark.tiff") Commented Jun 10, 2016 at 12:39
  • see my edit for multiple single bands instead of single multiband. Commented Jun 10, 2016 at 13:07
  • Thanks radouxju. How do I know which of my single band raster outputs is which? Commented Jun 10, 2016 at 13:18
  • thanks figured it our. Where do you look for the epsg code? Is there a website. Commented Jun 10, 2016 at 14:29
0

You could just use the "filename" argument in the raster::predict function. To bring up help for raster predict specifically use ?raster::predict and you can see the additional arguments that are available. It can be confusing because predict is an R generic and you are effectively calling two predict functions, with two sets of arguments, one for your actual model and one for raster.

predict(t5, type="state", newdata=nsw.stack, filename = "skylark.tiff", progress="window") 

This will skip the step of creating a temporary object and then using writeRaster to write it to a different file and format. Using the file extension is enough for defining most common formats and you should not have to use the format argument. If the projection is defined for the raster stack it will be assigned to the output file as well. The "..." argument allows you to pass specific arguments to a given models predict function.

answered Jun 10, 2016 at 13:42
1
  • Thanks Jeffrey. So in the code above once the raster has been "predicted" it will be added to my stack, and to my drive where my rasters that form the stack are stored? Is that correct? Commented Jun 10, 2016 at 14:03

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.