FME Version
Files
-
- 200 KB
- Download
Introduction
In this article we will perform a very common transformation, taking non-spatial (tabular) data in a CSV file (*.csv, or comma-delimited text) and writing it out to a spatial format, in this case, the Esri shapefile format (*.shp). Our CSV file lists cell phone signal measurements at various locations in the City of Vancouver. We have longitude, latitude, elevation, StationID, Power, Quality, Number of Measurements (num_measures), Code, and Recorded Timestamp (recorded_tstamp) columns.
Video
Note: This video was recorded using FME 2016, the interface might vary slightly.
Step-by-step Instructions
1. Start FME Workbench and Add a CSV Reader
Open FME Workbench and in a blank workspace add a CSV reader. Browse to the CellSignals-Small.csv dataset. Set the Coord. System to LL84, then open the Parameters.
2. Inspect the Reader Parameters
Change the Feature Type Name(s) to From File Name, this will display the actual file name on the reader feature type once it’s added to the canvas. This is helpful when you are adding multiple datasets of the same format.
In FME 2020 or newer, confirm the Type for Latitude, and Longitude are set to y_coord, and x_coord, respectively. In FME 2019 or older, you will need to manually update the Type. Change the Attribute Definition to Manual, then click the drop-down for Type, and update them to the correct coordinate as listed above. Updating the Type will automatically create points.
Optionally, in older versions of FME, you can skip this step and instead use a VertexCreator.
3. Verify the data in Visual Preview
Let's confirm that the points we have created are being correctly read. Click CellSingles-Small reader feature type to open the popup menu, then click on View Source Data.
In Visual Preview, if the CSV Types are set up correctly, you should see point data in the Graphics View window.
Turn on Background Maps to ensure that the coordinate system was set up. To do this in Visual Preview, if your window is small click on the >> to expand the window, then click on Background Map Off. In the Background Map drop-down, select a new background map or a pre-saved one.
If you have a background map enabled but you do not see it behind your points, this means the coordinate system was not set up in the reader. You can fix this by finding the CSV file in the Navigator pane, expanding it, and then opening the Coordinate System and setting it to LL84.
5. Set up a Shapefile Writer
Now that we have ensured our data is set up correctly, we can write it out to a shapefile. Add a writer to the canvas. For format, select Esri Shapefile and then browse to a folder to save your data to. We don’t need to set up the parameters for the shapefile within the initial writer setup, we will set them later once it is on the canvas. Before clicking OK, double-check that the Shapefile Definition is set to Copy from Reader.
6. Connect the Reader to the Writer
Connect the source feature type (CSV) to the destination feature type (shapefile) by clicking on the grey triangle on the reader and dragging the line to the red triangle on the writer. Once connected both triangles will turn grey.
7. Map Truncated Attributes
Now even though both the triangles are grey, if you expand both the reader and the writer by clicking on the small arrow next to the name, you will see two attributes (num_mesaures and recorded_Tstamp) that are not green. These attributes are not green because they haven’t been properly mapped because the shapefile writer truncated their names. This is because the shapefile format has a 10 character limit for attribute names.
To fix this mapping is easy, just connect the attributes by clicking the yellow triangle on num_mesaures and dragging the line to the red triangle on num_measur, they should both turn green. Repeat this for recorded_Tstamp.
8. Modify output Shapefile Writer Feature Type Properties
With the attributes mapped correctly, we have one last thing to do. Open the CellSignal-Small writer feature type properties by double-clicking on the writer. In the Feature Type Properties, change the Geometry to shape_point, then click ok.
9. Run the Workspace
The workspace is now ready to run. Run the workspace by clicking on the green play button in the toolbar to carry out the translation. Once the workspace has been completed, a Translation was SUCCESSFUL message will appear in the Translation Log.
Data Attribution
The data used here originates from open data made available by the City of Vancouver, British Columbia. It contains information licensed under the Open Government License - Vancouver.
Comments
0 comments
Please sign in to leave a comment.