Reclass ascii grid with awk

I had to reclass a large number of grids (20000+) on a server without any GIS installed. So my choice was awk.

BEGIN {FS=" ";}
 if (NR < 7) print $0;
 if ($i == "-9999") res=-9999;
 else if ($i < a) res=0;
 else res=1;
 printf "%s ", res;
 } printf "\n";

The script requires as a parameter a a threshold. Every value below this threshold is classified as 0 and every value above as 1. No data values (-9999) are not affected. Once the script is saved to reclass.awk, it can be calle with:

awk -v a=0.4 -f reclass.awk ingrid.asc > outgrid.asc

This entry was posted in awk, BASH, Computer. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s