Dear Robert,

Glad to read the problem occurs on other computers too. I contacted the author of the package.

As a workaround I corrected the cell size of the produced .asc file (which had 1 row and 1 column too many and a too small cell size). Then I cropped the file using the correct dimensions (= cutting off the unwanted extra 1 row and 1 col). It's a bit quick and dirty, but at least it works.

My aim is to get the soil data of the Harmonized World Soil Database, with a separate .asc file for each soil variable. HWSD offers a global .bil file with soil codes as attribute value and a .mdb file with the real, continuous values of soil variables for each soil code. I read the .bil file, crop it to the extent of my study area, for each grid cell replace the soil code by the real soil values, and finally export the object as .asc file.

Thanks again for helping!


André


From: Robert J. Hijmans [mailto:r.hijmans@gmail.com]
Sent: donderdag 15 november 2012 18:40
To: Proosdij, Andre van
Cc: r-sig-geo@r-project.org
Subject: Re: [R-sig-Geo] asc2dataframe and dataframe2asc problem with ncols nrows and cell size

André,

This looks like a bug. It would be appropriate to contact the author of the package to report this.

To see the problem, there is no need for Notepad or similar, you can compare

raster("d:/layer.asc")
# with
r

# or
dim(raster("d:/layer.asc"))
dim(r)

To work around it there are probably many options, e.g., x = as.data.frame(r, xy=T) but I do not know what you want to achieve, so I cannot comment on that except that your approach to first write an ascii file to then create a data.frame seems convoluted.

Best, Robert

	[[alternative HTML version deleted]]

