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.
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.
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.
It works very well.
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?
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.
Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.