Tuesday, 3 July 2018

arcgis 10.2 - arcpy.FeatureClassToFeatureClass_conversion() gives ERROR 000732: Output Location: Dataset ... does not exist or is not supported?


I'm trying to write a script to convert CSV to Feature Class (overwriting if pre-existing).


Unfortunately my version of Arc (10.2.2) does not have "XYTableToPoint()" so I needed to find another way.


I employed the suggestion made by "GISI" in response to this question: "Event layer to feature class - fastest method?", but here is the error I'm getting:



Traceback (most recent call last):
File "Q:\scripts\CSVtoASMADPointFeatureClass.py", line 23, in
arcpy.FeatureClassToFeatureClass_conversion(Temp_Layer, Target_GDB, Target_FC_name, "", "" , "")
File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\conversion.py", line 1675, in FeatureClassToFeatureClass
raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Output Location: Dataset Q:\Data\Stations.gdb\Stations does not exist or is not supported
Failed to execute (FeatureClassToFeatureClass).

Apparently the problem is with my parameters.



When I read ESRI's documentation on FeatureClasstoFeatureClass I saw their first example using only the first 3 paramaters, so I figured I was fine to just use the first 3 as well (last 3 optional).


For example, I didn't think I should need the 5th parameter (Field Mappings) because I want all the fields exactly as they are in the original CSV.


What is wrong with the Parameters as used in the "FeatureClassToFeatureClass" Arcpy Tool below?


import arcpy
Source_CSV = r"\\int.ec\Data\Stations.csv"
Target_FC = r"Q:\Data\Stations.gdb\Stations"
Description = arcpy.Describe(Target_FC)
Target_FC_name = Description.name
Target_GDB = Description.catalogPath
Temp_Layer = "Temp_Layer"

SR = arcpy.Describe(Target_FC).spatialReference
arcpy.MakeXYEventLayer_management(Source_CSV, "Lng", "Lat", Temp_Layer, SR, "")
arcpy.FeatureClassToFeatureClass_conversion(Temp_Layer, Target_GDB, Target_FC_name, "", "", "")

Answer



If this code snippet produces the same error as your full code then it suggests that on the arcpy.FeatureClassToFeatureClass_conversion() line you are specifying a full pathname to a feature class instead of a location (geodatabase or folder) for your out_path


import arcpy
Source_CSV = r"\\int.ec\Data\Stations.csv"
Target_FC = r"Q:\Data\Stations.gdb\Stations"
Description = arcpy.Describe(Target_FC)
Target_FC_name = Description.name

Target_GDB = Description.catalogPath
Temp_Layer = "Temp_Layer"
SR = arcpy.Describe(Target_FC).spatialReference
arcpy.MakeXYEventLayer_management(Source_CSV, "Lng", "Lat", Temp_Layer, SR, "")
arcpy.FeatureClassToFeatureClass_conversion(Temp_Layer, Target_GDB, Target_FC_name, "", "" , "")

You seem to be assuming that arcpy.Describe().catalogPath returns a location. You should print(Target_GDB) to be certain about what it returns.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...