span8
span4
span8
span4
A dynamic workspace is one where the writer schema is obtained not from a standard workspace definition, but from either the schema of an existing dataset or a schema constructed with list attributes.
In most cases the writer schema is obtained from a single source, however sometimes a single writer schema needs to be constructed from multiple sources.
This example uses the technique of constructing a writer schema using list attributes, but uses multiple sources to obtain the information needed to do so.It is a way to be able to merge different datasets together and write them out with a combined schema - all in a dynamic way.
Specifically, here the workspace translates a dataset of parks.Attributes from a secondary dataset need to be added to the parks and written out.Because these attributes are not known in advance, it is necessary to use a dynamic translation;and because there are multiple schema sources a technique that uses list attributes must be used.
As noted in a previous article, the list attributes required to construct a dynamic schema are attribute{}.name and attribute{}.fme_data_type - these two list attributes define the name and data type for the writer schema attributes.
As well as constructing these from scratch, these can be extracted directly from our main dataset using a reader format called "Schema (Any Format)", for example:
Attribute | Value |
attribute{0}.fme_data_type |
fme_int16 |
attribute{0}.name |
ParkId |
attribute{1}.fme_data_type |
fme_int16 |
attribute{1}.name |
RefParkId |
attribute{2}.fme_data_type |
fme_varchar(40) |
attribute{2}.name |
ParkName |
Similarly a list of attributes can be extracted from the secondary data source:
Attribute | Value |
attribute{0}.fme_data_type | fme_varchar(30) |
attribute{0}.name | ZoneName |
attribute{1}.fme_data_type | fme_varchar(30) |
attribute{1}.name | ZoneCategory |
The main problem to be solved by the workspace is to take these two lists and merge them together into a single output schema definition.
The workspace looks like this:
There are three readers:
The schema reader reads the schema from both source datasets (primary and secondary) and so emits two features.The attribute lists are exploded to create one feature per attribute, and then merged back into a single list using an Aggregator transformer.Excess schema information is removed with an AttributeKeeper transformer:
主要和次要的数据集是读的 primary dataset here is fixed, but the secondary dataset is generic/dynamic - and the information is transferred from secondary to primary (here using a SpatialFilter):
Finally the schema list attributes are merged onto the primary features using the FeatureMerger transformer:
The writer feature type is set up dynamically and to use the Schema Feature as a schema source.
Run the workspace and inspect the output.You will find that each park now has information attached about what development zone the park resides in.
The important part is that you can change the source zoning dataset to something else (of any format) and the attributes from those features will be dynamically attached and used in the output.
1.Add Readers and Schema
Add two MITAB Readers, one for Zones data and one for Parks data, ensure that Single Merged Feature Type is selected for both.Then add a schema Reader.For the Schema Reader, add the Zones.tab file first and then click on the parameters.In the parameters for Additional Attributes to Expose, add the following list.Then click ok to add the reader to the workspace.In the Navigator window, maximize Zones [SCHEMA] and click on the Source Dataset.Click on the dropdown, and click Select Multiple Files/Folders.Add the Parks.tab file.
2.Set up SpatialFilter
Connect a SpatialFilter to the Zones Writer via the Filter Input port and the Parks Writer via the Candidate Input port.In the parameters set the Spatial Predicates to Test:
3.ListExploder
Add a ListExploder to the Schema Writer.In the parameters set List Attribute to attribute{}.
4.Aggregator
Connect an Aggregator to the Elements Output port on the ListExploder.Set the Accumulation Mode to Merge Incoming Attributes.Check Generate List, set List Name to attribute and for Selected Attributes add fme_data_type and name
Note:Older versions of FME won't have the Add to list or Select Attributes parameters.If you open the attached template, it too is missing the parameters because the workspace was created with an older version.I'm leaving the template so that users with an older FME can still use it;but to get these parameters simply right-click and choose Upgrade Transformer.
5.AttributeKeeper
We are only interested in keeping two of the attributes that we exposed.Add an AttributeKeeper after the Aggregator.In the parameters select the … in Lists to Keep and select attribute{}.fme_data_type and attribute{}.name
6.FeatureMerger
To merge everything together we will use the FeatureMerger.Connect both the Passed and Failed Output ports on the SpatialFilter to the Requestor Input port and the AttributeKeepers Output port to the Supplier Input port on the FeatureMerger.In the FeatureMerger parameters, set the Requestor to 3 and the Supplier to 3, keep everything else as the defaults.
7.Write out to dynamic writer
Add a MITAB Writer to the workspace, ensure that it is set to Dynamic (Advanced).Connect it to the Merged Output port on the FeatureMerger.Once added to the workspace, in the parameters set the Schema Sources to “Schema From Schema Feature”.Connect an Inspector to the Merged Output port and run translation.
Dynamic Workflows: Advanced Example - Modifying the Schema Feature
Dynamic Workflows: Destination Schema as a Mirror Image of the Source Dataset
Dynamic Workflows: Destination Schema is Derived from a Schema Feature
Dynamic Workflows: Destination Schema is Derived from an External Dataset
Dynamic Workflows: Destination Schema is Derived from a Lookup Table
Dynamic Workflows: Basics of Dynamics
Dynamic Workflows: Destination Schema Contains Different Feature Type Names
Dynamic Workflow Tutorial: Advanced Technique - Using the SchemaMapper
© 2020 Safe Software Inc |Legal