[R-sig-Geo] insert NODATA_value -999.0 into asc file

Johannes Signer j.m.signer at gmail.com
Mon Jun 20 23:11:51 CEST 2011


Hello,

I would do that on a command line not R:

echo "ncols         601
nrows         351
xllcorner     100000.0
yllcorner     250000.0
cellsize      1000.0
0 0 0 0 0 0
0 0 0 0 0 0" > test.asc

head -n 5 test.asc > tmp_header
awk 'NR>5{print $0}' test.asc > tmp_body
echo NODATA -999.0 >> tmp_header
cat tmp_header rest.asc > new.asc
mv new.asc test.asc
rm tmp_header tmp body

You can easily wrap a loop arround it to apply it to a  few thousand rasters.

Of course you could do it also in R with readLines().

Hope this helps
Johannes

On Mon, Jun 20, 2011 at 4:51 PM, Alexander Arpaci
<alexander.arpaci at boku.ac.at> wrote:
> Dear List,
>
> I have a large number (several thousand) of asci files which were
> delivered to me without a NODATA_value  -999.0 line in the header
> I can´t use them with the raster package like that so far.  I got an
> error message about the missing NODATAVAL when I try to read it into a
> raster object.
> Does somebody have a suggestion how to insert that line into my existing
> asci files?
> I can´t really figure out how do insert that row in line number 5
> without replacing the old line 5...especially with a format like that
> ncols         601
> nrows         351
> xllcorner     100000.0
> yllcorner     250000.0
> cellsize      1000.0
> NODATA_value  -999.0
>
> while the other rows have 601 entries
> every help apreciated
> alexander
>
>
>
>
>
>
> MSc. Alexander Arpaci
> Assistant researcher
>
> Department of Forest - and Soil Sciences
> Institute of Silviculture
> Tel. +43-1-47654-4081
> e-mail: alexander.arpaci at boku.ac.at
> www.wabo.boku.ac.at
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



More information about the R-sig-Geo mailing list