How to convert KML to shapefile: QGIS, ogr2ogr or online
To convert KML to a shapefile, open the KML in QGIS, right-click the layer, choose Export > Save Features As and pick ESRI Shapefile. On the command line, run ogr2ogr -f "ESRI Shapefile" with one geometry type per output. Or drop the .kml into FileReshape's KML to Shapefile converter, which runs in your browser without the file being uploaded, splits points, lines and polygons, and adds .prj and .cpg files.
What changes when KML becomes a shapefile
KML, the format of Google Earth and Google My Maps, and the shapefile store geographic data in very different ways, and every method of converting has to deal with the same differences. Knowing them in advance saves you from surprises in the result.
One geometry type per file. A KML file can mix points, lines and polygons in one folder. A shapefile can hold only one geometry type, so a mixed KML has to become several shapefiles, one per type.
Short field names. The .dbf attribute table allows field names of up to 10 characters, so Description becomes Descriptio. Text values longer than 254 characters, such as long HTML descriptions, are cut off.
No styles. Colors, line widths and icons are part of KML but not of a shapefile, so they are lost. If the styling matters, you have to recreate it in your GIS program.
Coordinate system. KML is always WGS84 longitude and latitude. The shapefile can stay in WGS84 with a .prj file that says so, or be reprojected to a system such as a UTM zone if you need distances and areas in meters. A shapefile also needs its .shp, .shx and .dbf parts kept together, and a .cpg file tells programs the text encoding.
Convert KML to shapefile in QGIS
QGIS is free and open source and reads KML through GDAL. It is the best choice when you also want to check, edit or restyle the data, or reproject it. When a KML has several folders or mixed geometry types, QGIS may show a dialog listing them as separate layers; add the ones you need and export each of them.
In the Save Vector Layer dialog you can also set the coordinate system of the output and the encoding. Choose UTF-8 so names with letters such as é, ø or ü survive. Repeat the export for each layer if the KML had points, lines and polygons.
- Open QGIS and drag the .kml file onto the map, or use Layer > Add Layer > Add Vector Layer.
- Right-click the layer in the Layers panel and choose Export > Save Features As.
- Set Format to ESRI Shapefile, choose a file name and, if needed, a different CRS.
- Click OK and check the new shapefile layer and its attribute table.
Convert KML to shapefile with ogr2ogr
ogr2ogr is GDAL's command-line converter. Use it for large files, for batch jobs over many KML files, and in scripts. Start with ogrinfo to see which layers the KML has; with GDAL's KML drivers, each KML folder is usually read as its own layer.
Because a shapefile holds only one geometry type, write each type to its own shapefile. The OGR SQL special field OGR_GEOMETRY lets you filter by type with -where or -sql. The -nlt option sets the geometry type of the output layer, and -nlt PROMOTE_TO_MULTI is useful when a layer mixes single and multi-part lines or polygons. If you skip the filtering, the shapefile gets the type of the first feature and features of other types cause errors.
Whether ExtendedData fields become columns depends on the KML driver in your GDAL build. The LIBKML driver reads them; check which drivers you have with ogrinfo --formats. Network links, which point to KML on a web server, are best downloaded and saved as a local KML first.
# List the layers (folders) and their geometry types
ogrinfo -so -al places.kml
# One shapefile per geometry type
ogr2ogr -f "ESRI Shapefile" places_points.shp places.kml -where "OGR_GEOMETRY='POINT' OR OGR_GEOMETRY='MULTIPOINT'" -explodecollections -nlt POINT -lco ENCODING=UTF-8
ogr2ogr -f "ESRI Shapefile" places_lines.shp places.kml -where "OGR_GEOMETRY='LINESTRING' OR OGR_GEOMETRY='MULTILINESTRING'" -nlt PROMOTE_TO_MULTI -lco ENCODING=UTF-8
ogr2ogr -f "ESRI Shapefile" places_polygons.shp places.kml -where "OGR_GEOMETRY='POLYGON' OR OGR_GEOMETRY='MULTIPOLYGON'" -nlt PROMOTE_TO_MULTI -lco ENCODING=UTF-8
# Optional: reproject to UTM zone 33N instead of keeping WGS84
ogr2ogr -f "ESRI Shapefile" -t_srs EPSG:32633 places_utm.shp places_points.shpConvert KML to shapefile online with FileReshape
FileReshape's KML to Shapefile converter does the same job in your browser, with no software to install. It uses GDAL compiled for the web, and the KML is read from your own disk and not uploaded, so it is safe for client data. The result is a .zip with .shp, .shx, .dbf, .prj and .cpg files for each shapefile.
The converter handles the usual problems for you. Points, lines and polygons are written to separate shapefiles, for example Sights_points.shp and Routes_lines.shp, and each KML folder becomes its own shapefile named after the folder. Field names are cut to 10 characters. By default the output stays in WGS84 with a .prj file, and you can choose another system such as a UTM zone. Altitudes are kept as 3D shapefiles. The attribute table is written as UTF-8 with a matching .cpg file.
Know its limits. Colors and icons are not carried over. The placemark name and description are kept, but extra fields stored as KML ExtendedData are not read by the browser version of GDAL. Network links that point to data on the web are not followed; the converter says how many it skipped. For a KMZ, first take the KML out with the KMZ to KML tool. The size limit is your browser's memory, and files up to about 200 MB normally work.
- Open the KML to Shapefile converter and drop your .kml file, or click to choose it.
- Optionally choose a coordinate system for the output, for example a UTM zone.
- Click Convert and download the .zip with the shapefiles, then unzip it and add the .shp files to your GIS.
Which method should you choose?
Use the browser converter for a one-off file when you just need a shapefile to send on or open in another program. Use QGIS when you want to check the result on a map, edit attributes, rebuild the styling or keep ExtendedData fields. Use ogr2ogr for very large files, for converting many files at once, or for automated workflows. If the recipient accepts GeoPackage, consider it instead: it has no 10-character limit on field names and can hold several layers in one file.
Frequently asked questions
Why do I get several shapefiles from one KML?
A shapefile can store only one geometry type. When your KML mixes points, lines and polygons, or has several folders, each type or folder becomes its own shapefile so no data is dropped.
Are Google Earth colors and icons kept?
No. A shapefile has no place for styles, so colors, line widths and icons are lost with every method. Restyle the layer in QGIS or your GIS program.
Can I convert a KMZ file to a shapefile?
Yes. A KMZ is a zipped KML. QGIS and ogr2ogr can usually read it directly. With FileReshape, use the KMZ to KML tool first and then convert the KML to a shapefile.
Is my KML uploaded when I convert it online with FileReshape?
No. The conversion runs in your browser and the file stays on your computer.
Why is the Description field called Descriptio?
Shapefile field names are limited to 10 characters by the .dbf format, so longer names are cut. Rename fields before converting, or use GeoPackage if long names matter.