convert *.kmz to *.kml

7104
0
09-24-2016 06:15 PM

convert *.kmz to *.kml

A snippet, not big enough for a blog..

"""
Script:     kmz_kml.py
Author:     
Dan.Patterson@carleton.ca

References: many
Purpose: convert kmz to kml base script
"""
#import sys
import zipfile
#import glob
from xml.dom import minidom

def kmz_to_kml(fname):
    """save kmz to kml"""
    zf = zipfile.ZipFile(fname,'r')
    for fn in zf.namelist():
        if fn.endswith('.kml'):
            content = zf.read(fn)
            xmldoc = minidom.parseString(content)
            out_name = (fname.replace(".kmz",".kml")).replace("\\","/")
            out = open(out_name,'w')
            out.writelines(xmldoc.toxml())
            out.close()
        else:
            print("no kml file")
if __name__ == "__main__":
    fname = r"Drive:\Your_Path_here\GIS_central.kmz"
    kmz_to_kml(fname)
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

File for testing attached... just a simple bookmark

This document was generated from the following discussion: convert *.kmz to *.kml

Attachments
Version history
Last update:
‎12-12-2021 03:43 AM
Updated by: