2

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 <module>
    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, "", "", "")
0

1 Answer 1

2

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.

1
  • Touché. Fixed with Target_GDB = os.path.split(Description.catalogPath) [0]. Thanks.
    – Waterman
    May 23, 2018 at 23:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.