Select to view content in your preferred language

Error creating output feature class when reprojecting shp files

177
4
Saturday
Labels (2)
LiamTyler
New Contributor

I'm trying to reproject shapefiles and I keep getting stuck with this error

 

ExecuteError: ERROR 000208: Error creating output feature class
Failed to execute (Project).

 

 https://imgur.com/a/2cfXVox 
Here is all of my code.

import arcpy
from arcpy import env
env.overwriteOutput = True
env.workspace = r"D:\GEOG3530\Ex4\DataEX4"

# List feature classes and their coordinate systems in given folder
folderFiles = arcpy.ListFeatureClasses()
for fc in folderFiles:
    fcdesc = arcpy.Describe(fc)
    print(str(fcdesc.basename) + " is in " + str(fcdesc.spatialReference.name))

for fc in folderFiles:
    fcdesc = arcpy.Describe(fc)
    infc = fc
    print(infc)
    outfc = "D:/GEOG3530/Ex4/Ex4proj/Ex4proj.gdb/Results/" + fcdesc.basename
    print(outfc)
    sref = arcpy.SpatialReference('USA Contiguous Lambert Conformal Conic')
    print(sref)
    arcpy.management.Project(infc, outfc, sref)

list feature class code block output:

CA_Cities_Selection is in GCS_WGS_1984
CA_Earthquakes is in GCS_WGS_1984
CA_Outline is in GCS_WGS_1984

for loop output before error occurs:

CA_Cities_Selection.shp
D:/GEOG3530/Ex4/Ex4proj/Ex4proj.gdb/Results/CA_Cities_Selection
<geoprocessing spatial reference object object at 0x000001BFCC5A3E70>

And here is the full error message

---------------------------------------------------------------------------
ExecuteError                              Traceback (most recent call last)
Cell In[27], line 9
      7 sref = arcpy.SpatialReference('USA Contiguous Lambert Conformal Conic')
      8 print(sref)
----> 9 arcpy.management.Project(infc, outfc, sref)

File ~\AppData\Local\Programs\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py:20421, in Project(in_dataset, out_dataset, out_coor_system, transform_method, in_coor_system, preserve_shape, max_deviation, vertical)
  20419     return retval
  20420 except Exception as e:
> 20421     raise e

File ~\AppData\Local\Programs\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py:20403, in Project(in_dataset, out_dataset, out_coor_system, transform_method, in_coor_system, preserve_shape, max_deviation, vertical)
  20399 from arcpy.arcobjects.arcobjectconversion import convertArcObjectToPythonObject
  20401 try:
  20402     retval = convertArcObjectToPythonObject(
> 20403         gp.Project_management(
  20404             *gp_fixargs(
  20405                 (
  20406                     in_dataset,
  20407                     out_dataset,
  20408                     out_coor_system,
  20409                     transform_method,
  20410                     in_coor_system,
  20411                     preserve_shape,
  20412                     max_deviation,
  20413                     vertical,
  20414                 ),
  20415                 True,
  20416             )
  20417         )
  20418     )
  20419     return retval
  20420 except Exception as e:

File ~\AppData\Local\Programs\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py:532, in Geoprocessor.__getattr__.<locals>.<lambda>(*args)
    530 val = getattr(self._gp, attr)
    531 if callable(val):
--> 532     return lambda *args: val(*gp_fixargs(args, True))
    533 else:
    534     return convertArcObjectToPythonObject(val)

ExecuteError: ERROR 000208: Error creating output feature class
Failed to execute (Project).

I initially thought the problem was backslashes in the file path, but I switched those to forward slashes and it didn't fix it. I don't really understand how to read the error messages yet because I'm new to coding completely. 

At one point I also go this error.

 

ExecuteError: 000354: The name contains invalid characters.

 

I'm not really sure what I'm missing here. I appreciate all help, thanks.

 

 

Tags (2)
Discover the magic of the internet at Imgur, a community powered entertainment destination. Lift your spirits with funny jokes, trending memes, entertaining gifs, inspiring stories, viral videos, and so much more from users.
0 Kudos
4 Replies
DanPatterson
MVP Esteemed Contributor

Try adding a ValidateTableName into your code and dump the /Result/ section of your output environment path

Validating table and field names in Python—ArcGIS Pro | Documentation


... sort of retired...
0 Kudos
BrendanNewell
Esri Contributor

Can you confirm that the output does not have any special characters or spaces in the output name..?

0 Kudos
ModyBuchbinder
Esri Regular Contributor

In your code the var outfc  have a feature dataset named Results.

Does it exists?

0 Kudos
Robert_LeClair
Esri Esteemed Contributor

With a little help from the internet, I "wrote" this script that defines input folder/output file geodatabase location, sets the output spatial reference, lists the shapefiles in the folder with their coordinate system and projects them to USA Continuous Lambert Conformal Conic.  You'll need to change the input_folder and output_gdb but it "should" work:

# Define input folder and output geodatabase

input_folder = r"C:\temp\shapefiles"

output_gdb = r"C:\temp\shapefiles\test.gdb"

 

# Set the spatial reference (e.g., WGS 1984, EPSG:4326)

spatial_ref = arcpy.SpatialReference(102004)

 

# List feature classes and their coordinate systems in given folder

folderFiles = arcpy.ListFeatureClasses()

for fc in folderFiles:

    fcdesc = arcpy.Describe(fc)

    print(str(fcdesc.basename) + " is in " + str(fcdesc.spatialReference.name))

 

# Loop through all shapefiles in the input folder

for file_name in os.listdir(input_folder):

    if file_name.endswith(".shp"):

        input_shapefile = os.path.join(input_folder, file_name)

        output_feature_class = os.path.join(output_gdb, os.path.splitext(file_name)[0])

       

        # Project the shapefile into the file geodatabase

        arcpy.Project_management(input_shapefile, output_feature_class, spatial_ref)

        print(f"Projected {file_name} to {output_feature_class}")

0 Kudos