span8
span4
span8
span4
This article is also part of the tutorialHow Do I Do That in FME|Next: Defining a Drive-Time Zone
Shortest route calculations are done in FME using the ShortestPathFinder transformer.This transformer calculates the shortest path from a source node to a destination node on a given network.
Here,for example,a user is finding the shortest path between the start/end points of a given route,using a network of lines:
A from-to line defines the start and end of the route.Any number of from-to lines can be passed into the ShortestPathFinder for multiple calculations on the same network.
There are some simple variations and issues to be aware of.
Follow these steps as an example of how to calculate the shortest route in a network.
1.Start FME Workbench.Add a reader (Readers > Add Reader on the menubar) to read the attached Shape dataset of the from-to line.
2.Add a second reader to read the attached AutoCAD DWG dataset containing a road network.In the Add Reader dialog click the option for "Single Merged Feature Type".This will ensure all data is added as a single layer:
3.Add a ShortestPathFinder transformer and connect the road network and from-to line to the correct input ports.Add an Inspector transformer to visualize the output:
4.Open the parameters dialog for the ShortestPathFinder.Because the from-to end points may not sit exactly on the network,change the parameter From-To and Network Snapping to Yes.Set a tolerance of 200:
5.Run the workspace.The output will look like this:
Travelling the wrong way along a one-way street is avoided by using costs instead of distance.It is necessary for the one-way streets to be tagged (usually with an attribute) and for their direction (from the first coordinate to the last) to match the permitted direction of travel.
Follow these steps as an example of how to calculate the shortest route in a network and avoid travelling the wrong way along a one-way street.
1.Start FME Workbench.Open the attached workspace (or continue from example 1).
2.Add a Tester transformer to the workspace,between the streets feature type and the ShortestPathFinder transformer:
3.Open the Tester parameters dialog.Set up a test for where the attribute OneWay equals Y
4.Add two AttributeManager transformers,one connected to each of the Tester output ports.These will be used to set the travel cost:
5.Open the parameters dialog for the first AttributeManager (the one connected to the Tester:Passed port).Add two new attributes,ForwardCost and ReverseCost.Set ForwardCost to a value of 1 (representing the correct direction on a one-way street) and the ReverseCost to a value of 9999 (representing the incorrect direction on a one-way street)
6.Open the parameters dialog for the second AttributeManager (the one connected to the Tester:Failed port).Add two new attributes,ForwardCost and ReverseCost.Set both attributes to a value of 1.These are two-way streets where the cost is equal in both directions.
7.Open the parameters dialog for the ShortestPathFinder transformer.Change the Cost Type parameter from "By Length" to "By Two Attributes".Set ForwardCost as the Forward Cost Attribute and ReverseCost as the Reverse Cost Attribute
8.Run the workspace.The output will look like this:
Notice the difference between this output and example 1.Example 1 was using one-way streets incorrectly,whereas example 2 avoids doing so.
Using only cost attributes to determine a route means that distance is no longer considered.For instance,in example 2 there is no difference between a road of 100 metres and 100 kilometres,provided it is not a one-way street.To solve that requires use of both length AND cost.
Follow these steps as an example of how to calculate the shortest route in a network,applying both costs and length.
1.Start FME Workbench.Open the attached workspace (or continue from example 2).
2.Open the parameters dialog for the first AttributeManager transformer.Next to the value for the ForwardCost attribute,click the drop-down arrow and select Open Arithmetic Editor
3.In the arithmetic editor,add a multiplication symbol and then drag in the FME Feature Function called Length
Repeat this step for the ReverseCost attribute,and repeat again for both cost attributes in the second AttributeManager.
4.Run the workspace.The output will look like this:
Notice again the difference in result from examples 1 and 2.
NB:The method of multiplying cost by distance is only one example of what might be used.You could,for instance,weight the costs higher by multiplying cost by half the distance (cost * (distance/2))
Example 1 - Workspace as Template
Example 2 (Begin) - Workspace as Template
Example 2 (Complete) - Workspace as Template
Point in Polygon Calculations with the PointOnAreaOverlayer
Determining Spatial Relationships
Coordinate Systems and Measurements with the Reprojector
Distance Measurements with the LengthCalculator
Buffering features for Spatial Relationship Analysis
Creating Time and Distance Isolines using the NetworkCostCalculator
Find the Shortest Path Between a Start and End Point
Workaround: Road Segment Length and Snapping with the ShortestPathFinder
© 2019 亚搏在线Safe Software Inc |Legal