Solved

Replace raster cell values by table

  • 29 November 2022
  • 5 replies
  • 12 views

Hi,

 

I have a raster in GRAY8 that have cells ranging from 0 to 255. Additionaly I have a translation table with values as such: 

T	pixelvalue
≤ -22 0
-21,92 1
-21,84 2
-21,76 3
-21,69 4
-21,61 5
-21,53 6
-21,45 7
-21,37 8
etc...

I would like to replace every pixel value with its corresponding value in the T column. I have tried to do the following:

1) Trim the "-" sign

2) Round the attribute in the T column to remove the decimal values.

 

My thought after that was to use the attributecreator with:

if(A[0]=@Value(pixelvalue),@Value(T),

And then the aggregator and merge them with concatenation. Then finish it of with brackets to something like this with nested if statements:

if(A[0]==0,22,if(A[0]==1,22,if(A[0]==3,22,...

And feed it into the RasterExpressionEvaluator. This workflow does not seem to work since I can't get the RasterExpressionEvaluator to accept my nested if statements and write many different colors.

 

Any suggestions on how to achieve what I am after? Color my raster based on the matching value in the table.

icon

Best answer by dustin 29 November 2022, 15:43

View original

5 replies

Userlevel 3
Badge +26

Have you looked into the RasterCellValueReplacer? Although, depending on the number of entries in the lookup table it could take a while to input. Maybe uploading your lookup table here would be helpful to us.

Have you looked into the RasterCellValueReplacer? Although, depending on the number of entries in the lookup table it could take a while to input. Maybe uploading your lookup table here would be helpful to us.

Yeah, I have thought about it. This lookup table is 256 rows, and I have more images to process after this one that I suspect have different tables. Therefore a dynamic approach would be preferred.

Userlevel 3
Badge +26

Yeah, I have thought about it. This lookup table is 256 rows, and I have more images to process after this one that I suspect have different tables. Therefore a dynamic approach would be preferred.

Seems like SchemaMapper or DatabaseJoiner could be used with a dynamic lookup table, as long as the column names are consistent between the different datasets. However, I don't think there is a way to apply either of those transformers to a pixel values in a raster. You could potentially use a RasterCellCoercer to convert the raster to vector points, use SchemaMapper or DatabaseJoiner to get new values, then convert back to raster using ImageRasterizer.

Userlevel 4

Yeah, I have thought about it. This lookup table is 256 rows, and I have more images to process after this one that I suspect have different tables. Therefore a dynamic approach would be preferred.

For larger rasters, the approach using the RasterCellCoercer / ImageRasterizer will be hopelessly slow (in my opinion), but it might be OK for small rasters unless speed is critical.

Clearly the fastest and most dynamic solution is going to be through the PythonCaller and the FMERaster object family, although it's definitely not something I'd recommend for beginners.

Userlevel 1
Badge +10

I would suspect an issue with your formula, although i don't know if there are limits on the number of nested statements. Are you getting an error message? Have you remembered to add the statement on the end that tells what to do if no conditions are met?

 

 Edit: it looks like passing the conditional statement via an attribute is still not possible, so maybe this is the actual issue you are encountering?

https://community.safe.com/s/question/0D54Q000080hRjMSAU/rasterexpressionevaluator-and-attributes

 

Reply