[R-sig-Geo] Problem in creating esri grid from SpatialGridDataFrame

Roger Bivand Roger.Bivand at nhh.no
Sat Jun 30 15:35:07 CEST 2007


On Fri, 29 Jun 2007, Debarchana Ghosh wrote:

> Hello,
>
> I'm running R in windows with 2 GB Ram and 120 GB hard drive
>
> I have created a SpatialGridDataFrame object by using the functions
> GridTopology and spkernel2d.
>
> Here is the code:
> bird06.xy<-coordinates(splanc_bird06[1:2])
> grd1<-GridTopology(c(419983.3, 4924198), c(30,30), c(3375,3499))
> k5000<-spkernel2d(bird06.xy, splanc_bird06$poly, h0=5000, grd1)
> df<-data.frame(k5000=k5000)
> kernel5000<-SpatialGridDataFrame(grd1, data=df)
>
> Now I want to write kernel5000 into a ESRI readable grid/raster
> I used the following function:
>
> write.asciigrid(kernel5000, fname="kernelbird06.ag")
> Error: cannot allocate vector of size 92258 Kb
>
> I have three questions:
> 1. what is the solution to work around the memory problem? The computer has
> 2 GB of ram

You might try to call gc() several times to flush unused temporary 
objects, but your ~ 16M cell raster object is quite large. The 
writeAsciiGrid() function in maptools (your version is in sp and not 
maintained as such) converts the raster from 8 byte to about 20 byte 
character representation. I personally would have used writeGDAL() in 
rgdal, writing to a GTiff file - in Arc, you'll need to adjust the 
symbology, because Arc doesn't automatically understand the many small 
density values.

> 2. How can I read/open the .ag file in ESRI ArcMap or ArcCatalog. I tried
> the example in the write.asciigrid manual page but I could not read/open the
> .ag file in ArcMap

I believe it doesn't recognize the extension, try *.txt or *.aai, or open 
All files.

> 3. Is write.asciigrid the correct function to write spatialGridDataFrame
> object in ESRI readable grid format?

The writeGDAL() function in rgdal supports many more drivers, including 
GTiff, which seems robust. From 9.2, ArcGIS is also uding the same 
underlying GDAL library for some raster file exchange operations.

Hope this helps,

Roger

>
> Thanks,
> Debs.
>
>
>

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




More information about the R-sig-Geo mailing list