1

I have a script that I run in ArcMap 10.5.1 that iterates through feature classes in a file geodatabase and projects each one to a WGS84 shapefile. This works smoothly for most feature classes in the geodatabase, but there is one feature class that is giving an odd error:

Traceback (most recent call last):
File "E:\ProvingGrounds\SCAT\Script\SCAT Shapefile Export 02.py", line 38, in <module>
    arcpy.Project_management(fc, outShape, spatialRef)
File "c:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\management.py", line 9523, in Project
raise e
ExecuteError: ERROR 999999: Error executing function.
The input featureclass fields and the Output fields do not have the same number of fields
Failed to execute (Project).

This seems strange since arcpy.Project_management is creating the output from the input. The feature class in question is as simple as it gets, a single feature polyline with no attributes other than ObjectID and Shape_length.

Here is the script that generates the error:

import arcpy, os
arcpy.env.overwrite = True

scatFolder = arcpy.GetParameterAsText(0)
gdb = os.path.join(scatFolder, "scatprocessing.gdb")
shapeFolder = os.path.join(scatFolder, "ShapeFiles")
spatialRef = arcpy.SpatialReference("WGS 1984") 

if arcpy.Exists(gdb):

    if not os.path.exists(shapeFolder):
        arcpy.AddMessage("\nCreating shapefile folder\n")
        os.makedirs(shapeFolder)

    arcpy.env.workspace = gdb
    featureClasses = arcpy.ListFeatureClasses()
    for fc in featureClasses:
        arcpy.AddMessage("Exporting " + fc + " to shapefile")
        outShape = os.path.join(shapeFolder, fc)

        arcpy.Project_management(fc, outShape, spatialRef)

The standalone Project tool in the Management Toolbox works as advertised on the same feature class using the same parameters. It is only when iterating through feature classes (to do the same thing) that it throws the error on that feature class.

  • What happens when you run the Project tool using the same parameter values that your script is passing to it? You can print those values immediately before using them. – PolyGeo Sep 21 '17 at 22:34
  • The standalone Project tool in the Management Toolbox works as advertised on the same feature class using the same parameters. It is only when iterating through feature classes (to do the same thing) that it throws the error on that feature class. – spaine Sep 21 '17 at 22:42
  • Please use the edit button beneath your question to revise it with any requested information. I think you should add the print statements that I suggested, and show us the output, then include a screen shot of your tool dialog being run manually. – PolyGeo Sep 21 '17 at 22:50
  • "The input featureclass fields and the Output fields do not have the same number of fields" offers a hint that maybe you should check the number of fields in both your input and output feature classes. Since Project_management is intended to create a new output feature class I wonder whether you are naming an existing one. – PolyGeo Sep 22 '17 at 0:53
  • Do the input FC have more than 255 fields? A shapefile cant have more than 255 fields so maybe that is the reason Project fail. – BERA Sep 22 '17 at 6:47
1

Since you're creating a feature class in a folder, it needs to be a shapefile file name.

outShape = os.path.join(shapeFolder, fc + ".shp")
| improve this answer | |
  • I don't think so, because the other feature classes in the file geodatabase are exported to shapefiles, just this one feature class was causing the error. – spaine Sep 22 '17 at 17:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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