Reimers.dk

.NET, AJAX and Google APIs brought together
Welcome to Reimers.dk Sign in | Join | Help
in Search

Jacob Reimers Weblog

ESRI Shapefile to KML Converter

A basic shapefile to KML utility has been added to the files section. The utility parses a shapefile and creates the equivalent Google Maps objects. At the same time it reads the corresponding .dbf file and displays the possible columns to add to the individual shapes.

A shapefile is in fact a collection of different files. The most important files in the collection are the .shp and the .dbf files (some would say the .shx file is essential also, but it is not parsed by the Shp2Kml parser). The .shp file contains the definition of all the shapes in a special binary format, while the .dbf file is a standard dBase file, which contains one record for each shape record.

A shape record can contain several Google Maps object, eg. a polyline shape record can contain several polylines which are not connected. So when transforming the shapefile to KML you may find that several objects have the same name and description. This is intentional. The alternative was to leave sub objects without name or description.

The functionality is very straightforward. Click the 'Load Shapefile' button to load the binary definition file (the .shp file). The converter will then parse the corresponding .dbf database and will present the available columns. The column to use for the name is set using the dropdown list, while the values to add to the description are selected in the checked listbox below. Finally you need to click the 'Write Kml' button to start writing your KML file to the selected location.

Note! The code is entirely written in C# and requires .NET 2.0 installed on the computer to work. If you regularly update your computer this should have been installed close to a year ago.

You can download it here.

Published 5. februar 2007 04:56 by jjrdk
Filed under: , ,

Comments

 

Manfred Mustermann said:

Fine tool.

september 4, 2007 01:34
 

ctm said:

You are a legend :) this is perfect, however (as per my email) would love to add an addition of being able to filter the export so only specific shapes get exported into the KML. If you could release this open source that would be brilliant.

oktober 4, 2007 19:02
 

sebae said:

Hi, I got an OutOfMemoryException when I convert a shape file to kml using this software.  How can I handle it?

Thanks in advance.

oktober 6, 2007 08:03
 

jjrdk said:

Could you maybe be more descriptive about how you get the exception?? Are you trying to convert a 2GB shapefile on an Win98 machine with 4MB memory? You give me nothing to work with.

oktober 6, 2007 08:50
 

vouillas said:

Hi Jacob! Thanks for this great tool, I was wondering if you could convert it to a console application so that we could execute it from a script with parameters? Or even better open the source code. Thanks in advance for you answer. Stf,

november 27, 2007 16:04
 

AlexD said:

As soon as I select shape file to convert  I  get an Unhandled exception--"Error[im002][Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified."

Thanks, Alex.

december 26, 2007 10:57
 

sceaton said:

I get the same error as AlexD :(  I had high hopes for this, too!

juli 3, 2008 17:09
 

bdguoqian said:

I want to know whether the C# code of this program is open?

If so, would you please offer it to me? I need it now.

Thank you.

september 8, 2008 08:25
 

curlej said:

When I run the application on a polygon, it places the .kml data at the north pole, rather than in the correct geographic location.  I have attempted this with multiple datasets and the same result.  Is there perhaps something that I am doing wrong?

september 11, 2008 20:23
 

meklke said:

When I run the application on a polygon, it places the .kml data at the north pole, rather than in the correct geographic location.  Same as curlej states below, did this get an answer?

oktober 8, 2008 20:21
 

jjrdk said:

This happens because you are not using WGS84 coordinates. You are going to have to provide a converter.

oktober 9, 2008 21:47
 

roynilanjana said:

I've tried downloading it........... But the .zip is not working......... what can be the possible reasons? I'm on Windows XP, ArcGIS 9.2,

november 4, 2008 07:45
 

jjrdk said:

I tried downloading it, and it works fine for me. Anyone else having problems?

november 4, 2008 20:32
 

prakashmkanive said:

ya i too facing t problem in downloading, i coun\ld not download as it directs to a downloadan aspx file and start downloading it

november 16, 2008 05:52
 

plmerry said:

Did not work for me all the data points ended up at Lat N90.000 and E180.000 instead of South Dekoda, USA.  This placed all the points a little out of my travel plans for this vacation.

juni 20, 2009 22:11
 

jjrdk said:

If your shapefiles don't use WGS84, then this will happen. You can download the source code and hook in your own coordinate converter to match whatever system you are using.

juni 21, 2009 14:12
 

hats said:

As soon as I select shape file to convert  I  get an Unhandled exception--"Error[im002][Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified."

Steve Hatfield

shatfield@geoshack.com

januar 22, 2010 16:23
Anonymous comments are disabled