Skip to main content
Question

Convert raster to vector grid, populate attributes with colours?

  • September 13, 2018
  • 3 replies
  • 120 views

nicholas
Contributor
Forum|alt.badge.img+14

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?

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

3 replies

Forum|alt.badge.img+2
  • 719 replies
  • September 14, 2018

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
  • 2252 replies
  • 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+37
  • Contributor
  • 2002 replies
  • October 12, 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)

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