Tuesday, July 13, 2010

Converting csv data into shapefile

In the inaugural post of the new Free GIS Tools series I presented Google Map API, a very powerful and functional alternative to open source and commercial online GIS software. Then I wrote about a handy tools for selecting colour scheme for thematic maps. Today a quick overview of csv to shapefile converter tool which can be very handy if you need to convert latitude and longitude coordinates in decimal degrees to point, line or polygon features for display in desktop GIS software or for further conversion to complex KML/KMZ. These could be geocoded locations of your clients, or locations derived from geoRSS feeds, outlines of features from online digitalisation tools (eg. using aus-emaps.com simple geocoder point coordinates tool), or similar.

CSV to Shapefile Converter is the best tool for such tasks and it can be downloaded from wanderingidea.com for free. It is a Windows based application and requires .NET 2.0 framework to run - quite a large download as a bundle but really worth the effort. Here are a few tips on how to use it:

  • Conversion steps are almost self-explanatory: open csv file, select shape type, specify which field is latitude and which is longitude, and which fields to use as data attributes - all in a single form - then press a button to execute.
  • CSV file you want to convert has to have a header row, otherwise you will lose the first record.
  • When creating a polygon, the last record relating to a particular polygon has to be identical as the first record in order to “close the loop”.
  • This converter supports complex shape structures like multi-part polygons (ie. many polygons with the same attribute) and doughnut type polygons – just need to remember a convention that in shp file format points for outer boundaries go clockwise and inner boundary points are listed in anti-clockwise order.
Here is an example of a csv input files to generate a multi-part polygon and a doughnut type polygon (the result of CSV to Shapefile conversion is depicted on the images below):

doughnut polygon:

1,1,-28.323724553546, 153.028564453125
1,1,-28.297125824492888, 153.49273681640625
1,1,-28.77488163974644, 153.5064697265625
1,1,-28.74117220459353, 153.10821533203125
1,1,-28.323724553546, 153.028564453125
1,2,-28.359984824037397, 153.12469482421875
1,2,-28.58693349906796, 153.1329345703125
1,2,-28.596580064634804, 153.43231201171875
1,2,-28.32130676215295, 153.39111328125
1,2,-28.359984824037397, 153.12469482421875

multi-part polygon:

1,1, -28.01584726281309, 153.39008331298828
1,1,-28.030015853768017, 153.38913917541504
1,1,-28.03024314216738, 153.40621948242188
1,1,-28.0140286990148, 153.4053611755371
1,1, -28.01584726281309, 153.39008331298828
1,2,-28.0140286990148, 153.41609001159668
1,2,-28.029182458863605, 153.41548919677734
1,2,-28.028955168224194, 153.43093872070312
1,2,-28.012740531077274, 153.4310245513916
1,2,-28.0140286990148, 153.41609001159668

More Handy Tools:
Free GIS Tools: Google Map
Free Address Validation Tool
Manual geocoder for 70 countries

For more useful tips please also see posts listed under “How to…” category.


Andy Rogers said...

I tried using csv_to_shapefile. Unfortunately, it identifies the units as "meters" even though they are decimal degrees, which confuses the Mapwindows program. It also labels the projcs as "unnamed". Is there someway to fix this? The data is Maryland state plane and decimal degrees . It was originally in feet, so I used the converter at http://beta.ngs.noaa.gov/gtkweb/ to convert it to lat long.

PROJCS["unnamed",GEOGCS["NAD83",DATUM["North_American_Datum_1983",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6269"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9108"]],AUTHORITY["EPSG","4269"]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",38.3],PARAMETER["standard_parallel_2",39.45],PARAMETER["latitude_of_origin",37.6666666666],PARAMETER["central_meridian",-77],PARAMETER["false_easting",400000],PARAMETER["false_northing",0],UNIT["Meter",1]]

All Things Spatial said...

Hi Andy, this task can now be easily accomplished with free QGIS software. Just import original csv without changing coordinates (set the project to NAD83 projection first). Then you can "save file as" shp... If you need to reproject, just set the project projection to whatever you need then "save as" again selecting project projection option. Or send me your file if you have any troubles (email address at the bottom of this page). Cheers.