kml contour plot

Create a Google Earth KML file with labelled contour lines.
Updated 15 Dec 2011

View License

This function can be called exactly the same as one would call MATLAB's CONTOUR function. It directly calls CONTOUR and then takes the output and converts it into a KML file, so that the contour lines display nicely and natively in Google Earth.

If you want to change the color and/or width of the contour lines, you will have to edit lines 38-40 of the function. There are some comments there to guide you.

KML_CONTOUR(LON,LAT,Z) writes contour lines in the same format as
KML_CONTOUR(LON,LAT,Z,N) draws N contour lines, overriding the
automatic value
KML_CONTOUR(LON,LAT,Z,V) draws LENGTH(V) contour lines at the values
specified in the vector V
KML_CONTOUR(LON,LAT,Z,[v v]) computes a single contour at the level v

LON: This can be either a matrix the same size as Z or a vector with
length the same as the number of columns in Z.
LAT: This can be either a matrix the same size as Z or a vector with
length the same as the number of rows in Z.
Z: Matrix of elevations

This function creates a kml file called 'doc.kml' in the current
working directory

for anyone interested, I also have a version written in Python available here:

Cite As

Cameron Sparr (2024). kml contour plot (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2010b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes

Changed the contour labelling algorithm so that it uses the MATLAB native scheme when given lon,lat,z as a grid, and the proprietary scheme when lon,lat are a list.

Added support for changing the color and width of the contour lines.

added link to python version