convert *.kmz to *.kml

Document created by Dan_Patterson Champion on Sep 24, 2016
Version 1Show Document
  • View in full screen mode

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: The specified item was not found.

Attachments

Outcomes