span8
span4
span8
span4
Translating your data to Comma Separated Value (CSV) allows you to distribute your dataset to a multitude of users and customers.The reason you may want to use this data format is the versatility due to the way tabular data emulates a database,as well as being written in plain text format that is readable by many applications.
The CSV writer is easy to set up,as there are few parameters to change.You may choose to overwrite an existing CSV,and you may include a header line with the field names.Choosing not to include the header line may be useful for appending the dataset to an existing database if you know ahead of time that the field names will align properly.
This article will cover two different ways to convert your data into CSV.In part 1,we will look at converting non-spatial tabular data (excel) to a non-spatial tabular CSV file.In part 2,we will convert spatial data (shapefile) to a spatial CSV file.Both exercise can be adapted for any tabular data,including databases,as well as any spatial data.
ConvertingToCSV.zip (contains data for both Part 1 & 2 and the finished workspace)
1.Add an Excel Reader
Open up a blank workspace in FME Workbench and add an Excel Reader.Browse to the CensusLocalAreaProfiles11.xls file,which is a tabular file containing census data for the City of Vancouver.Open up the parameters,this shows a preview of the Excel file,notice that the data doesn't start until line 5.Under Sheets to Read change Field Names Row to 5,the preview should update with a list of neighbourhoods as the first row.Click ok to add the reader.
Excel Reader parameters,set the Field Names Row to 5
2.Rename A
The first column in the excel file contains all the different census information but it is called A,which isn't very descriptive.Add an AttributeManager transformer and change the output attribute name of A to CensusType.
3.Remove empty rows
The excel file contains empty rows at the bottom,we should remove these so our CSV file is clean.Connect a Tester transformer and set it to CensusType - Attribute is Missing.
Tester parameters set the Left Value to CensusType and the Operator to Attribute is Missing
4.Write to CSV
Add a CSV Writer,in the parameters you can change the Delimiter Character if you wish.For this example let's leave it as ",".Change the CSV File Definition to Automatic and then click ok.Change the CSV File Name to VancouverCensus2011 click ok.Connect the CSV Writer to the Failed Output port on the Tester.We're connecting to this port because we tested for CensusType - Attribute Missing,so every row that had data failed the test.
Overview of the workspace for Part 1: Tabular to Tabular CSV
5.Run the translation
Run the translation and open up the VancouverCensus2011.csv file with a text reader.
The output VancouverCensus2011.csv file viewed in a text reader
1.Add a Shapefile Reader to FME Workbench
In FME Workbench,add a Shapefile reader and read in the rapid_transit_lines.shp.Enter UTM83-10 as the Coordinate System and click ok to add it to the canvas.
2.Extract coordinates
Within the shapefile,the coordinates are hidden within the line geometry,we will need to extract these to display in our CSV file.Add a CoordinateExtractor transformer to the shapefile reader,view the parameters,but we will just use the defaults.
3.Inspect the data
After the CoordinateExtractor,connect an Inspector,then run the translation.In the Data Inspector,if you click on the Canada Line feature,in the Feature Information pane you will see a list of _indicies{} for both x and y.The CoordinateExtractor made these lists with the coordinates,but we will need to extract them further to put them into a CSV.
The data viewed after the CoordinateExtractor in the Data Inspector,notice the coordinates contained in _indices{}.x and _indices{}.y
4.Explode the _indices lists
Add a ListExploder transformer after the CoordinateExtractor.In the parameters,set the List Attribute to _indices{} and accept the defaults.You can add another inspector and run the translation again if you wish to view each of the vertices making the line.
List Exploder parameters,set List Attribute to _indices{}
5.Clean up attributes
The ListExploder added an extra attribute we don't need,called _element_index.Add an AttributeManager and remove _element_index.You can also use the AttributeManager to rename x and y to Longitude and Latitude.
6.Write to CSV
Now that we have our coordinates extracted and the attributes cleaned up,let's write to a CSV file.Add a CSV writer to the canvas and connect to the AttributeManager.Run the translation and view your new CSV file in a text editor.
Overview of the workspace for Part 2: Spatial Shapefile to Spatial CSV
Output rapid_transit_line.csv file viewed in a text editor
Data Attribution
The data used here originates from open data made available by theCity of Vancouver,British Columbia.It contains information licensed under the Open Government License - Vancouver.
Converting from CSV to Spatial Geometry
How to Convert CSV to Shapefile (Non-spatial to Spatial)
Tutorial: Getting Started with CSV
Build Road Lines from GPS Points (CSV to Shape)
Viewing and Inspecting CSV Data
Converting from CSV to PostgreSQL and PostGIS
How to Convert CSV to Microsoft Excel
How to Convert Microsoft Excel to Esri SHAPE
Using Google's Chart API to Create Charts from a CSV and Shapefile
© 2019 亚搏在线Safe Software Inc |Legal