Skip to main content
Solved

Raster Cell Value Replacer: How to extract cell value


Forum|alt.badge.img

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?

 

Best answer by jdh

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)))

View original
Did this help you find an answer to your question?
This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

10 replies

Forum|alt.badge.img
  • Author
  • July 11, 2019

This is how I define the new values:


jdh
Contributor
Forum|alt.badge.img+36
  • Contributor
  • Best Answer
  • July 11, 2019

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)))


Forum|alt.badge.img
  • Author
  • July 11, 2019
jdh wrote:

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.


jdh
Contributor
Forum|alt.badge.img+36
  • Contributor
  • July 11, 2019
oiram wrote:

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?


Forum|alt.badge.img
  • Author
  • July 11, 2019
jdh wrote:

Which option are you using?

Like this, with RasterExpressionEvaluator


jdh
Contributor
Forum|alt.badge.img+36
  • Contributor
  • July 11, 2019
oiram wrote:

Like this, with RasterExpressionEvaluator

Could you provide your full expresion


jdh
Contributor
Forum|alt.badge.img+36
  • Contributor
  • July 11, 2019
jdh wrote:

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)))

Forum|alt.badge.img
  • Author
  • July 11, 2019
jdh wrote:

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


jdh
Contributor
Forum|alt.badge.img+36
  • Contributor
  • July 11, 2019
oiram wrote:

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.

Forum|alt.badge.img
  • Author
  • July 11, 2019
jdh wrote:

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings