[GRASS-user] Fill holes with an area bigger of a specific value in a raster coverage

Nick Ves vesnikos at gmail.com
Thu May 1 11:00:46 PDT 2014


On Tue, Apr 29, 2014 at 11:07 PM, Markus Neteler <neteler at osgeo.org> wrote:
> On Tue, Apr 29, 2014 at 6:48 PM, Jorge Arevalo
> <jorgearevalo at libregis.org> wrote:
>> I want to fill some areas of a raster coverage with a value of my choice.
>> Those areas now contain NODATA values. So, they look like holes in my
>> coverage.
>
> If you want to set all NODATA area to the same value, then use r.null
> with null=yourvalue:
>
> http://grass.osgeo.org/grass70/manuals/r.null.html#examples
>
>
>> I know I could use r.clump function , but I don't know how to specify the
>> maximum area. Because if a hole is bigger than that area, I don't want to
>> consider it as hole. Is that even possible with GRASS?
>
> You could assign all NODATA areas a specific, yet unused value (see above).
> Then extract this value with r.mapcalc (if condition) and extract from
> the resulting map only the smaller areas with
>
> http://grass.osgeo.org/grass70/manuals/r.reclass.area.html
>
> Then merge them back with r.patch into the original maps in order to
> create the final map.
>
> Maybe there are other possibilities, too.

You can try and parse the output or r.report of a "valid data map" eg:

1) r.mapcalc "in.valid = if(isnull(in))?1:2"

2) r.clump input=in.valid out=in.clump

3) r.report -h map=in.clump out=report units=me

here's a small python snippet which parses the report file which was
created in step3 and writes in a file which clumps you are intrested
at:

'''''
import fileinput
import locale
locale.setlocale( locale.LC_ALL, 'en_US.UTF-8' )
t = []
threshold = 100 #<- threshold in sq meters since r.report is reporting in meters
for l in fileinput.input(['report']):
        try:
            if locale.atof((l.split("|")[3])) > threshold:
                t.append(l.split("|")[1])
        except:
            continue

with open('somefile.txt', 'w') as f:
    for x in t:
        f.write(str(x) + "\n")
'''''

and now since you know in what holes you want to act upon you can
itterate easy with a little bash:

for hole in $(cat somefile.txt);
    do stuff;
done

>
> Markus
> _______________________________________________
> grass-user mailing list
> grass-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-user


More information about the grass-user mailing list