Skip to main content

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(At0]==0,22,if(Ar0]==1,22,if(Ao0]==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.

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.


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.


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.


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