Solved

Raster Cell Value Replacer: How to extract cell value


Badge

I have a continuous raster with cell values between 0 and 100. I want to reclassify these values to 5 classes:

For example everything between 90 and 100 should have the new cell value 1.

I do not know how to extract the cell values to make them accessible for the conditional comparison.

 

In the screenshot you can see my current approach. The problem is @CurrentAttribute() which is the wrong choice to extract the cells.

What's the correct way to extract the cell value?

 

icon

Best answer by jdh 11 July 2019, 16:33

View original

10 replies

Badge

This is how I define the new values:

Badge +22

I don't think you can do this with a single RasterCellValueReplacer (RCVR).

 

Either chain as many RCVR as you have classes, making sure the new value isn't in the range of any of the subsequent classes.

 

 

Or use a RasterExpressionEvaluator with nested conditionals

if (A[0] >90, 1, if (A[0]>80, 2, if (A[0]>10, 3,0)))

Badge

I don't think you can do this with a single RasterCellValueReplacer (RCVR).

 

Either chain as many RCVR as you have classes, making sure the new value isn't in the range of any of the subsequent classes.

 

 

Or use a RasterExpressionEvaluator with nested conditionals

if (A[0] >90, 1, if (A[0]>80, 2, if (A[0]>10, 3,0)))

Thanks! However, this does not work quite yet – I have either the new class 1 or 0 (NoData). It never gets into class 2 or 3 even though it should be getting there according to the source data.

Badge +22

Thanks! However, this does not work quite yet – I have either the new class 1 or 0 (NoData). It never gets into class 2 or 3 even though it should be getting there according to the source data.

Which option are you using?

Badge

Which option are you using?

Like this, with RasterExpressionEvaluator

Badge +22

Like this, with RasterExpressionEvaluator

Could you provide your full expresion

Badge +22

Could you provide your full expresion

The following expression matches your original conditionals:

 

 

if (A[0]>=@Value(A:Suburban)&&A[0]<@Value(A:Residential),1,if (A[0]>=@Value(A:Urban)&&A[0]<@Value(A:Suburban),2,if (A[0]>=@Value(A:DenseUrban)&& A[0]< @Value(A:Urban),3,if(A[0]<@Value(A:DenseUrban),4,0))))

 

 

but if you don't have data above your residential value it can be simplified to

 

if (A[0]>=@Value(A:Suburban,1,if (A[0]>=@Value(A:Urban),2,if (A[0]>=@Value(A:DenseUrban,3,4)))
Badge

The following expression matches your original conditionals:

 

 

if (A[0]>=@Value(A:Suburban)&&A[0]<@Value(A:Residential),1,if (A[0]>=@Value(A:Urban)&&A[0]<@Value(A:Suburban),2,if (A[0]>=@Value(A:DenseUrban)&& A[0]< @Value(A:Urban),3,if(A[0]<@Value(A:DenseUrban),4,0))))

 

 

but if you don't have data above your residential value it can be simplified to

 

if (A[0]>=@Value(A:Suburban,1,if (A[0]>=@Value(A:Urban),2,if (A[0]>=@Value(A:DenseUrban,3,4)))

It still does not really work.

I attached a sample raster, do you achieve a classification into 5 classes with RasterExpressionEvaluator?

freiflaeche.tif

Badge +22

It still does not really work.

I attached a sample raster, do you achieve a classification into 5 classes with RasterExpressionEvaluator?

freiflaeche.tif

Put a RasterBandNodataRemover before the RasterExpressionEvaluator.

 

 

Bad things happen when there is a NoData value set.

 

 

I would use the expression

 

if (A[0]==0,0,if (A[0]>=@Value(A:Suburban,1,if (A[0]>=@Value(A:Urban),2,if (A[0]>=@Value(A:DenseUrban,3,4))))

 

and then you can use a RasterBandNoDataSetter to put back the NoData.
Badge

Put a RasterBandNodataRemover before the RasterExpressionEvaluator.

 

 

Bad things happen when there is a NoData value set.

 

 

I would use the expression

 

if (A[0]==0,0,if (A[0]>=@Value(A:Suburban,1,if (A[0]>=@Value(A:Urban),2,if (A[0]>=@Value(A:DenseUrban,3,4))))

 

and then you can use a RasterBandNoDataSetter to put back the NoData.

great thanks!

this works :-)

just found out about NoData too in this article: https://knowledge.safe.com/articles/1221/elevation-zoning-scenario.html

Reply