Python standalone script using ArcGIS Pro license

611
3
Jump to solution
09-06-2018 08:22 AM
JYI
by
Occasional Contributor

Hi,

I am writing some standalone code following the link KML To Layer—Conversion toolbox | ArcGIS Desktop (KMLToLayer example 2 (stand-alone script)) to try to convert a list of .KMZ files to .lyrx files, using ArcGIS Pro license. The sample .kmz file I used is attached. It can be opened from Google Earth. 

My testing code is as simple as this:

import arcpy
import os

# Set workspace (where all the KMZs are)
arcpy.env.workspace = r"C:\Work\Google_MASHUP\AdministrativeBoundary\ParkTest"

# Set local variables and location for the consolidated file geodatabase
out_location = r"C:\Work\ArcGIS_Layers_From_KMZ"

# Convert all KMZ and KML files found in the current workspace
for kmz in arcpy.ListFiles("*.km*"):
    print("CONVERTING: {0}".format(os.path.join(arcpy.env.workspace, kmz)))
    arcpy.KMLToLayer_conversion(kmz, out_location)

I got the error: 

arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input KML File: Dataset Dinosaur.kmz does not exist or is not supported
Failed to execute (KMLToLayer).

The printed result is: 

CONVERTING: C:\Work\Google_MASHUP\AdministrativeBoundary\ParkTest\Dinosaur.kmz, which is correct.

I am able to use the Geoprocessing tool KML to Layer directly from ArcGIS Pro window to convert the .KMZ successfully but not from the above code. 

Also, using the same code, with ArcGIS Server License, I am able to run it successfully. 

Could anybody give the suggestions on this error?

Thanks

JYI

0 Kudos
1 Solution

Accepted Solutions
JYI
by
Occasional Contributor

Solution: 

...... 

for kmz in arcpy.ListFiles("*.km*"):
    print("CONVERTING: {0}".format(os.path.join(arcpy.env.workspace, kmz)))

    kmzFile = os.path.join(arcpy.env.workspace, kmz)
    arcpy.KMLToLayer_conversion(kmzFile, out_location)

View solution in original post

0 Kudos
3 Replies
MichaelVolz
Esteemed Contributor

Did you get the print statement to fire and show the correct path to the kmz file?

0 Kudos
JYI
by
Occasional Contributor

Yes, it is correct:

CONVERTING: C:\Work\Google_MASHUP\AdministrativeBoundary\ParkTest\Dinosaur.kmz

0 Kudos
JYI
by
Occasional Contributor

Solution: 

...... 

for kmz in arcpy.ListFiles("*.km*"):
    print("CONVERTING: {0}".format(os.path.join(arcpy.env.workspace, kmz)))

    kmzFile = os.path.join(arcpy.env.workspace, kmz)
    arcpy.KMLToLayer_conversion(kmzFile, out_location)

0 Kudos