File Exchange

image thumbnail

KML-Matlab-Shapefile conversion

version 1.2 (5.21 KB) by

Matlab script to import KML files into Matlab as well as conversion to Shapefile.



View License

Matlab script to read KML files into a mapstruct structure array and offers the option of writing to a Shapefile. KML files must be of a uniform type: Point, LineString, LinearRing or
Polygon. The output contains 5-6 fields, 'Geometry', 'X', 'Y', 'altitude', 'Id' and 'name'. The final field is created and populated only if there is exactly one <name> tag for each feature - these are the names that are used in Google Earth for labeling. This mapstruct array can be easily displayed in Matlab using the 'mapshow' or 'geoshow' command. This output format allows exporting to a Shapefile using the Matlab command, 'shapewrite', which is initiated by entering an output filename into the function. This conversion requires Matlab version 2008a or a more recent version.

Comments and Ratings (5)

Xiaoning Yang

Works great. But, doesn't it generate a geostruct instead of a mapstruct? If so, the fields X and Y should be Lon and Lat.

Anna Kelbert

Thanks Michael for submitting this script. It works great to load the USGS kmz files (after unzipping). Had to comment out the altitude. The writing crashes for me, but that's ok.

ZZL Zhang

It works very well.

Dear Michael,

I have downloaded your code, but I do not know how to use it (I am quite new in matlab...).I write:

and it does not work, I get:
??? Error: File: kml_shapefile.m Line: 1 Column: 11
Unexpected MATLAB expression.

Could you help me on this?




Eliza (view profile)

Really great code, thanks!



June 1, 2010 : Small change to the help information/description to correct a typo. The code itself is exactly the same.

MATLAB Release
MATLAB 7.6 (R2008a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video