I have a string created from lxml's etree module in appropriate format for KML. It outputs ok as a KML file and opens in Google Earth ok. Here is the code for storing it:
stream_str = io.BytesIO(kml_str)
with open(f'{fname}.kml', 'wb') as f:
f.write(stream_str.getvalue())
Some of the KML files are growing to over 8 mb, so I am looking to store in zipped format.
Currently, I'm using the Python zipfile package.
with zipfile.ZipFile(f'{fname}.kmz', 'w', compression=zipfile.ZIP_STORED) as zf:
zf.writestr(f'{fname}.kml', stream_str.getvalue())
ZIP_STORED is the default compression, which is uncompressed. This KMZ opens in Google Earth ok, but doesn't give any advantage in storage size.
I've tried using compression=ZIP_LZMA and =ZIP_BZIP2 (https://docs.python.org/3/library/zipfile.html#zipfile.ZIP_BZIP2). Both save ok, and can be opened with WinZip to show a usable KML file. However, Google Earth does not open them. Going to the file menu and clicking Open, and pointing to the KMZ file results in Google Earth continuing to run and not actually opening anything.
How can I create KMZ in Python?
zipfile.ZIP_DEFLATED