Tutorial: Getting Started with CSV

Liz Sanderson
Liz Sanderson
  • Updated

FME Version

Introduction

Comma Separated Value, or CSV, is a way to store structured information in an ASCII file format, thereby making it a very simple database. This has made it a very popular format for exchanging information between spreadsheets, databases and other software systems.

In FME, CSV is treated as a database format. Each line in the file is a record, with a comma (or other) character between each field within the record.

In the CSV file, there is often a header line to provide names for the fields. For example:

csvexample-wordpad.png

Example of a CSV file viewed in a text editor like Word Pad

 

If you check the parameter Field Names Line, you can select which line the column names start on, for this example it is Line 1, but sometimes you could have lines of text at the beginning of the CSV file.

csvexample-fme.png

The same CSV file preview in the CSV Reader parameters in FME

 

Delimiters

Despite the name, a CSV file does not have to be comma-separated. FME is capable of recognizing a file with any separator or delimiter character, as long as you specify that character in the settings box.

The CSV reader is also capable of handling data consisting of fixed-width columns without a separator, provided that the character spacing the data (usually a space character) does not appear in the data itself. Simply use the parameter 'Remove Duplicate Separators' to achieve this. For more information, please see the CSV Reader documentation.
 

Translating Tabular Data

FME can be used to translate CSV data into other tabular formats such as Excel, Oracle, SQL Server, or XML.
 

Turning Text Data into Spatial Features

CSV files often contain spatial data listed as a series of X/Y coordinates, these can be extracted by setting up the reader parameters or using a VertexCreator. When adding a CSV Reader remember to set the coordinate system. CSV files are not coordinate aware data types, so in order for the data to be displayed correctly, a coordinate system must be set. For more information on creating spatial data from a CSV, please see the Converting from CSV to Spatial Geometry article.
 

Examples

Viewing and Inspecting CSV Data

This example will demonstrate how to view both a tabular CSV file and a spatial CSV file using FME Workbench and the Data Inspector.

How to Convert CSV to Microsoft Excel

Learn how to convert a CSV file to Microsoft Excel format and do simple attribute manipulation including date-time formatting.

Converting from CSV to PostgreSQL and PostGIS

Using FME to convert CSV files to both PostgreSQL and PostGIS is easy. This example demonstrates how to handle CSV data with a delimiter other than a comma.

Converting from CSV to Spatial Geometry

This example is a brief overview of how to convert CSV data with latitude and longitude values, or addresses, into points, lines, or polygons.

How to Convert CSV to Shapefile (Non-spatial to Spatial)

Shapefiles have a 10 character limit on attribute names. This example demonstrates how to convert CSV to Shapefile, as well as how to map attributes between the reader and writer when attribute names are truncated.

Converting Tabular (Non-Spatial) and Spatial Data to CSV

CSV files are versatile and are an accessible way to share data. Learn how to convert both tabular and spatial data into CSV format.

 

Advanced Examples

Build Road Lines from GPS Points (CSV to Shape)

Most GPS data is acquired in point form. Learn how to create lines from GPS points contained in a CSV file and then store the lines in a Shapefile.

Attribute Processing Example Workspace (CSV to MapInfo)

In this example, learn how to use various transformers to manipulate CSV data before outputting it to MapInfo Tab. This example can easily be adapted to transform data to a tabular output format instead of a spatial output format.

Join CSV File to a Database Table with the DatabaseJoiner

Data can come from various sources, learn how to use a DatabaseJoiner to Join a CSV file to a Microsoft Access file.

Using Google's Chart API to Create Charts from a CSV and Shapefile

There is a lot you can do with Google APIs, in this example, we will create a pie chart from a CSV file and a Shapefile and display it in Google Earth.

 

Resources

CSV Quick Facts

CSV Reader/Writer Documentation

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.