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

Edzer Pebesma edzer.pebesma at uni-muenster.de
Mon Jul 7 12:17:40 CEST 2008


Paulo,

Please note that there is also an

as(d[1], "matrix")

but that it returns the matrix in a different organization.

Please find out which one suits you best; the help of ?image has all 
information how image assumes image matrices to be organized, and thus 
how as.image.Spatial... converts it---it is not the typical one that a 
geographer or person used to a raster GIS would think of.
--
Edzer

Michael Sumner wrote:
> 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
>>
>>
>>
>>
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

-- 
Edzer Pebesma
Institute for Geoinformatics (IfGI), University of Münster, Weseler
Straße 253, 48151 Münster. Phone: +49 251 8333081 Fax: +49 251 8339763
email: edzer.pebesma at uni-muenster.de http://ifgi.uni-muenster.de/




More information about the R-sig-Geo mailing list