FME Version
Files
Introduction
Spider Diagrams, also known as Spider Maps, are a great way to visualize lots of data that relates to a single point. In this exercise, we will be looking at the distance between businesses and their closest rapid transit station in the downtown core. We will clean up data that has extra attributes we aren't interested in and then relate the two datasets and write it out to Tableau format. Finally, we will open our final dataset in Tableau and style it to create a Spider Diagram to share with our colleagues.
Step-by-Step Instructions
1. Open a blank workspace and add a CSV reader
In the black workspace, add a CSV reader and add the business_licenses.csv file. Open up the parameters and verify that the Latitude and Longitude attributes have the y_coordinate and x_coordinate data type set (automatic in FME 2020+. Otherwise, set the Attribute Definition to Manual and change the Latitude and Longitude to Y and X.
Set the Coord. System to LL84 and click ok.
2. Inspect the data
Open up the business_licenses.csv in Visual Preview by partially running the workspace and inspecting the feature cache. We are only interested in the businesses which are in the downtown core, so we need to determine which attribute we can filter by. It looks like we have an attribute called LocalArea, that might contain the data we are looking for. Click on a point in the middle of the dense cluster of points near the top of the map, this is the downtown area. Looking at LocalArea, it has a value of 02-Central Business/Downtown. This is what we will filter by.
3. Add a Tester to filter by Downtown
Back in the workspace, add a Tester transformer to our CSV file. In the Tester enter: LocalArea contains Downtown and then click ok.
Add a Tester, set it to LocalArea Contains Downtown
4. Remove unnecessary attributes
The business_licenses.csv contains a lot of data that we don't need to create our spider diagram, so we should tidy up the dataset before we continue. Add an AttributeKeeper to the Passed Output port on the Tester. Open up the parameters and under Attributes to Keep, check only BusinessName, BusinessTradeName, BusinessType, and BusinessSubType and then click ok. We don't need to keep LocalArea because we've already filtered what we needed from it. Click ok.
5. Filter out rows without a latitude and longitude
The CSV is almost tidy, we just need to do one more thing. Add a GeometryFilter to filter out any rows that don't contain any latitude or longitude values. Set the Geometries Types to Filter to Point.
6. Inspect the data
Partially run the workspace by selecting the GeometryFilter and clicking the run to this button. Then Inspect the feature cache on the Point Output port of the GeometryFilter. In the Visual Preview window, confirm that there are only points in the downtown area, that there are only 4 attributes starting with "Business" and that all values have a point on the map.
7. Create a unique ID
For the spider diagram to be compatible with Tableau, the points data requires a unique identifier. Add a UUIDGenerator and connect it to the Point Output port on the GeometryFilter.
8. Add a KML Reader
Add a reader, enter the following:
Reader Format: | Google KML |
Reader Dataset: | ...\rapid_transit_stations.kmz |
Click ok, when the Select Feature Type dialog appears, deselect everything except for Rapid Transit Stations.
9. Change STATION to StationName
To keep with our camelcase naming style, add another AttributeManager to Rapid Transit Stations. Change the input name of STATION to the output of StationName.
10. VoronoiDiagrammer
We want to connect each business to the closest transit station. We could do this using something like a Bufferer transformer, but let's take a look at the VoronoiDiagrammer. The VoronoiDiagrammer creates a set of polygons showing the area that is closest to a particular input point.
Add the VoronoiDiagrammer and connect the Points Input port to the Output port on the AttributeManager connected to the Rapid Transit Stations. Then attach an Inspector to the VoronoiPolygons Output port.
11. Inspect the data
Inspecting the data, we can see that the VoronoiDiagrammer worked and created the polygons, but it removed our Rapid Transit Stations points.
The Voronoi Diagram in Visual Preview, notice that there are no latitude or longitude values in the Table View
12. Add a CoordinateExtractor
We would like to keep the original point data of our Rapid Transit Stations, so let's add a CoordinateExtractor in between the AttributeManager and the VoronoiDiagrammer. The CoordinateExtractor will store the latitude and longitude in an attribute. Open up the parameters and change the Mode to Specify Coordinate. Then change the X Attribute to trainStation_xcoord and the Y Attribute to trainStation_ycoord. Remove the Z Attribute and click ok.
In the CoordinateExtractor set the Mode to Specify Coordinate and change the X and Y Attributes
13. Relate the two datasets
Time to relate the two datasets, add the PointOnAreaOverlayer, connect the UUIDGenerator to the Points Input port and the VoronoiDiagrammer Voronoi Polygons Output port to the Areas Input port.
14. Determine which points overlap with the areas
Add another Tester and connect it to the Point Output port on the PointOnAreaOverlayer. Set the Tester to _overlaps > 0 to test to see which of the points overlaps with the polygons.
15. Create spider diagram
Now that we have processed our data let's turn it into a spider diagram. Add a VertexCreator and connect it to the Passed Output port on the Tester. Open up the parameters and set Mode to Add Point. Set the X Value to trainStation_xcoord and the Y Value to trainStation_ycoord. This will create a line that starts at the business point location and ends at the transit station. This is done by using the latitude and longitude attributes we created with the CoordinateExtractor.
In the VertexCreator set the X and Y Values to trainStation_xcoord and _ycoord
16. Determine the distance between the business and the nearest train station
To find the distance (as the crow flies) between the business and the nearest train station we need to measure the length of the lines. Add a LengthCalculator, open up the parameters and change the Multiplier to 100, this will give us the approximate distance in kilometers. Connect this to the Output port on the VertexCreator. Connect an Inspector to the Output port of the LengthCalculator to ensure that the translation worked before we write it to Tableau.
17. Write to Tableau
Add a Tableau writer and write it to your Output folder. Change the Add Feature Type(s) to Automatic... then click ok. When the Feature Type dialog box opens, change the Table Name to SpiderDiagram and change the Geometry to hyper_line. Run the translation and view the results in Tableau.
18. Create the spider diagram in Tableau
To create the spider diagram within Tableau, we need to add the spatial_latitude and spatial_longitude to the shelf. Add both the _uuid and spatial_geometry_order to Detail and then change the Mark Type to Line to see the results. Finally, customize and style your map as desired.
Create a spider diagram in Tableau by adding the _uuid and spatial_geometry_order to Detail
Comments
0 comments
Please sign in to leave a comment.