small islands, how to eliminate?

Michael Shapiro shapiro at zorro.cecer.army.mil
Fri Oct 23 11:40:08 EDT 1992


|
|Does anyone know a method to remove single pixel islands either in cell map or vector map
|? I'm trying to export a grass file to arc.info and need fewer than 10,000
|polygons for it to work.
|Thanks,
|Mary Ingham
|mingham at grits.valdosta.peachnet.edu
|
|
This r.mapcalc expression should work for single pixel islands in a raster map.
This looks at the 8 pixels surrounding a pixel. If they are all
the same value then it replaces the pixel with this common value.
The purpose is to remove single pixel "islands" and it is done
by replacing the island value by the value of the surrounding pixels.
It will NOT work if the "island" contains more than 1 pixel and it will
not work for "pixel islands" at the edges of the map.

The script takes the upper left corner as the common value: map[-1,-1]

(Put this in a file and replace "map" with the map name you want islands
removed from, and "result" by the map name to hold the resultan map.
Then run r.mapcalc < file)

result = if (map[-1,-1] == map[-1,0] && map[-1,-1] == map[-1,1] && \
             map[-1,-1] == map[0,-1] && map[-1,-1] == map[0,1]  && \
             map[-1,-1] == map[1,-1] && map[-1,-1] == map[1,0]  && \
             map[-1,-1] == map[1,1],                               \
	     map[-1,-1], map)


-----------------------------------------------------------------
Michael Shapiro                        U.S. Army CERL                  
email:   shapiro at zorro.cecer.army.mil  Environmental Division          
phone:   (217) 373-7277                P.O. Box 9005                   
fax:     (217) 373-7222                Champaign, Ill. 61826-9005
-----------------------------------------------------------------




More information about the grass-user mailing list