[R-sig-Geo] going from R to ESRI grids

Roger Bivand Roger.Bivand at nhh.no
Thu Jan 6 18:45:12 CET 2005


On Thu, 6 Jan 2005, Darla Munroe wrote:

> Just wondering if others have worked with this, and if I am missing
> something totally obvious to make this simpler, apologies for my ignorance -
> 

These are the interesting differences in world-view, like oceanographers
reversing depth (1 to deep) from topographers (1 to high). Many
images/rasters have the rows in reverse order to matrices, and I think
this is what you've met.

> 
>  
> 
> OK - it is my understanding that when you reshape a vector (nx1) into a
> matrix in R, it reads the matrix by columns, correct?  I discovered that if
> you read a vector into GRID, it will read the matrix by rows.  Therefore, it
> seems that if you want to take a column vector in R and reshape it to a
> matrix in R, you should take the transpose of that column vector before
> forming it to a matrix.  Correct?
> 
>  
> 
> SO - let's say for example I generated a random uniform column vector 16x1
> which I was assuming to represent a 4x4 grid, and then I created a 4x4
> neighborhood for that grid, then a matrix from that neighborhood (wrk16),
> and calculated a spatial moving average:
> 
>  
> 
> grid1 -> 0.3 * wrk16 %*% grid + grid
> 
>  
> 
> The result is again a 16x1 column vector - now let's say I want to output
> this and read it into GRID - should I reshape it into a 4x4 matrix of the
> transpose of the grid1 column vector?
>  
> 
> That's the best I can figure out.  Seems logical.  BUT, I opened up a grid
> whose values I knew, and the southwest corner of the source data was the
> northwest corner of the resulting grid.  If I don't do a transpose, the data
> are definitely not correct.
> 
> 

Try grid1[nrow(grid1):1,] to reverse the row order, possibly after the 
transpose.  
 
Roger

> 
> Thank you,
> 
> Darla Munroe
> 
> 
> 	[[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
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Breiviksveien 40, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
e-mail: Roger.Bivand at nhh.no




More information about the R-sig-Geo mailing list