Question

Select certain colours in raster to become a polygon

  • 17 March 2015
  • 2 replies
  • 6 views

Hi,

 

 

I have a raster file which identifies vegetation. There is a distact background colour, and then levels of green identify vegetation. 

 

I'm looking to identify certain rgb values of the vegetation and transform into polygon.

 

 

I've tried RasterExpressionEvaluator and then RasterPaletteExtractor but I keep having errors.

 

Is there something simple like a tester where I could test;

 

if ( A[0]!=210 && A[1]!=180 && A[2]!=140 && A[3]!=255 )

 

     output ;

 

 

 

 

2 replies

Userlevel 2
Badge +17
Hi,

 

 

The "if" function in the expression for the RasterExpressionEvaluator requires three arguments.

 

1st: test condition for a cell value

 

2nd: the replacement value if the condition was true

 

3rd: the replacement value if the condition was false

 

 

Takashi
Badge +3
Hi,

 

In a script to "trace" lines in a grayscale raster, i use RasterExpressionEvaluator like you do, but like Takashi says it needs 3 arguments.

 

 

I replace the unwanted values by a no-data value, wich you set first.

 

 

if(A[0]== 4 || A[0]== 16 || A[0]== 32 || A[0]== 36 || A[0]== 46 || A[0]== 48 || A[0]== 14 || A[0]== 54 || A[0]== 50 || A[0]== 2,0,A[0])

 

All unwanted values are set to value =0, Rest keep their value, in my case A[0].

 

Then i used a RasterCellCoercer with ExtractNoDataValues=No  to only keep the cells i want (that is rest have no data in subsequents stages of the proces).

 

(you can also use RasterCellValueReplacer to simpify or clean unwanted colours).

 

 

You cannot just "select" cells, as it is always a raster wich is  rectangular. You always select all cells by default, so you must set the ones you do not want to participate in some proces to, most commonly done to some no data value.

 

 

 

Reply