Solved

Extract pixels with given values from an ERDAS .img file

  • 6 January 2018
  • 7 replies
  • 24 views

Hello,

I am trying to extract from a huge ERDAS .img file specific pixels (i.e. with given values). At the moment, I am totally unable to expose pixel values as an attribute that I will then able to filter. The objecive is to create distinct polygons for each selected values.

The raster file consists of a single band and has 2 palettes:

The image contains many classes I am not interseted in, so, before using a RasterToPolygonCoercer, I would like to be able to filter some classes (either on their integer value, for instance 5, or on their string value, for instance Soybeans). The final goal is to compute for each US county the percentage covered by each selected crops.

Any idea on how to achieve this?

 

Best regards

PS: raster layer is available here

icon

Best answer by takashi 6 January 2018, 15:55

View original

7 replies

Userlevel 2
Badge +17

Hi @asherk, if I understand the requirement correctly, this workflow might help you.

The point is how to find the mapping rule between pixel values and land-use (farm crop?) classes, based on the Palette 1. You can use the RasterPaletteExtractor to extract a selected palette definition as a text string, and then parse it to create features each of which has a pixel value and a class name. See also the help on the RasterPaletteExtractor to lean more about the format of palette definition.

Hi @asherk, if I understand the requirement correctly, this workflow might help you.

The point is how to find the mapping rule between pixel values and land-use (farm crop?) classes, based on the Palette 1. You can use the RasterPaletteExtractor to extract a selected palette definition as a text string, and then parse it to create features each of which has a pixel value and a class name. See also the help on the RasterPaletteExtractor to lean more about the format of palette definition.
Thanks @takashi for your answer. I tried to implement it with FME 2017.1 but I face an issue: where does the __label attribute comes from? I am able to use an AttributeExposer to expose it after the RasterToPolygonCoercer, but which transformer is supposed to output this attribute in the "lower" branch?

 

 

Regards

 

 

Userlevel 2
Badge +17

Hi @asherk, if I understand the requirement correctly, this workflow might help you.

The point is how to find the mapping rule between pixel values and land-use (farm crop?) classes, based on the Palette 1. You can use the RasterPaletteExtractor to extract a selected palette definition as a text string, and then parse it to create features each of which has a pixel value and a class name. See also the help on the RasterPaletteExtractor to lean more about the format of palette definition.
If your question was how to avoid generating polygons except area having your interested crop (e.g. cell value = 5), the RasterExpressionEvaluator and the RasterBandNodataSetter might help you.

 

In this example, the RasterExpressionEvaluator replaces all cell values except 5 with 0, and the RasterBandNodataSetter defines 0 as the Nodata. Then, the RaseterToPolygonCoercer (Extract Nodata Values: No) creates only polygons which have the value 5. The RasterPaletteRemover is essential in this workflow.

 

 

@takashi, great!!!

Exactly was I was trying to do, especially with the last tip to set nodata for classes not of interest!

Thanks

@takashi, I think I manage to construct the workbench I expected. However, it seems that it works only for the image reflecting the 2016 crops. When I try with other image (for instance 2014 or 2015), I got an issue with the RasterExpressionEvaluator which does not give the expected output (I it able to filter a single pixel value, but when I try with several value it outputs 0 featurecreate-crops-masks2.fmw). I attach my workbench with a comment on the problematic transformer. Hope you could help.

Regards

Userlevel 2
Badge +17

@takashi, I think I manage to construct the workbench I expected. However, it seems that it works only for the image reflecting the 2016 crops. When I try with other image (for instance 2014 or 2015), I got an issue with the RasterExpressionEvaluator which does not give the expected output (I it able to filter a single pixel value, but when I try with several value it outputs 0 featurecreate-crops-masks2.fmw). I attach my workbench with a comment on the problematic transformer. Hope you could help.

Regards

The RasterExpressionEvaluator may not work as expected if the source raster has Nodata definition originally. Read the raster with FME Data Inspector (Feature Information Window) to check if it has Nodata.

 

If the raster had Nodata, remove it with the RasterBandNodataRemover beforehand.

 

 

@takashi, I think I manage to construct the workbench I expected. However, it seems that it works only for the image reflecting the 2016 crops. When I try with other image (for instance 2014 or 2015), I got an issue with the RasterExpressionEvaluator which does not give the expected output (I it able to filter a single pixel value, but when I try with several value it outputs 0 featurecreate-crops-masks2.fmw). I attach my workbench with a comment on the problematic transformer. Hope you could help.

Regards

Perfect @takashi! I was not aware of this.

 

Reply