ERROR 000732: Layer: File does not exist or is not supported (ArcPy)

4266
6
Jump to solution
11-20-2017 08:04 AM
GriffinWilliams
New Contributor

Hello GeoNet community, 

I am attempting to do some (basic) processing using ArcPy to speed up a workflow. Essentially, I have a ~100 shapefiles of property boundaries that I need to convert to .kml so that they can be visualized in Google Earth.

When I run the code which is pasted below I get ERROR 000732: Layer: File does not exist or is not supported. However, when I try to export one shapefile to .kml individually it exports successfully, when done in ArcGIS. (please note that if the statement "print file" is inserted after the "if. file.endswith('boudnary.shp')" the desired files are printed)

Thank you in advance for your time and energy, any comments and/or suggestions are greatly appreciated.

import os
import arcpy

kmz_out = r"Z:/outPath"



for dirpath, dirnames, filenames in os.walk(r"Z:/inPath"):
    for file in filenames:
        if file.endswith('boundary.shp'):
            arcpy.LayerToKML_conversion(layer="file",
                                        out_kmz_file="kmz_out",
                                        layer_output_scale="0", is_composite="NO_COMPOSITE",
                                        boundary_box_extent="DEFAULT", image_size="1024", dpi_of_client="96",
                                        ignore_zvalue="CLAMPED_TO_GROUND")
            print "boundary has been made"

0 Kudos
1 Solution

Accepted Solutions
MitchHolley1
MVP Regular Contributor

You may want to convert each .shp to an in-memory feature layer before running the LayerToKML tool.  

for dirpath, dirnames, filenames in os.walk(r"Z:/inPath"):
    for file in filenames:
        if file.endswith('boundary.shp'):
            shpPath = os.path.join(dirpath, file)
            arcpy.MakeFeatureLayer_management(shpPath,'featLyr')
            arcpy.LayerToKML_conversion(layer='featLyr',
                                        out_kmz_file="kmz_out",
                                        layer_output_scale="0", is_composite="NO_COMPOSITE",
                                        boundary_box_extent="DEFAULT", image_size="1024", dpi_of_client="96",
                                        ignore_zvalue="CLAMPED_TO_GROUND")
            print "boundary has been made"
            arcpy.Delete_management('featLyr')‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

6 Replies
MitchHolley1
MVP Regular Contributor

I think it's because your input "file" does not represent anything other than the string of 'file'.  Try the code below.  Line 11 is giving the variable 'layer' to the complete path of the shapefile.

import os
import arcpy

kmz_out = r"Z:/outPath"



for dirpath, dirnames, filenames in os.walk(r"Z:/inPath"):
    for file in filenames:
        if file.endswith('boundary.shp'):
            layer = os.path.join(dirpath, file)
            arcpy.LayerToKML_conversion(layer=layer,
                                        out_kmz_file="kmz_out",
                                        layer_output_scale="0", is_composite="NO_COMPOSITE",
                                        boundary_box_extent="DEFAULT", image_size="1024", dpi_of_client="96",
                                        ignore_zvalue="CLAMPED_TO_GROUND")
            print "boundary has been made"
GriffinWilliams
New Contributor

That you Mitch for your comment. Unfortunately, I am still running into the same error 000732. 

 

Here is the full error code

Traceback (most recent call last):

  File "C:/Users/Owner/PycharmProjects/Testing/Test.py", line 17, in <module>
ignore_zvalue="CLAMPED_TO_GROUND")
File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\conversion.py", line 2322, in LayerToKML
raise e
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Layer: Dataset Z:/KHCGIS/KLTData/Properties\Property_Owner_Name\Data\Andersen_Property_boundary.shp does not exist or is not supported
Failed to execute (LayerToKML).

 

Could this perhaps be a result of the mixing of forward/backslashes that are returned in the file path? If so, how would I go about fixing the slashes to be consistent?

Or is the error a result of line 17 ignore_zvalue"CLAMPED_TO_GROUND" -> as far as I am aware this is a default value

0 Kudos
DanPatterson_Retired
MVP Emeritus

Use raw notation 

r"C:\temp\somepath"

or if they are mixed up to begin with

a
'C:\\temp/somepath'

a.replace("/","\\")

'C:\\temp\\somepath'

Or some variant.  The best way is to get them right from the start using os.path and when hardcoding paths, use raw notation.  You can even split a path on the backslashed and use 'join' to piece the bits together.  In python 3, path control is a lot easier, so start reading the docs for the way forward.

GriffinWilliams
New Contributor

Thank you Dan, I have been able to now have the paths with all the slashes in a consistent orientation. 

However, I still get the error 000732 when running the script. Below is the error code. Do I have to convert the .shp files to .lyr files for this to work?

Traceback (most recent call last):
File "C:/Users/Owner/PycharmProjects/Testing/Test.py", line 20, in <module>
ignore_zvalue="CLAMPED_TO_GROUND")
File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\conversion.py", line 2322, in LayerToKML
raise e
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Layer: Dataset Z:\KHCGIS\KLTData\Properties\Property_Owner_Name\Data\Andersen_Property_boundary.shp does not exist or is not supported
Failed to execute (LayerToKML).

0 Kudos
DanPatterson_Retired
MVP Emeritus

feature or raster 'layer'  right from the help files...http://desktop.arcgis.com/en/arcmap/10.3/tools/conversion-toolbox/layer-to-kml.htm check the code example, they are using *.lyr files

MitchHolley1
MVP Regular Contributor

You may want to convert each .shp to an in-memory feature layer before running the LayerToKML tool.  

for dirpath, dirnames, filenames in os.walk(r"Z:/inPath"):
    for file in filenames:
        if file.endswith('boundary.shp'):
            shpPath = os.path.join(dirpath, file)
            arcpy.MakeFeatureLayer_management(shpPath,'featLyr')
            arcpy.LayerToKML_conversion(layer='featLyr',
                                        out_kmz_file="kmz_out",
                                        layer_output_scale="0", is_composite="NO_COMPOSITE",
                                        boundary_box_extent="DEFAULT", image_size="1024", dpi_of_client="96",
                                        ignore_zvalue="CLAMPED_TO_GROUND")
            print "boundary has been made"
            arcpy.Delete_management('featLyr')‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍