[R-sig-Geo] Exporting spatstat 'pixel image' to Arcview 9.x as an e00 or ascii

Honey-Marie de la Giroday honeydelagiroday at gmail.com
Tue Jul 12 21:20:40 CEST 2011


@Michael Sumner,

Your suggestion worked, thank you very much for your help!  I was able
to covert from image to "SpatialGridDataFrame" but I now have the
following issue:

#load packages
library(spatstat)
library(maptools)
library(sp)

#load file with model data
load(file="C:/bestmodel2004.RData")

#Plot best model data for 2004
plot(bestmodel2004)

#Coerce Rdata pixel image to SpatialGridDataFrame
BM2004 <- as(bestmodel2004, "SpatialGridDataFrame")

#Did it work?
attributes(BM2004)
plot(BM2004)
summary(BM2004)

#Output to Acrview = write.asciigrid(x, fname, attr=1, na.value=-9999.....
#x=SpatialGridDataFrame
#fname=filename
write.asciigrid(bestmodel2004, fname ="C:/mb2004asc")

***Error in write.asciigrid(BM2004, fname = "C:/mb2004asc") :
  Asciigrid does not support grids with non-square cells****

My first question is, to which cells is this error message referring
(pixels of the grid or the extent of the SpatialGridDataFrame) and has
anyone found a way around this issue?  I found another posting about
this but found the explanation of the resolution is a bit difficult to
understand (a bit like a monkey trying to read braille for the first
time).  See link below.
http://r-sig-geo.2731867.n2.nabble.com/help-on-quot-non-square-quot-problem-when-using-write-asciigrid-td2762098.html
Is there another approach to converting an image (im) to a file format
that is readable by ArcGIS 9.x (AND maintain attributes and
projection/coordinates) or should this monkey go back to trying read
braille.  Thank you for your help!

Sincerely,



HMC

On Mon, Jul 11, 2011 at 8:40 PM, Michael Sumner <mdsumner at gmail.com> wrote:
> Another way is to use the coercion methods in maptools (these are
> considered additional to the basics provided by sp, since they
> provider converters between classes in other packages):
>
> library(maptools)
> as(Im, "SpatialGridDataFrame")
>
> In terms of the data the result is identical to Rolf's method, though
> various attributes will not be.
>
> Cheers, Mike.
>
>
> On Tue, Jul 12, 2011 at 1:30 PM, Rolf Turner <r.turner at auckland.ac.nz> wrote:
>>
>> This is definitely a case of the blind leading the blind, but I thought I'd
>> chip
>> in anyway.
>>
>> Let "Im" be your pixel image.  Do:
>>
>> xy <- as.matrix(as.data.frame(raster.xy(as.owin(Im))))
>> v <- lookup.im(Im,xy[,1],xy[,2])
>> A <- SpatialPixelsDataFrame(points=xy,data=data.frame(v))
>> B <- as(A,"SpatialGridDataFrame")
>>
>> Then "B" is an object of class "SpatialGridDataFrame" which ***may*** be
>> what
>> you need.  I can't really tell, since I don't understand
>> SpatialGridDataFrames.
>>
>> The foregoing is kludgey, almost surely sub-optimal, and quite possibly
>> wrong .....
>> But there's a chance it will be of some use to you.
>>
>>    cheers,
>>
>>        Rolf Turner
>>
>> On 12/07/11 10:54, Honey-Marie de la Giroday wrote:
>>>
>>> Dear All,
>>>
>>> I have a pixel image (im) I received as a .RData file.  I need to
>>> export this pixel image from R in a file format that can be imported
>>> into Arcview 9.x (e.g., .e00 or ascii).
>>>
>>> Below is some of the code that I have been trying to use.  I have
>>> reviewed the manuals for rgdal, maptools, sp, and spatstat packages
>>> but have been unable to find another approach to converting the pixel
>>> image to an Arcview raster dataset.  Please note that I have also
>>> searched the R-sig-geo archives and was unable to find this covered
>>> elsewhere.
>>>
>>> "#load spatst package
>>> library(spatstat)
>>>
>>> #load file with model data
>>> load(file="C:/bestmodel2004.RData")
>>>
>>> #Plot best model data for 2004
>>> plot(bestmodel2004)
>>>
>>> #Examine attributes of pixel image
>>> attributes(bestmodel2004)
>>> $names
>>>  [1] "v"      "dim"    "xrange" "yrange" "xstep"  "ystep"  "xcol"   "yrow"
>>>  [9] "type"   "units"
>>>
>>> $class
>>> [1] "im"
>>>
>>> #Load sp package
>>> library(sp)
>>>
>>> #Coerce bestmodel2004 (pixel image) to SpatialGridDataFrame
>>> #......how do I do this?......
>>>
>>> #Output to Acrview = write.asciigrid(x, fname, attr=1, na.value=-9999.....
>>> #x=SpatialGridDataFrame
>>> #fname=filename
>>> write.asciigrid"
>>>
>>> Thank you for your time, and please let me know if I need to provide
>>> further information.
>>>
>>> Sincerely,
>>>
>>>
>>>
>>> H.M.C de la Giroday
>>>
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> R-sig-Geo at r-project.org
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
>
>
> --
> Michael Sumner
> Institute for Marine and Antarctic Studies, University of Tasmania
> Hobart, Australia
> e-mail: mdsumner at gmail.com
>



More information about the R-sig-Geo mailing list