|Exercise 5||Dynamic Community Mapping Updates|
|Data||Community Mapping (Esri File Geodatabase)|
|Overall Goal||Generate a new Community Mapping dataset using a table-based schema|
|Demonstrates||Table-based schemas for dynamic translations|
In a previous exercise you created a new community map dataset for the planning department using a dynamic schema. At the time only two tables were defined, but now another one is required and the planning department wants you to update the workspace.
Rather than having to make changes each time they add more datasets, you figure that you can simply create an Excel spreadsheet containing the schema definition, so the planning team can edit it themselves and do the same for all future updates.
1) Inspect Spreadsheet
Open and examine the spreadsheet at C:\FMEData2016\Resources\CommunityMapSchema.xlsx.
If you don’t have Excel then open it in the FME Data Inspector and switch to Table View.
The table has schema definitions for Firehalls, Parks, and Zones feature types.
2) Start Workbench
Start FME Workbench. Open the workspace from the previous exercise or the begin workspace listed above.
3) Delete CommunityMap Resource Reader
Because we are using a spreadsheet to define our output schemas, the CommunityMap Resource Reader is no longer needed. Locate it in the Navigator window, right-click on it, and choose Delete.
When prompted, click OK to confirm that all references relating to this dataset will also be removed.
4) Add Excel File as Reader Resource
Now select Readers > Add Reader as Resource. In the dialog that opens choose:
|Reader Format||Schema (From Table)|
Click the parameters button (if you don’t you will be prompted to anyway). This dialog is where we can define how the table maps to the required schema.
Check the Reader parameters at the top. They should show the dataset is an Excel format file. Select Sheet1 as the table to use:
The first row should get used as the field names. If this is not the case, then click the parameters button above and set the values properly:
Next select the appropriate fields to match to the required parameters (for example Feature Type = FeatureType):
Click OK to close the dialog and again to add the Reader.
5) Set Dynamic Parameters
Now open the feature type properties dialog for the Writer feature type.
Under the User Attributes tab remove the LastUpdatedBy attribute, as we’ve added this to the spreadsheet definition for each type and no longer need it in here.
In the General tab click the Schema Sources edit button. Uncheck FireHalls and check CommunityMapSchema [SCHEMA_FROM_TABLE]:
Click OK and OK again to close these dialogs.
6) Add Reader
If you noticed, the schema spreadsheet included an entry for the Zones dataset, so add a Reader (not a Resource – we really want the data this time) as follows:
|Reader Format||MapInfo TAB (MITAB)|
Once added, connect its Reader feature type to the dynamic Writer feature type.
7) Save and Run Workspace
Save the workspace and then run it.
Inspect the output. Notice that all three feature types have been written, and that their attribute schema matches what was defined in the Excel spreadsheet; including the LastUpdatedBy field for each one.
|If you have the ability to edit the Excel spreadsheet then let’s do a couple more advanced steps (alternatively you can convert the spreadsheet to a CSV dataset and work in there).|
8) Update Spreadsheet - 1
The planning team have decided they should rename some attributes, so open the spreadsheet and rename the following attributes for the FireHalls feature type:
- Name to HallName
- Address to HallAddress
- PhoneNumber to HallPhone
Save the spreadsheet.
9) Update Spreadsheet - 2
If you run the workspace now it will run to completion, but there will be no values in the renamed fields. That’s because FME has no way to tell how to map the source data to the new schema.
We could simply add an AttributeRenamer transformer to handle this change, but the better way is to use the SchemaMapper. That way it can be made a little more dynamic.
So, in sheet 2 of the spreadsheet, enter:
Then save the spreadsheet.
10) Add SchemaMapper
Add a SchemaMapper transformer to the workspace, with both output ports connected to the output feature type:
Open the parameters dialog. For the format select the edited Excel file. In the next dialog select Sheet 2 as the table to use.
In the final dialog, select Add > Attribute Map.
When prompted, select OldAttrName as the source field and NewAttrName as the Destination field. Check the box to Remove the original attributes (i.e. this is a renaming, not copying):
Click OK to close this dialog, then click Finish. Now save and run the workspace again.
This time the output will have its attributes properly mapped. So now the planning department can translate their data, decide on the output schema, and map source to destination attributes dynamically; all by editing this one Excel spreadsheet.
By completing this exercise you have learned how to: