shapefile

Basic Steps for Converting an ArcMap Shapefile to GeoJSON

The process of converting a shapefile to GeoJSON is straight forward – it just requires a few steps.  While GeoJSON can handle multiple types (e.g., points, lines, and polygons) simultaneously in one file, a single shapefile cannot.  Therefore, this overview asks you to select and use a single shapefile.

 

Step 0.  If necessary, create the point, line, or polygon that you wish to make into a shapefile. Then save as feature (e.g., Drawing -> Convert Graphics to Features -> Save as shapefile).

 

Step 1.  Select a shapefile that you wish to convert.  This shapefile may contain one or more records, but note that everything will be converted.  If you want select records, then you need to select these records and save them to their own shapefile first (e.g., Data -> Export Data -> Selected features to an output feature class).

 

Step 2.  Convert shapefile layer to KML using ArcToolbox (i.e., ArcToolbox -> Conversion Tools -> To KML -> Layer to KML; see Example 1). 

 

Step 3.  Use an online conversion tool to convert KML (.kmz) file to GeoJSON.  One tool is to use http://ogre.adc4gis.com/ to upload the KML (*.kmz) file and convert it to GeoJSON.  Using this web site, in the “Convert to GeoJSON” section, under “File*:” Browse to and choose your file. Then select “Convert to GeoJSON”.  This will generate GeoJSON code and display in a new window (Example 2).

 

Step 4. Clean up GeoJSON code and validate using online tool.  The online KML-to-GeoJSON tool will add some extra (and potentially unnecessary) code to the GeoJSON export file.  You can clean this up by trimming unnecessary stuff at the beginning of the code, if desired (Example 3).  Validate your KML-to-GeoJSON conversion by copying and pasting the GeoJSON code into window at http://geojsonlint.com/, then “Test GeoJSON”.  If code is correct, this will display your location on a map (Example 4).

 

 

Example 1 (for Step 2). ArcMap Layer To KML

 

Example 2 (for Step 3). GeoJSON output:

{

"type": "FeatureCollection",

"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },

"features": [

{ "type": "Feature", "properties": { "Name": "3N 2E 14", "Description": "<html xmlns:fo=\"http:\/\/www.w3.org\/1999\/XSL\/Format\" xmlns:msxsl=\"urn:schemas-microsoft-com:xslt\"> <head> <META http-equiv=\"Content-Type\" content=\"text\/html\"> <meta http-equiv=\"content-type\" content=\"text\/html; charset=UTF-8\"> <\/head> <body style=\"margin:0px 0px 0px 0px;overflow:auto;background:#FFFFFF;\"> <table style=\"font-family:Arial,Verdana,Times;font-size:12px;text-align:left;width:100%;border-collapse:collapse;padding:3px 3px 3px 3px\"> <tr style=\"text-align:center;font-weight:bold;background:#9CBCE2\"> <td>3N 2E 14<\/td> <\/tr> <tr> <td> <table style=\"font-family:Arial,Verdana,Times;font-size:12px;text-align:left;width:100%;border-spacing:0px; padding:3px 3px 3px 3px\"> <tr> <td>FID<\/td> <td>0<\/td> <\/tr> <tr bgcolor=\"#D4E4F3\"> <td>TRS<\/td> <td>T 03 NR 02  E 014<\/td> <\/tr> <tr> <td>SECTION<\/td> <td>14<\/td> <\/tr> <tr bgcolor=\"#D4E4F3\"> <td>TOWNRANGE<\/td> <td>T 03 NR 02  E<\/td> <\/tr> <tr> <td>NAME<\/td> <td>3N 2E 14<\/td> <\/tr> <tr bgcolor=\"#D4E4F3\"> <td>SHAPE_area<\/td> <td>2614561.62831<\/td> <\/tr> <tr> <td>SHAPE_len<\/td> <td>6468.228208<\/td> <\/tr> <\/table> <\/td> <\/tr> <\/table> <\/body> <\/html>" }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ -116.173349131967598, 43.592406515151097, 0.0 ], [ -116.173352859582806, 43.593335222258943, 0.0 ], [ -116.173396030892604, 43.596506495703117, 0.0 ], [ -116.173396357521995, 43.596978493872442, 0.0 ], [ -116.173429829365304, 43.600636779777894, 0.0 ], [ -116.1734632166457, 43.60429517589948, 0.0 ], [ -116.178454329840307, 43.604295613848862, 0.0 ], [ -116.183445427704896, 43.604296350172127, 0.0 ], [ -116.185447407007501, 43.604296599339797, 0.0 ], [ -116.188436440883095, 43.604296869883413, 0.0 ], [ -116.193427530174006, 43.604297409623172, 0.0 ], [ -116.193437078656203, 43.602773711537658, 0.0 ], [ -116.193442252650499, 43.60194291747883, 0.0 ], [ -116.193445231076893, 43.600678221453641, 0.0 ], [ -116.193469630636997, 43.597072124086402, 0.0 ], [ -116.193518556624994, 43.593476839137871, 0.0 ], [ -116.193567485386694, 43.589881552188587, 0.0 ], [ -116.188515271107704, 43.589833819143387, 0.0 ], [ -116.183463067880098, 43.589786194180107, 0.0 ], [ -116.178410776930804, 43.589738752944257, 0.0 ], [ -116.173358558431204, 43.589691012943547, 0.0 ], [ -116.173349131967598, 43.592406515151097, 0.0 ] ] ] ] } }

]

}

 

Example 3 (Step 4). Trimmed GeoJSON Code.

{ "type": "MultiPolygon", "coordinates": [ [ [ [ -116.173349131967598, 43.592406515151097, 0.0 ], [ -116.173352859582806, 43.593335222258943, 0.0 ], [ -116.173396030892604, 43.596506495703117, 0.0 ], [ -116.173396357521995, 43.596978493872442, 0.0 ], [ -116.173429829365304, 43.600636779777894, 0.0 ], [ -116.1734632166457, 43.60429517589948, 0.0 ], [ -116.178454329840307, 43.604295613848862, 0.0 ], [ -116.183445427704896, 43.604296350172127, 0.0 ], [ -116.185447407007501, 43.604296599339797, 0.0 ], [ -116.188436440883095, 43.604296869883413, 0.0 ], [ -116.193427530174006, 43.604297409623172, 0.0 ], [ -116.193437078656203, 43.602773711537658, 0.0 ], [ -116.193442252650499, 43.60194291747883, 0.0 ], [ -116.193445231076893, 43.600678221453641, 0.0 ], [ -116.193469630636997, 43.597072124086402, 0.0 ], [ -116.193518556624994, 43.593476839137871, 0.0 ], [ -116.193567485386694, 43.589881552188587, 0.0 ], [ -116.188515271107704, 43.589833819143387, 0.0 ], [ -116.183463067880098, 43.589786194180107, 0.0 ], [ -116.178410776930804, 43.589738752944257, 0.0 ], [ -116.173358558431204, 43.589691012943547, 0.0 ], [ -116.173349131967598, 43.592406515151097, 0.0 ] ] ] ] }

 

Example 4 (Step 4). Validated GeoJSON Code.

 

 

Create GPX (gps files) from ArcGIS Shapefiles or GoogleEarth KML files

For some, DNR garmin (http://www.dnr.state.mn.us/mis/gis/tools/arcview/extensions/DNRGarmin/DNRGarmin.html) may be enough for converting shapefiles to gpx files but this program may not always work - especially for large files. I have found it easiest to convert ArcGIS shapefiles to KML and then to GPX files.

Shapefile to KML

Depending on the content of your shapefile, there are two different options for creating a KML.

1)      Open-source Shp2kml, available at: http://www.zonums.com/shp2kml.html .  This would be my first choice.  The GUI is very straightforward and gives you quite a few options for customizing your KML, such as: the color scheme, roll-over effect, and which attributes are displayed.  NOTE: The list of acceptable Datums is kind of short.  Found it easiest to just re-project shapefiles to WGS84.  Also, found that this tool would not always work for shapefiles with especially long text attributes and/or multi-part polygons. (This is discussed in more detail in a past blog called Shapefile to Google Earth kml - Customize Symbol Properties and Labeling (NO PROGRAMMING REQUIRED!).

2)      Create a layer file of your shapefile and use the ‘Layer to KML’ tool in ArcGIS.  You have less authority over the output with this method.  Limited customization of color scheme can be done in Google Earth (unless you would like to program some fancy customizations).  NOTE: Actually saves the file as a KMZ; resave the KMZ as a KML for conversion to GPX in GoogleEarth.  If you are using this options, delete all of the attribute fields that you do not want to show up in Google Earth – this information pops up when the feature is clicked.

KML to GPX

Lots of options. 

1)      Open-source KML2GPX, available at: http://groups.google.com/group/kml-support-getting-started/msg/ec5e2ae637ed4bfc

3)      Open-source GPSbabel, available at: http://www.gpsbabel.org/

4)      Built-in tool on gpsies.com, available at: http://www.gpsies.com/convert.do

I know that DNR garmin and the tool on gpsies.com are not good for very large datasets.