2012年8月8日星期三

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;
 else{
 for(i=1;i<=NF;i++)
 {
 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

没有评论:

发表评论