[R-sig-Geo] importing ascii grids with 15 header lines

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Fri Oct 21 15:08:32 CEST 2011


On Fri, Oct 21, 2011 at 12:29 PM, Matthias Boer <M.Boer at uws.edu.au> wrote:
> Dear list members
>
> I have a very large number of ascii map layers representing interpolated daily weather observations for Australia.
> Each file is an ascii grid with a header consisting of 15 lines (6 lines for the usual header of Arcraster ascii grids plus 9 lines of additional info). I want to import the maps one by one, to compute monthly and annual values, overlay those with veg type maps, etc. I am having trouble with the spatial data formats.
>
> I usually use 'read.asciigrid' to import ascii grids in Arcraster format but this fails here due to the header format. I can read the actual grid data using read.delim and create the GridTopology seperately but then struggle to create a SpatialGridDataFrame or other spatial data format. I assume there is a simple way to do this, but I haven't managed to work it out. Some help from the list would be great.

 GDAL doesn't seem to mind if extra headers come after an initial
NCOLS header. Do your extra bits come before that? That messes up
GDAL's detection. You could bodge this by adding the right NCOLS
header (a duplicate of the NCOLS in the file) at the start of the
file.

  I also tried opening a file connection, reading the header lines I
stuck in, then tried reading the raster from the connection - both
raster and readGDAL failed, but I would have been surprised if it had
worked.

  Others have suggested some general text editing tools - I would also
suggest appropriate use of the ClueBat on whoever created these things
- open geospatial data sets with rich metadata options are hardly
rarities!

Barry



More information about the R-sig-Geo mailing list