Convert JXLS to KML: A Quick Guide for Geodata Conversion
Converting geospatial data stored in JXLS-formatted Excel files to KML (Keyhole Markup Language) enables visualization in mapping apps like Google Earth and many GIS tools. This guide walks through a straightforward, reliable workflow: extract coordinates from a JXLS spreadsheet, transform them into the KML structure, and validate the resulting file.
What you need
- A JXLS spreadsheet containing geographic coordinates (latitude, longitude) and optional attributes (name, description, style).
- A text editor or code environment (Python recommended).
- Python 3 and these packages: pandas, simplekml (install with
pip install pandas simplekml).
Step 1 — Inspect and prepare the JXLS file
- Open the spreadsheet and confirm column headers: at minimum have latitude and longitude. Common extra fields: name, description, altitude, style.
- Ensure coordinates are numeric and in decimal degrees. Remove rows with missing or invalid coordinates.
- Save a copy as XLSX if needed.
Step 2 — Load the spreadsheet (Python example)
Use pandas to read the sheet. Save this as convert_jxls_tokml.py and run with Python.
python
import pandas as pd from simplekml import Kml # Load spreadsheet (adjust filename and sheet name as needed) df = pd.read_excel(“input_jxls.xlsx”, sheetname=0) # Basic cleanup: drop rows without coords df = df.dropna(subset=[‘latitude’, ‘longitude’])
Step 3 — Create KML and add placemarks
Use simplekml to convert rows to placemarks. Include optional name/description if present.
python
kml = Kml() for , row in df.iterrows(): lat = float(row[‘latitude’]) lon = float(row[‘longitude’]) name = str(row.get(‘name’, “)) if ‘name’ in row else None desc = str(row.get(‘description’, ”)) if ‘description’ in row else None p = kml.newpoint(name=name, description=desc, coords=[(lon, lat)]) # Optional: set altitude or style if present if ‘altitude’ in row and not pd.isna(row[‘altitude’]): p.altitudemode = ‘absolute’ p.coordinates = [(lon, lat, float(row[‘altitude’]))]
Step 4 — Save the KML
python
kml.save(“output.kml”)
Step 5 — Validate and view
- Open output.kml in Google Earth or a KML-aware GIS. Verify placemarks appear in correct locations.
- If coordinates seem flipped or incorrect, confirm column mapping (latitude vs longitude) and sign conventions.
Tips and variations
- Batch conversion: loop through multiple files or sheets and append placemarks to the same KML.
- Styles: use simplekml to set icons, colors, and balloon content for richer display.
- Polylines/polygons: if your JXLS contains ordered coordinate sequences, convert them to LineString or Polygon objects instead of points.
- Large datasets: consider writing a KMZ (compressed KML) or using tiling/cluster strategies for performance.
Troubleshooting
- Missing coordinates: log and skip rows with invalid lat/lon.
- Non-decimal coordinates: convert DMS (degrees-minutes-seconds) to decimal degrees before conversion.
- Encoding issues in descriptions: ensure strings
Leave a Reply
You must be logged in to post a comment.