HomeSoftware

logo

KML and KMZ

KML (Keyhole Markup Language) is an XML-based file format used to display geographic and spatial data in two‑dimensional or three‑dimensional maps. KMZ is its compressed version. We commonly use it to indicate points and paths (alignments) with Google Earth.

We can create a KML with some application, for example the cartographic viewer of the Cartographic and Geological Institute of Catalonia and inspect the code. I have done a test: a point Lleida - bridge over the Segre (vissir4).kml and a short path Lleida - Av Catalunya (vissir4).kml in the city of Lleida. Once the code is understood, we will be able to create other KML files directly from a text editor or generated as output from a program.

A concrete point

A concrete point with only one coordinate in geographic coordinates of longitude and latitude.

<kml xmlns="http://www.opengis.net/kml/2.2"><Document> <Placemark id="YKC3fZAvJdsMvtTAPkXdTqXLekrtTJwq"> <ExtendedData> <Data name="portColor"> <value>#c800ff </value> </Data> </ExtendedData> <Point> <coordinates> 0.6230486176957584,41.61004407558153 </coordinates> </Point> </Placemark> </Document> </kml>

A short path

We simply see that there is a list of coordinates that form our polyline. By changing them to others we will obtain other paths...

<kml xmlns="http://www.opengis.net/kml/2.2"><Document> <Placemark id="5qsKHhIhduKG0gmoLreRI8zfw0gaRFUt"> <ExtendedData> <Data name="portColor"> <value>#c800ff </value> </Data> </ExtendedData> <LineString> <coordinates> 0.6203969955767548,41.614597529710295 0.6195343396884709,41.61273547991922 0.6193877831637451,41.612381788411426 0.6195880821418314,41.612159929582646 0.6200183540221929,41.61189369798012 0.6243459520552221,41.609303006272285 0.6261840301640405,41.60823855846874 </coordinates> </LineString> </Placemark> </Document> </kml>

How to convert from KML to KMZ?

Simply compress our example.kml file into example.zip, and then change the extension .zip to .kmz.
And to convert from kmz to kml? Even easier, uncompress the kmz as if it were a zip file (it is).