r:r-gis:raster

# 1-Raster Operations

### all usual formats

#e.g. tiff:
RasterLayer=raster("rasterLayer.tiff")

### Several layers as RasterStack

All operations for RasterStacks work the same as for RasterLayers. They are performed for each layer in the stack.

  RasterStack=stack("rasterLayer1.tiff",
"rasterLayer2.tiff","rasterLayer3.tiff")

### HDF Files (zb MODIS)

  library(MODIS)
tmp=getSds("rasterLayer.hdf")

## Identify Patches

patches<-clump(rasterLayer)

## Statistics on Patches (size, shape, etc)

library(SDMTools)
PatchStat(patches)

## Cost analysis

This fuction comes from the gdistance package. For a cost analysis, a cost raster is required where the values contain the “cost” to cross the respective cell. Further, a start and end point is required.

  costraster=RasterLayer
start=SpatialPoint1
end=SpatialPoint2

### Least Cost Path

Connect start and end point by the way of minimal costs:

  tr=transition(costraster, function(x) 1/mean(x), directions=8)
trC=geoCorrection(tr)
CostPath=shortestPath(trC, start, end,output="SpatialLines")

Show results:

  plot(costraster)
lines(CostPath)
points(rbind(start,end))

### Akkumulate costs

For each cell, the accummulated costs to the start point are calculated.

  accCost(trC,start)