Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
podcast
Filter by Categories
ArcGIS Pro
GDAL
Map
Python
QGIS
Uncategorized

Converting Between KML and Shapefiles

A Comprehensive Guide to Converting Between KML and Shapefiles

Working with geospatial data often involves dealing with multiple file formats to accommodate various software, platforms, and workflows. Among the most common geospatial file formats are KML (Keyhole Markup Language) and shapefiles (SHP), each with its unique characteristics and capabilities.

While KML is an XML-based format widely used in Google Earth, shapefiles are the industry-standard format for GIS applications like ESRI ArcGIS and QGIS. In this blog post, we will explore the ins and outs of converting between KML and shapefile formats, discuss the common challenges and issues that might arise during the process, and provide step-by-step guides for performing these conversions using popular tools like GDAL, QGIS, and ArcGIS Pro.

Throughout our conversation, we will touch on key topics, such as geometry support, attribute handling, styling, and symbology, coordinate systems, and file structure, to help you understand the crucial aspects of each file format.

Additionally, we will offer practical advice on how to tackle potential problems and ensure a smooth, successful conversion between KML and shapefile formats. Whether you’re a GIS professional or a geospatial enthusiast, this blog post will equip you with the knowledge and skills to effectively convert and manage your geospatial data.

Converting between KML and shapefile (SHP) format

KML (Keyhole Markup Language) and shapefile (SHP) are two popular formats for storing geospatial data. KML is an XML-based format mainly used by Google Earth, while shapefiles are the industry-standard format used by GIS (Geographic Information System) software like ESRI ArcGIS and QGIS. To convert between these two formats, you can use open-source tools like GDAL, QGIS, or ArcGIS Pro.

Step-by-step guide for converting between KML and shapefile formats using GDAL:

Using GDAL: GDAL (Geospatial Data Abstraction Library) is an open-source library for working with geospatial data. You can use the command-line tool “ogr2ogr” included in GDAL to convert between KML and shapefile formats.

  • Install GDAL: For Windows: You can use the OSGeo4W installer (https://trac.osgeo.org/osgeo4w/) to install GDAL and other geospatial tools. For Linux: Use your distribution’s package manager to install GDAL (e.g., sudo apt-get install gdal-bin for Ubuntu).
  • Convert KML to shapefile: Run the following command in your terminal or command prompt:
ogr2ogr -f "ESRI Shapefile" output_shapefile.shp input_kml.kml
  • Convert shapefile to KML: Run the following command in your terminal or command prompt:
ogr2ogr -f "KML" output_kml.kml input_shapefile.shp

Step-by-step guide for converting between KML and shapefile formats using QGIS:

QGIS is an open-source desktop GIS application that can be used to visualize, edit, and analyze geospatial data. You can also use QGIS to convert between KML and shapefile formats.

Install QGIS: Visit the QGIS website (https://www.qgis.org/) to download and install the software on your computer.

Convert KML to shapefile:

  1. Open QGIS.
  2. Go to “Layer” > “Add Layer” > “Add Vector Layer” or press Ctrl+Shift+V.
  3. In the “Data Source Manager” window, select “File” and browse to your KML file.
  4. Click “Add” to load the KML file into QGIS.
  5. Right-click on the loaded KML layer in the “Layers” panel and select “Export” > “Save Features As…”
  6. Choose “ESRI Shapefile” as the format and set your output location and file name.
  7. Click “OK” to start the conversion.

Convert shapefile to KML:

  1. Open QGIS.
  2. Go to “Layer” > “Add Layer” > “Add Vector Layer” or press Ctrl+Shift+V.
  3. In the “Data Source Manager” window, select “File” and browse to your shapefile (.shp).
  4. Click “Add” to load the shapefile into QGIS.
  5. Right-click on the loaded shapefile layer in the “Layers” panel and select “Export” > “Save Features As…”
  6. Choose “Keyhole Markup Language (KML)” as the format and set your output location and file name.
  7. Click “OK” to start the conversion.

These methods will help you convert between KML and shapefile formats using GDAL and QGIS. Note that, during conversion, some attributes or styling may not be preserved perfectly, so you might need to edit the output files to ensure the data is accurately represented.

Step-by-step guide for converting between KML and shapefile formats using ArcGIS Pro:

In ArcGIS Pro, you can convert KML files to shapefiles and vice versa using the built-in geoprocessing tools. Here’s a step-by-step guide on how to perform these conversions in ArcGIS Pro:

Convert KML to shapefile:

  • Open ArcGIS Pro and create or open a project.
  • In the “Insert” tab, click “Toolbox” to open the Geoprocessing pane.
  • Search for the “KML To Layer” tool in the search box, and click on it to open its settings.
  • For the “Input KML File,” click the browse button and select the KML file you want to convert.
  • For the “Output Location,” choose the folder where you want the output to be saved.
  • Click “Run” to execute the conversion. The tool will create a file geodatabase containing the converted data as feature classes. The feature classes will be added to the map in ArcGIS Pro.
  • To convert the feature class into a shapefile, right-click the feature class in the Contents pane, select “Data” > “Export Features.”
  • In the “Feature Class to Feature Class” window, select the “Output Location” and type the desired “Output Feature Class” name with a “.shp” extension.
  • Click “Run” to create the shapefile.

Convert shapefile to KML:

  • Open ArcGIS Pro and create or open a project.
  • Add the shapefile you want to convert to KML by clicking on the “Map” tab and selecting “Add Data” or by dragging and dropping the shapefile into the map view.
  • In the “Insert” tab, click “Toolbox” to open the Geoprocessing pane.
  • Search for the “Layer To KML” tool in the search box, and click on it to open its settings.
  • For the “Layer” field, select the shapefile layer you added earlier.
  • For the “Output File,” click the browse button and choose the location where you want to save the KML file, and provide a file name with a “.kml” extension.
  • Click “Run” to execute the conversion. The tool will create a KML file that can be used in Google Earth or other KML-compatible applications.

By following these steps, you can convert KML files to shapefiles and shapefiles to KML files using ArcGIS Pro. Remember that KML files might contain multiple layers or nested folders. When converting KML files to shapefiles, you may need to repeat the process for each layer or feature class contained within the KML file.

Common issues when converting between KML and shapefiles

When converting between KML and shapefiles, you may encounter several common issues due to differences in data models, supported geometries, attribute handling, and coordinate systems. Here are some of the most common issues:

  1. Loss of attributes or data: KML and shapefiles may store attributes differently. During conversion, some attributes may not be transferred correctly or could be lost altogether. After conversion, you should check the attribute table to ensure that all necessary information is preserved.
  2. Loss of styles or symbology: KML files can contain rich styling and symbology information, while shapefiles have more limited styling capabilities. As a result, any advanced styling or symbology in a KML file may be lost during the conversion to a shapefile.
  3. Geometry limitations: Shapefiles support points, lines, and polygons, while KML also supports more complex geometries like multigeometries, 3D models, and GroundOverlays. When converting a KML file with complex geometries to a shapefile, these geometries may be lost or converted to simpler types.
  4. Z (elevation) and M (measure) values: Shapefiles can store Z and M values, while KML files generally store elevation as part of the coordinate information. During conversion, Z values may be lost, or you may need to adjust your settings to ensure the elevation information is preserved.
  5. Coordinate system issues: KML files use the WGS84 geographic coordinate system (EPSG:4326), while shapefiles can support various coordinate systems. When converting between these formats, make sure to specify the appropriate coordinate system or reproject the data as needed.
  6. Nesting and hierarchical structures: KML files can have nested folders and complex hierarchical structures that cannot be directly represented in a shapefile format. When converting a KML file to a shapefile, this hierarchy will be flattened, which can lead to duplicated features or loss of organization.
  7. Text encoding: Shapefiles use a different character encoding compared to KML files. KML files are encoded in UTF-8, while shapefiles typically use the local system encoding or a specified encoding in an accompanying .cpg file. This can lead to issues with special characters or non-Latin scripts during conversion.
  8. Large file sizes: KML files are usually smaller in size than shapefiles due to their XML-based format. However, when converting a KML file to a shapefile, the file size may increase significantly. In some cases, this can cause performance issues or difficulties when sharing files.

To mitigate these issues, always verify the output data after conversion to ensure that geometries, attributes, and styles are preserved correctly. You may need to make manual adjustments or use additional tools to handle specific issues, such as reprojecting data or modifying attribute tables.

Here’s a table comparing shapefile and KML file formats:

FeatureShapefile (SHP)Keyhole Markup Language (KML)
File StructureMultiple files (SHP, SHX, DBF, PRJ, etc.)Single XML-based file
Geometry TypesPoints, Lines, Polygons, MultipointsPoints, Lines, Polygons, Multigeometries, 3D models
AttributesStored in a DBF fileStored as XML elements within the KML file
Styling and SymbologyLimited styling capabilitiesRich styling and symbology support
Coordinate SystemSupports various coordinate systemsWGS84 geographic coordinate system (EPSG:4326)
Z (Elevation) and M valuesSupports Z and M valuesElevation stored in coordinate information
Text EncodingLocal system encoding or specified in .cpg fileUTF-8
Nesting and HierarchyFlat structure, no hierarchySupports nested folders and complex hierarchical structures
File SizeUsually larger than KML filesUsually smaller than shapefiles
This table provides a general comparison between shapefile and KML file formats, highlighting their main differences in terms of structure, geometry types, attributes, styling, coordinate systems, and other features. Keep in mind that when converting between these formats, some information may be lost or altered due to their inherent differences.
About the Author
I'm Daniel O'Donohue, the voice and creator behind The MapScaping Podcast ( A podcast for the geospatial community ). With a professional background as a geospatial specialist, I've spent years harnessing the power of spatial to unravel the complexities of our world, one layer at a time.

Leave a Reply