I have a table (say landuse polygons for example) structured as follows:
ID | landuse_category
---------------------
1 | woodland
2 | industry
3 | farmland
4 | woodland
5 | lake
6 | farmland
7 | industry
8 | lake
Now I would like to create attributes from the distinct values (farmland
,industry
,lake
,woodland
) of landuse_category
to a table districts
for example like
ID | farmland | industry | lake | woodland
I succeeded in obtaining the distinct values with a DuplicateFilter
with key attribute landuse_category
on the Unique port and then create a list of these unique values with a ListBuilder
like
Since input data may vary, this is a generic task and thus the attribute values themselves should not be part of the process.
How to create attributes on another table using this list?
Best Answer
The simplest way to create the attribute is to use an AttributeManager and use the value of the landuse_category attribute as the name of the new attribute:
When you write that (and I'm using plain CSV format here) the results look like this:
I'm guessing this is what you're looking for. There are two things to consider though...
1) If you want a 0 (or null) value for the other fields, then you could expose those attributes (AttributeExposer) and map them to null (NullAttributeMapper).
2) I'm assuming the output schema is fixed (ie you know the fields are only going to be farmland, industry, lake, woodland). If you are not sure what the fields will be, then you would have to use a Dynamic writer. That's a bit more tricky (I was going to leave it out, but I figure it's worth documenting)...
2a) In the AttributeManager, also create attributes name (as a copy of landuse_category) and fme_data_type (set to your data type, I used fme_char(1))
2b) Add an Aggregator transformer. Set the Generate List option. Call the list attribute and add name and fme_data_type:
btw, you could use this instead of your method to get a schema definition. If you check the output of this you will see a schema defined as a list.
2c) We now need to get the schema definition onto all the features. Do this with a FeatureMerger transformer. Set it up like this with the requestor/supplier set to a constant value (like 1 in my case):
2d) Set the writer to Dynamic mode, using Schema from Schema Feature as the schema source:
Now you have a truly dynamic solution. If a landuse type changed (from farmland to agriculture perhaps) or a new landuse type was added (say urban) or one was deleted, then the workspace will operate automatically without needing to be edited.