Exercise 4 FME Hackathon
Data Roads (Autodesk AutoCAD DWG, Esri Shapefile, and/or PostGIS)
Overall Goal Find the shortest route from the hackathon to an Italian Cafe
Demonstrates Data Translation, Transformation, and Best Practice
Start Workspace None
End Workspace C:\FMEData2016\Workspaces\DesktopBasic\BestPractice-Ex4-Complete.fmwt

A regional GIS group is holding an FME Hackathon and you have been invited to take part.

You have been provided with a set of source data and asked to create a useful project from it. You decide that it would be interesting to produce a tool that maps the route from the hackathon venue to a cafe the where a group get-together will be held that evening.

So, your task is to use the data available to you to calculate the best route from the convention centre to the cafe, and to write out that data to GPX format so folk can use it in their GPS/mobile device.


1) Create Database Connection
The source data has been provided in a PostGIS database; therefore our first task should be to create a connection to it. That way we can use the connection instead of having to enter connection parameters.

In a web browser visit http://fme.ly/database - this will show the parameters for a PostGIS database running on Amazon RDS.

In Workbench, select Tools > FME Options from the menubar

Click on the icon for the Database Connections category, then click the [+] button to create a new connection. In the "Add Database Connection" dialog, first select PostgreSQL as the database type. Then enter the connection parameters obtained through the web browser.

Give the connection a name (such as Hackathon PostGIS Database) and click Save. Then click OK to close the FME Options dialog.


2) Inspect Data
Start the FME Data Inspector to inspect the dataset we will be using. Select File > Open Dataset and, when prompted, enter the following:

Reader Format PostGIS
Reader Dataset Hackathon PostGIS Database
Parameters Under Table List choose Roads and One-Way Streets

Click OK to close the dialogs and open the data. Change the color of the one-way streets so you can see that they are a different set of features. It's important to know which roads are one-way if we want to calculate a route that is actually legal!

*NB: If you have any problems using the PostGIS database - for example connectivity problems with a firewall - then the following AutoCAD dataset can be substituted with very few changes required:*

Reader Format Autodesk AutoCAD DWG/DXF
Reader Dataset C:\FMEData2016\Data\Transportation\OneWayStreets.dwg


3) Start Workbench
Start Workbench and use the option to Generate a workspace.

Reader Format PostGIS
Reader Dataset Hackathon PostGIS Database
Parameters Under Table List choose Roads and One-Way Streets
Writer Format GPS eXchange Format (GPX)
Writer Dataset C:\FMEData2016\Output\Training\Route.gpx

The workspace will look like this:

For the sake of Best Practice, you may want to put a bookmark around these features, and maybe annotate which are the one-way streets.


4) Add ShortestPathFinder
Now we need to start calculating a route. The obvious first step is to add a ShortestPathFinder transformer, which is how we can calculate our route.

So, add a ShortestPathFinder transformer. Connect Roads to the Network port.


.1 UPDATE
The ShortestPathFinder transformer in the above (and following) screenshots gained a Reordered port in FME2016.1


5) Add Creator
The other input port on the ShortestPathFinder is for the From-To path (the start and end points of our journey). To add a feature to input here we can manually create it with the Creator transformer.

Add a Creator transformer and connect it to the From-To port.

Open the Creator parameters dialog.

Firstly enter UTM83-10 as the coordinate system of the data we are about to create. For the Geometry Object parameter, click the [...] browse button to the right to open a geometry-creation dialog. Select Line as the geometry type and enter the following coordinates:

X 491500 Y 5459550
X 494500 Y 5457440

The first coordinate is that of the hackathon venue and the second is the closest point in our network to the cafe we're going to visit.

Click the OK button to close the dialog.


6) Check ShortestPathFinder Parameters
The coordinates of the feature we've added might not sit exactly on the road network. To get around this issue there are parameters we can use in the ShortestPathFinder.

So, open the ShortestPathFinder parameters dialog. Under Snap Options set From-To Snapping to Yes and enter 150 as the Snapping Tolerance:

Also notice that there are parameters for network costs - we'll be making use of those later.


7) Run Workspace
Add some Inspector transformers after the ShortestPathFinder and run the workspace to prove it is working up to this point.

If all has gone well, the output will look like this, with a route defined:


Tiles Courtesy of MapQuest

Of course, if all has not gone correctly, you must make use of Inspector and Logger transformers, plus Feature Debugging, to try and locate the error!


8) Add ChangeDetector
The result looks fine, but there are some things we are yet uncertain about: what if the route takes us the wrong way down a one-way street; and what if it uses slower, residential routes?

The first issue we can fix - most quickly - by ignoring one-way streets (i.e. avoiding them).

This we can implement in FME by matching up one-way streets so we can remove them from the network.

Add a ChangeDetector transformer to the workspace. Connect the Roads feature types to the Original port and the OneWayStreets feature type to the Revised port: i.e the Roads feature type includes one-way streets, and we can match them with the One-Way Streets feature type to filter them out:

Open up the ChangeDetector parameters. Note that we are matching geometry (correct) so don't change any parameters, just click OK to close the dialog.

By using the ChangeDetector road features that match a one-way street will emerge from the Unchanged port, so we should leave this unconnected. Similarly, Added features will be oneway streets that haven't been matched, and we can leave these out too.

So connect the Deleted port to the ShortestPathFinder Network port. The "Deleted" features are those that the transformer thinks have been deleted because they exist as roads, but not in the one-way data.


9) Re-Run Workspace
Now re-attach any Inspector transformers (if necessary) and re-run the workspace. Check the new route. If it has changed from before then you know this is because it is now avoiding oneway streets. This might not be the shortest route, but it's one we can confidently follow without heading directly into incoming traffic!


10) Add AttributeValueMapper
To weight our route in favour of arterial roads (not residential) we need to give each type of route a cost.

The best solution is an AttributeValueMapper transformer; so place one of these into the workspace.

After the ChangeDetector will be the best location, as then some features will have already been filtered out and this transformer will have less work to do.


11) Edit AttributeValueMapper
Now we can set up the AttributeValueMapper transformer. Open its parameters dialog:

  • Select 'type' as the Source Attribute
  • Enter Cost as the Destination Attribute
  • Enter 2 as the Default Value

Now, underneath those parameters, we'll map some data.

Enter "Arterial" into the first Source Value field and a value of 1 in the matching Destination Value.

Enter "Residential" into the second Source Value field and a value of 3 in the matching Destination Value.

Basically, if the route is arterial (a main road) it will get a cost of 1; residential routes will get a cost of 3 and all other types will get a cost of 2 (because that's the default value). Click OK to close the dialog.


12) Apply Costs
Now we'll apply that newly calculated cost in the ShortestPathFinder.

Open the ShortestPathFinder parameters dialog. Set the Cost Type parameter to be "By Two Attributes".

Select "Cost" as the attribute for both the Forward and Reverse cost parameters (i.e. it will cost the same whichever direction the road feature runs and whichever direction we travel along it).


First-Officer Transformer says...
If we knew that the one way streets were connected in the right direction (i.e. from the first vertex to the last was the actual direction of travel) we could just set a weighting of 999 for the reverse cost and that would leave them out. Since this isn't our data we can't be sure of that, so our method is safer.


13) Run Workspace
The workspace will now look like this:

Save and then run the workspace. You'll find that your new route directs you from the convention centre to Commercial Drive avoiding one-way streets and taking the slowness of residential routes into account.


14) Connect Schema
Oh! Don't forget to remove the Inspector transformers and connect the Path port to the Route output feature type:

Now run the workspace, upload the data to your GPS device, and you are ready to go!


Advanced Exercise
Not really advanced, but you did use Best Practice throughout, right? I mean, you have bookmarks and annotations where needed, and no overlapping connections? If not, well you might want to fix that!

CONGRATULATIONS
By completing this exercise you proved you know how to:
  • Create and use an FME database connection
  • Create an FME workspace and use transformers
  • Use debugging techniques to find any problems encountered in an exercise
  • Use a good style for developing workspaces

results matching ""

    No results matching ""