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
 

mer said:

Howsabout if it is in WGS84 (in original shp) and still goes to north pole?

april 5, 2010 18:38
 

TheMaxx said:

Has this been sorted by someone ?

"Error[im002][Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified."

As i am getting the same thing still..

juni 17, 2010 10:07
 

jjrdk said:

It sounds like you don't have the assisting database file.

juni 17, 2010 22:24
 

TheMaxx said:

In the folder where the shape file is, i have the following type files:

name.dbf

name.shp

name.shx

name.mwsr

name.prj

This all is in the same directory as the Shp2Kml Converter.exe....

What am i missing ?

Maybe some ODBC driver or something that is not loaded on the Machine ?

juni 18, 2010 11:58
 

jjrdk said:

This sounds very strange. Would you mind sending me the full error message you are getting?

juni 19, 2010 23:59
 

TheMaxx said:

Here is the full Error. I have  an Error window that shows the following:

"Unhandled exception has occured in your application....

ERROR [IM002][Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified.

If i click on the details, this is what i get:

************** Loaded Assemblies **************

mscorlib

   Assembly Version: 2.0.0.0

   Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)

   CodeBase: file:///C:/Windows/Microsoft.NET/Framework64/v2.0.50727/mscorlib.dll

----------------------------------------

ESRI Converter

   Assembly Version: 1.0.0.0

   Win32 Version: 1.0.0.0

   CodeBase: file:///C:/Projects/KMLCreator/Shp2Kml/Shp2Kml%20Converter.exe

----------------------------------------

System.Windows.Forms

   Assembly Version: 2.0.0.0

   Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)

   CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll

----------------------------------------

System

   Assembly Version: 2.0.0.0

   Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)

   CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll

----------------------------------------

System.Drawing

   Assembly Version: 2.0.0.0

   Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)

   CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll

----------------------------------------

System.Data

   Assembly Version: 2.0.0.0

   Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)

   CodeBase: file:///C:/Windows/assembly/GAC_64/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll

----------------------------------------

System.Xml

   Assembly Version: 2.0.0.0

   Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)

   CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll

----------------------------------------

System.Transactions

   Assembly Version: 2.0.0.0

   Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)

   CodeBase: file:///C:/Windows/assembly/GAC_64/System.Transactions/2.0.0.0__b77a5c561934e089/System.Transactions.dll

----------------------------------------

************** JIT Debugging **************

To enable just-in-time (JIT) debugging, the .config file for this

application or computer (machine.config) must have the

jitDebugging value set in the system.windows.forms section.

The application must also be compiled with debugging

enabled.

For example:

<configuration>

   <system.windows.forms jitDebugging="true" />

</configuration>

When JIT debugging is enabled, any unhandled exception

will be sent to the JIT debugger registered on the computer

rather than be handled by this dialog box.

juni 21, 2010 12:49
 

jmcbride2010 said:

Very nice tool! Downloaded the code but noticed the form files aren't included. Just trying to convert to VB.NET 2.0 (in vs 2005) and make some minor mods. Can I just create a similar form (w/ fields) and call the appropriate functions?

juli 7, 2010 21:59
 

jjrdk said:

There is nothing to the UI really. Just a form to select your file and determine which fields get merged to the description field in the KML output.

I would be much obliged if you would send me your VB code, and I will post it on the site.

juli 7, 2010 23:35
 

jmcbride2010 said:

Thanks for the quick reply!! I'd be happy to send you my VB code - just want to put some finishing touches on it. Would you prefer that I email it to you?

juli 8, 2010 17:21
 

jjrdk said:

Send me an email or a private message, what ever suits you best. If you haven't guessed the email then it's username at domain.

juli 8, 2010 20:28
Anonymous comments are disabled