Last active
December 11, 2020 13:21
-
-
Save arashmad/252fbfd2a55c612a808261c27392d8a7 to your computer and use it in GitHub Desktop.
Creating .kmz file automatically using ESRI ArcPy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import arcpy | |
def mxdToKMZ(url): | |
if os.path.exists(path): | |
mxd_dir = os.path.split(path)[0] | |
kmz_dir = mxd_dir + "/kml" | |
os.mkdir(kmz_dir) | |
mxd = arcpy.mapping.MapDocument(r"path\to\mxd\file\name.mxd") | |
df = arcpy.mapping.ListDataFrames(mxd)[0] | |
layers = arcpy.mapping.ListLayers(mxd, "", df) | |
for layer in layers: | |
lyr_name = layer.name | |
kmz_name = + lyr_name + '.kmz' | |
arcpy.LayerToKML_conversion(layer, kmz_name) | |
else: | |
raise Exception("File not found. => Check .mxd file path.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment