Skip to content

help on "non-square" problem when using write.asciigrid

3 messages · Yong Li, Edzer Pebesma, Roger Bivand

#
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
#
Yong Li wrote:

            
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

--
Edzer
#
On Tue, 7 Mar 2006, Edzer J. Pebesma wrote:

            
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.