Skip to main content
Solved

RasterToPolygonCoercer assign color to output polygons


Forum|alt.badge.img

I have a geotiff image feeding a rasterToPolygonCoercer. I need to assign the value of the output polygons based on the input raster palette and value. How do I feed the MapInfo TAB writer the correct color from the RasterToPolygoneCoercer?

Best answer by takashi

H @jayrussell, if the raster has a palette to define colors, at first you will have to resolve the palette to transform the raster from the single band (palette entry) to 3 bands (color elements: R, G, B). You can use the RasterPaletteResolover here.

The RasterToPolygonCoercer adds an attribute called "_label" to the output polygons, which stores comma separated cell values. In the case where the raster interpretation was RGB24 (3 bands = Red8, Green8, Blue8), each cell value is in the range 0-255.

FME requires comma separated color values normalized in the range 0-1 for setting a color to features, so you also will have to add a process to normalize the color value.

This is an example, assuming that the palette defines RGB24 color.

Hope this helps.

View original
Did this help you find an answer to your question?

8 replies

Forum|alt.badge.img+2

takashi
Influencer
  • Best Answer
  • October 12, 2018

H @jayrussell, if the raster has a palette to define colors, at first you will have to resolve the palette to transform the raster from the single band (palette entry) to 3 bands (color elements: R, G, B). You can use the RasterPaletteResolover here.

The RasterToPolygonCoercer adds an attribute called "_label" to the output polygons, which stores comma separated cell values. In the case where the raster interpretation was RGB24 (3 bands = Red8, Green8, Blue8), each cell value is in the range 0-255.

FME requires comma separated color values normalized in the range 0-1 for setting a color to features, so you also will have to add a process to normalize the color value.

This is an example, assuming that the palette defines RGB24 color.

Hope this helps.


Forum|alt.badge.img
  • Author
  • October 15, 2018
takashi wrote:

H @jayrussell, if the raster has a palette to define colors, at first you will have to resolve the palette to transform the raster from the single band (palette entry) to 3 bands (color elements: R, G, B). You can use the RasterPaletteResolover here.

The RasterToPolygonCoercer adds an attribute called "_label" to the output polygons, which stores comma separated cell values. In the case where the raster interpretation was RGB24 (3 bands = Red8, Green8, Blue8), each cell value is in the range 0-255.

FME requires comma separated color values normalized in the range 0-1 for setting a color to features, so you also will have to add a process to normalize the color value.

This is an example, assuming that the palette defines RGB24 color.

Hope this helps.

Thank you this does help @takashi

 

Is there a way to retain the original palette index that was present before the RasterPaletteResolver? It represents a radar reflectivity dB that I need to retain along with assigning a color.

 


takashi
Influencer
  • October 15, 2018
takashi wrote:

H @jayrussell, if the raster has a palette to define colors, at first you will have to resolve the palette to transform the raster from the single band (palette entry) to 3 bands (color elements: R, G, B). You can use the RasterPaletteResolover here.

The RasterToPolygonCoercer adds an attribute called "_label" to the output polygons, which stores comma separated cell values. In the case where the raster interpretation was RGB24 (3 bands = Red8, Green8, Blue8), each cell value is in the range 0-255.

FME requires comma separated color values normalized in the range 0-1 for setting a color to features, so you also will have to add a process to normalize the color value.

This is an example, assuming that the palette defines RGB24 color.

Hope this helps.

Do you mean that both the palette index and the color value (R, G, B) should be extracted? Or, need to extract only the palette index?

 

 


Forum|alt.badge.img
  • Author
  • October 15, 2018
takashi wrote:
Do you mean that both the palette index and the color value (R, G, B) should be extracted? Or, need to extract only the palette index?

 

 

I only need to extract the palette index as an attribute. I would use the color value (R,G,B) to assign the color to the extracted polygon using your example.

 

 


takashi
Influencer
  • October 15, 2018
takashi wrote:
Do you mean that both the palette index and the color value (R, G, B) should be extracted? Or, need to extract only the palette index?

 

 

OK. In that case, you can just use the RasterToPolygonCoercer. The "_label" attribute will store the palette index.

Forum|alt.badge.img
  • Author
  • October 15, 2018
takashi wrote:
Do you mean that both the palette index and the color value (R, G, B) should be extracted? Or, need to extract only the palette index?

 

 

If I wanted to extract both the palette index and color value how would I retain the palette index through the RasterPaleteResolver in your original example.

 

 


takashi
Influencer
  • October 15, 2018
takashi wrote:
Do you mean that both the palette index and the color value (R, G, B) should be extracted? Or, need to extract only the palette index?

 

 

You can use the RasterBandCombiner to make 4-band raster (palette index, red, green, blue) and then extract comma-separated those values as "_label" attribute in the subsequent RasterToPolygonCoercer.

 

The order of bands (palette index -> color, or color -> palette index) can be controlled by setting the Connection Runtime Order at the output port (right-click > Set Connection Runtime order) where the data flow branches into two streams. e.g. at the Junction in the screenshot below.

 


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