Skip to main content
Question

Convert raster to vector grid, populate attributes with colours?

  • September 13, 2018
  • 3 replies
  • 82 views

nicholas
Contributor
Forum|alt.badge.img+10

I have a (4KB) png file I want to convert to a vector grid. I want each pixel in the raster to be its own cell in the vector grid.

I am using RasterCellCoercer

Output Cell Geometery: Polygons

Extract Band Values As: Attributes

Extract Nodata Values: Yes

My question is how do I transfer the colour values of the raster to attribute values in the vector?

3 replies

Forum|alt.badge.img+2

Hi @nicholas,

There is a custom transformer that can help you do this. After the RasterCellCoercer:

  1. Add an AttributeManager or Creator to create a single RGB attribute from the raster band cell values, set the new value to:
@Value(_band{0}.value),@Value(_band{1}.value),@Value(_band{2}.value)
  1. Add a custom transformer, the ColorConverter, to convert this value to FME colours
  2. Add a FeatureColorSetter and set the colour scheme to 'Fixed' and the fill color to the _output_color created by the custom transformer.


gio
Contributor
Forum|alt.badge.img+15
  • Contributor
  • September 14, 2018

You can just create an attribute

for 8bit

fme_fill_color =

@Evaluate(@Value(_band{0}.value)/256),@Evaluate(@Value(_band{1}.value)/256),@Evaluate(@Value(_band{2}.value)/256)

(use texteditor to avoid further Evaluation!!)

(fme_color for borders)


jdh
Contributor
Forum|alt.badge.img+28
  • Contributor
  • October 12, 2018
gio wrote:

You can just create an attribute

for 8bit

fme_fill_color =

@Evaluate(@Value(_band{0}.value)/256),@Evaluate(@Value(_band{1}.value)/256),@Evaluate(@Value(_band{2}.value)/256)

(use texteditor to avoid further Evaluation!!)

(fme_color for borders)

Wouldn't that be divide by 255? The 256th value is 0.

 

 


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