
Complete Guide: How to Convert Shapefile to KML
Shapefiles are the cornerstone of GIS data storage, but when you need to visualize your spatial data in Google Earth, share it with non-GIS users, or integrate it with web mapping applications, converting to KML (Keyhole Markup Language) format becomes essential. This comprehensive guide covers multiple conversion methods, troubleshooting tips, and best practices.
Understanding the Formats
Shapefile: A vector data format developed by Esri, consisting of multiple files (.shp, .shx, .dbf, .prj, etc.) that store geometric and attribute information.
KML (Keyhole Markup Language): An XML-based format designed for displaying geographic data in Earth browsers like Google Earth. It supports both vector and raster data with rich styling options.
What You’ll Need
Essential Files
- Shapefile (.shp) – Contains the geometry
- Index file (.shx) – Spatial index
- Attribute table (.dbf) – Feature attributes
- Projection file (.prj) – Coordinate system information (highly recommended)
Software Options
- Desktop GIS: QGIS (free), ArcGIS Pro, ArcMap
- Command Line: GDAL/OGR tools
- Online Tools: MyGeodata Converter, Mapshaper, QGIS Web
- Programming: Python with libraries like Fiona, Geopandas
Method 1: Using QGIS (Recommended for Beginners)
QGIS is free, open-source, and provides excellent conversion capabilities with full control over the process.
Step-by-Step Process
- Install and Launch QGIS
- Download from qgis.org
- Launch QGIS Desktop
- Load Your Shapefile
- Go to Layer → Add Layer → Add Vector Layer
- Click the “…” button next to Vector Dataset(s)
- Navigate to your .shp file and select it
- Click Add, then Close
- Check Coordinate Reference System
- Right-click the layer in the Layers Panel
- Select Properties → Source
- Verify the CRS is correct (WGS 84 EPSG:4326 is ideal for KML)
- Export to KML
- Right-click the layer in the Layers Panel
- Select Export → Save Features As…
- Set Format to “Keyhole Markup Language [KML]”
- Choose your output file name and location
- Under CRS, select “EPSG:4326 – WGS 84” if not already set
- Click OK
- Verify the Output
- Open the KML file in Google Earth
- Check that all features display correctly
- Verify attribute information is preserved
Advanced QGIS Options
Styling Options:
- Before exporting, style your layer in QGIS
- Colors, symbols, and labels will be preserved in the KML
Attribute Selection:
- In the export dialog, click Select Fields to Export
- Choose which attributes to include in the KML
Method 2: Using ArcGIS
ArcGIS Pro
- Load Data
- Add your shapefile to the map
- Ensure proper coordinate system
- Use Conversion Tool
- Open the Geoprocessing pane
- Search for “Layer To KML”
- Select your layer as input
- Specify output location
- Set Layer Output Scale (1 = full resolution)
- Run the tool
ArcMap (Legacy)
- Access Conversion Tools
- Go to ArcToolbox → Conversion Tools → To KML
- Double-click Layer to KML
- Configure Parameters
- Select your shapefile layer
- Set output KML file path
- Choose appropriate scale and image size
- Execute the tool
Method 3: Command Line with GDAL
For power users who prefer command-line tools or need to automate conversions:
# Basic conversion
ogr2ogr -f "KML" output.kml input.shp
# With coordinate system transformation
ogr2ogr -f "KML" -t_srs EPSG:4326 output.kml input.shp
# With specific attribute selection
ogr2ogr -f "KML" -select "NAME,POPULATION" output.kml input.shp
GDAL Installation
- Windows: Download from gisinternals.com
- Mac: Use Homebrew:
brew install gdal
- Linux: Use package manager:
sudo apt-get install gdal-bin
Method 4: Online Conversion Tools
Recommended Online Converters
MyGeodata Converter
- Upload all shapefile components (.shp, .shx, .dbf, .prj)
- Select KML as output format
- Download converted file
Mapshaper
- Drag and drop your shapefile
- Use the console command:
export format=kml
- Download the result
QGIS Web
- Browser-based version of QGIS
- No installation required
- Same process as desktop QGIS
Pros and Cons of Online Tools
Advantages:
- No software installation required
- Quick for simple conversions
- Accessible from any device
Limitations:
- File size restrictions
- Less control over conversion parameters
- Privacy concerns with sensitive data
- Limited styling options
Method 5: Python Programming Approach
For developers or users needing automated batch processing:
import geopandas as gpd
# Read shapefile
gdf = gpd.read_file('input.shp')
# Ensure WGS84 coordinate system
gdf = gdf.to_crs('EPSG:4326')
# Save as KML
gdf.to_file('output.kml', driver='KML')
Troubleshooting Common Issues
Coordinate System Problems
Issue: Features appear in wrong locations Solution:
- Ensure shapefile has a .prj file
- Reproject to WGS 84 (EPSG:4326) before conversion
- In QGIS: Vector → Data Management Tools → Reproject Layer
Large File Size
Issue: KML file is too large for Google Earth Solution:
- Simplify geometry: Vector → Geometry Tools → Simplify
- Reduce attribute data: Select only necessary fields during export
- Consider splitting into multiple files
Missing Attributes
Issue: Attribute information not showing in Google Earth Solution:
- Ensure attribute table (.dbf) is included
- Check field names for special characters
- Verify data types are supported
Projection Warnings
Issue: QGIS shows CRS transformation warnings Solution:
- Always include the .prj file
- Set project CRS to match your data before loading
- Use “Set Layer CRS” if projection file is missing
Best Practices for Optimal Results
Before Conversion
- Validate Your Data
- Check geometry validity: Vector → Geometry Tools → Check Validity
- Repair if necessary: Vector → Geometry Tools → Fix Geometries
- Optimize Attribute Table
- Remove unnecessary fields
- Use concise field names
- Ensure proper data types
- Set Appropriate Styling
- Apply symbology in your GIS software
- Use meaningful colors and symbols
- Set transparency if needed
During Conversion
- Choose Correct CRS
- Always use WGS 84 (EPSG:4326) for KML output
- Transform if your data uses a different projection
- Select Appropriate Scale
- Higher scale = more detail = larger file size
- Balance between detail and performance
- Include Relevant Attributes
- Only export attributes that will be useful
- Consider character limits for field names
After Conversion
- Test in Target Application
- Open in Google Earth
- Verify all features display correctly
- Check attribute information accessibility
- Validate File Structure
- Ensure KML is well-formed XML
- Check for encoding issues
- Optimize for Distribution
- Compress to KMZ if sharing
- Document coordinate system and data source
Advanced Considerations
Styling and Appearance
- KML supports rich styling including colors, icons, and labels
- Style your data in GIS software before conversion for best results
- Consider using network links for dynamic data
Performance Optimization
- Large datasets may cause performance issues in Google Earth
- Consider using KMZ (compressed KML) format
- Implement level-of-detail (LOD) for complex datasets
Coordinate System Considerations
- WGS 84 is the standard for KML
- Some local coordinate systems may cause distortion
- Always include projection information with your shapefile
Alternative Formats and Use Cases
When to Use KML
- Visualization in Google Earth
- Sharing with non-GIS users
- Web mapping applications
- Simple data distribution
When to Consider Other Formats
- GeoJSON: For web development
- GPX: For GPS devices
- SHP: For GIS analysis
- GeoPackage: For modern GIS workflows
Converting shapefiles to KML opens up new possibilities for data visualization and sharing. Whether you choose desktop GIS software like QGIS for full control, command-line tools for automation, or online converters for convenience, the key is understanding your data requirements and choosing the appropriate method.
Remember to always validate your coordinate reference system, test the output in your target application, and optimize for your specific use case. With proper preparation and the right tools, shapefile to KML conversion can be a straightforward process that significantly enhances your data’s accessibility and impact.
Quick Reference Commands
QGIS: Layer → Export → Save Features As → KML GDAL: ogr2ogr -f "KML" -t_srs EPSG:4326 output.kml input.shp
Python: geopandas.read_file('input.shp').to_crs('EPSG:4326').to_file('output.kml', driver='KML')
Need help with your GIS projects? This guide covers the most common scenarios, but complex datasets may require specialized approaches. Consider the specific requirements of your project and choose the method that best fits your technical expertise and available tools.