Converting from CSV to Spatial Geometry (Vector)

Liz Sanderson
Liz Sanderson
  • Updated

FME Version

  • FME 2020.1

Introduction

Converting from CSV to point, line, or polygon features, also known as vectors, is easy as long as there is spatial data contained within the CSV file, like latitude and longitude information or addresses. In this article, we will convert CSV to point features using the built-in CSV Reader parameters, the VertexCreator transformer, as well as using geocoding. We will also convert CSV to line and polygon features using the VertexCreator transformer with the LineBuilder transformer. This article can also be followed for any table based dataset that contains addresses or lat/long. 
  

Step-by-step Instructions

Part 1: Point Features

To get point features there are three different methods: (1) using the reader parameters, (2) using the VertexCreator, and (3) geocoding addresses. 

  • Method 1: Using the reader parameters, works well if you are going to be working with spatial data from the start. As of FME 2020, this method occurs automatically as long as the attributes are named correctly, such as latitude, longitude, and elevation, or x, y, and z. It is still possible to use this method in older versions of FME or if your attribute names are different, it just requires a manual step. 
  • Method 2: Using the VertexCreator is useful for when spatial data is added later on in the workspace, or if you are using a transformer that removes geometry. 
  • Method 3: Geocoding addresses, this method is useful if you do not have coordinates only addresses. Depending on how many addresses are in your dataset, you may need to run this workspace multiple times over a series of hours/days or pay for a service as geocoding can be costly. 

 

Method 1: Using the Reader Parameters

In a blank workspace, add a CSV read and browse to the rapid_transit_stations.csv file. Set the Coord. System to UTM83-10, then open the parameters. If you are using FME 2020 or newer, confirm that the Attribute Definition has x and y, set to x_coord and y_coord, respectively.
If you are using an older version of FME or it is not automatically set, switch the Attribute Definition to Manual, then change the X/Y/Z (Longitude/Latitude/Elevation) fields to the x/y/z_coordinate(_coord) data type, click OK until the reader is added to the canvas.

 

Method 2: Using the VertexCreator transformer

After the reader is added to the canvas without setting the Attribute Definition in the parameters, add a VertexCreator transformer. The VertexCreator creates a point feature of each record using X/Y/Z or Longitude/Latitude/Elevation values stored in the attributes. Each point feature retains all the attributes of the original non-geometry feature.

 

Method 3: Geocoding Addresses

Sometimes your CSV file will only contain addresses, without latitude/longitude data. To handle these kinds of situations, you can use the Geocoder transformer. Add a CSV reader with the CulturalSpaces2016.csv dataset to the canvas, add a Geocoder. Note that in FME 2021.2 and newer, the built-in Geocoder transformer has been replaced with the Geocoder Package, which is available from the FME Hub. For more information on Packages, see here
 
In the Geocoder parameters, sign up for a free Google Geocoder API and then paste the API into the parameters. Next, for Street Address, identify where the address is stored select that Attribute. For this example, the address is stored in ADDRESS. Before running the translation, set the Rejected Feature Handling to Continue Translation. We need to do this because some of the cultural spaces don't have an address associated with them, so our translation will stop when the Geocoder rejects these features. To do this, in the Navigator Pane > Workspace Parameters > Translation > Rejected Feature Handling > Continue Translation. Running the translation you will now have points on the map.

 

Results


 The output of point features using any of the three methods. Stylized in FME Data Inspector using map tiles by Stamen Design, under CC-BY-3.0. Data by OpenStreetMap, under CC-BY-SA.

 

Part 2: Line Features

To get line features is a two-step process. In a workspace, add a CSV Reader and add the rapid_transit_lines.csv file, set the appropriate coordinate system, for this example enter UTM83-10. Then follow either Method 1 or Method 2 that was covered in Part 1: Point Features.
Add a LineBuilder transformer to the canvas connecting it to either the CSV reader or the VertexCreator depending on the method you chose to get the points. In the LineBuilder parameters, set the Group By to LINE. This tells the LineBuilder to stop connecting the points together when the LINE attribute changes. This will result in three different lines in this example. If your lines are not coming out as expected, you may be required to sort by a particular attribute to organize the data by using the Sorter. In FME 2018 or older, the Group By option is not available, instead use Connection Break Attribute. 

 

Results


The output of lines using any of the three methods and a LineBuilder transformer. Stylized in FME Data Inspector using map tiles by Stamen Design, under CC-BY-3.0. Data by OpenStreetMap, under CC-BY-SA.
 

Part 3: Polygon Features

To get polygon features it is the same method to get line features. In a workspace, add a CSV Reader and add the NeighborhoodNames.csv file, set the appropriate coordinate system, for this example enter LL84. Then follow either Method 1 or Method 2 that was covered in Part 1: Point Features. Add a LineBuilder transformer to the canvas connecting it to either the CSV reader or the VertexCreator depending on the method you chose to get the points. In the LineBuilder parameters, set the Group By to NeighbourhoodName. If the last point is the same as the first then a polygon is automatically created. In FME 2018 or older, the Group By option is not available, instead use Connection Break Attribute. 

 

Results


The output of polygons using any of the three methods and a LineBuilder transformer. Stylized in FME Data Inspector using map tiles by Stamen Design, under CC-BY-3.0. Data by OpenStreetMap, under CC-BY-SA.



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.
 

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.