span8
span4
span8
span4
In this tutorial we will translate Google KML (*.kml) data, representing neighborhood areas, to Esri shapefile (*.shp) format.Our goal will be to create an Esri shapefile of neighborhoods, and to calculate the percent increase in population between 2001 and 2011.
The VancouverNeighborhoods.kml Google Earth file contains area features representing neighborhoods, along with accompanying attribute information including population data.
This video was created with FME version 2016.0.Some of the steps might be slightly different, but the overall process is the same for newer versions of FME.
KMLToShapefile.zipContains workspace and data
1) Inspect the Data in FME
The first step is to inspect the VancouverNeighborhoods.kml file.Open a blank FME Workspace and add a new reader.In the reader dialog, type in GoogleKML, then browse to the VancouverNeighborhoods.kml file.Click OK to add the reader to the canvas.
In the Select Feature Types dialog, click the Select All box to unselect all of the feature types and then select the Neighborhoods feature type.
Now to view the data, click on the Neighborhood reader feature type on the canvas to open the popup menu.Then on the popup menu click the View Source Data button to view the data in the Visual Preview Window.
In the Visual Preview window (or FME Data Inspector), click the drop-down in the table window and select Neighborhoods to view the Neighborhoods attributes.Take note of the length of the attribute names, since we are planning on writing out to Esri shapefile we will need to shorten the attribute names to only 10 characters.
Note:This step can also be completed in FME Data Inspector for versions previous to FME 2019.Just be sure to add the Google KML reader to FME Workbench after inspecting the data.
2) Set the Output (Writer) Format to Esri Shapefile
Next, we need to add a writer to the canvas.Click on the Add Writer and in the Add Writer dialog box, for the Format, select Esri Shapefile.Then for Dataset, browse to a folder to save the shapefile and then click OK to add the writer.
3) Clean up Attribute Names
To shorten the attribute names we will need to use an AttributeManager transformer.Add an AttributeManager transformer to the canvas and connect the input port to the Neighborhoods reader feature type and the output to the Neighborhoods writer feature type.
Open the AttributeManager parameters and change the following Output Attributes:
Input Attribute |
Output Attribute |
NeighborhoodID |
NeighID |
NeighborhoodName |
NeighName |
NeighborhoodURL |
NeighURL |
TotalPopulation2001 |
Pop2001 |
TotalPopulation2011 |
Pop2011 |
4) Update Writer Properties
Now that we have renamed the attributes, we need to reflect the name change in the writer.Open the writer feature type parameters and switch to the User Attributes tab.In this tab, we can see that the attributes are not the same as the ones we just renamed in the AttributeManager.To easily fix this, switch the Attribute Definition to Automatic and it will automatically update to the attributes we renamed.Click OK to accept the new attribute names.
5) Calculate Population Increase
最后一步之前运行的翻译是 calculate the population increase;we will do this with an ExpressionEvaluator transformer.Add an ExpressionEvaluator to the canvas and connect it between the AttributeManager and the writer feature type.
In the ExpressionEvaluator parameters, set the New Attribute name to PopChange.Then in the Arithmetic Expression window set the expression to:
((@Value(Pop2011)-@Value(Pop2001))/@Value(Pop2001))*100
This expression calculates the percent increase between 2001 and 2011 populations.It does this by taking the absolute value of the difference and divides it by the original value - the resulting decimal is then converted to a percent.
Since we set the writer feature type definition to Automatic, the PopChange attribute will automatically be added to the writer.This can be confirmed by expanding the Neighborhoods writer feature type to view the attributes.
6) Run the Workspace
The workspace is now ready to be run.Run the workspace by clicking on the green play button.
7) View the Output Dataset
To view the output dataset, click on the Neighborhoods writer feature type to open the popup menu.Then click on the View Output Data button.
The attributes have been renamed and we now have a PopChange column containing the population change data as a percent.
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.
Using Google's Chart API to Create Charts from a CSV and Shapefile
How to convert Shapefile to KML
How to Convert CSV to Shapefile (Non-spatial to Spatial)
How to convert MapInfo to Shapefile (MIF/MID to SHP)
Importing Database Tables, Raster Data, Vector Data
© 2020 Safe Software Inc |Legal