[R-sig-Geo] help on "non-square" problem when using write.asciigrid
Roger Bivand
Roger.Bivand at nhh.no
Tue Mar 7 09:21:10 CET 2006
On Tue, 7 Mar 2006, Edzer J. Pebesma wrote:
> Yong Li wrote:
>
> >Dear Friends,
> >
> >Can anybody help me for the subject?
> >When I tried to use write.asciigrid to export a spatialgrid to esri
> >ascii grid, I always failed because of the message "non-square grid
> >is not support" even I knew my grid is 100% squared.
> >Yong
> >
> It means that your grid cells are not square, i.e.
> they have a different size in x and y direction. Such
> a feature is not supported by the asciigrid format.
> As an example,
>
> > library(sp)
> > data(meuse.grid)
> > gridded(meuse.grid) = ~x+y
> > diff(gridparameters(meuse.grid)$cellsize)
> [1] 0
The line in writeAsciiGrid() in the maptools package is:
gp = gridparameters(x)
if (gp$cellsize[1] != gp$cellsize[2])
stop("Asciigrid does not support grids with non-square cells")
which might be misled by numeric fuzz. (This is the same as
write.asciigrid() in the sp package). If x is your SpatialGridDataFrame
object, what does:
print(slot(slot(x, "grid"), "cellsize"), digits=20)
say? If they differ only by fuzz, you could use brute force and say:
slot(slot(x, "grid"), "cellsize") <-
rep(mean(slot(slot(x, "grid"), "cellsize")), 2)
or round them to equality (not tried, only for exporting, the bounding
box will get messed up by this).
As far as I know from the GDAL list, in fact the restriction may be
spurious, that is while GDAL drivers for Arc ASCII grids required square
cells, recent Arc software requires rectangular cells, but I'm not sure,
not checked against Arc documentation.
>
> --
> Edzer
>
--
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