[R-sig-Geo] Spatial analysis - matrix algebra

Michael Sumner mdsumner at utas.edu.au
Mon Jul 7 12:05:02 CEST 2008


Hi Paulo,

You can read ESRI ASCII grids (amongst many others) using rgdal package:

library(rgdal)
d <- readGDAL("file1.asc")

See gdalDrivers() for a listing of the available file formats for your 
package build.

The read above would result in a single-colum SpatialGridDataFrame - 
named "band1". To add further files as a new column (assuming the 
subsequent files have exactly the same grid topology):

d$band2 <- readGDAL("file2.asc")$band1

. . . and so on.

To obtain the resulting raster bands as individual matrices you can use 
as.image.SpatialGridDataFrame:

m1 <- as.image.SpatialGridDataFrame(d[1])$z

m2 <- as.image.SpatialGriddataFrame(d[2])$z

. . .

Then use your matrices as needed.  If you only want the matrices and not 
the intermediate SGDF objects, use readGDAL directly:

m1 <- as.image.SpatialGridDataFrame(readGDAL("file1.asc")[1])
. . .

These could be collected in a single 3-way array, or a list of matrices 
as needed.

HTH,

Mike.


Paulo Cardoso wrote:
> Can R perform matrix algebra between ascii converted Esri grids? I'm
> convinced that its trivial.
>
>  
>
> The question is a little more complex (from my point of view and
> inexperience): I'm interested in perform cost surface and distance surface
> analysis avoiding ArcGIS tools. Maybe R can deal with grid formatted as
> matrices...
>
>  
>
> Maybe R could call FWtools to perform all calculations iteratively...
>
>  
>
> Paulo
>
>  
>
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>
> No virus found in this incoming message.
> Checked by AVG - http://www.avg.com 
> Version: 8.0.138 / Virus Database: 270.4.5/1537 - Release Date: 7/6/2008 5:26 AM
>
>
>
>




More information about the R-sig-Geo mailing list