[GIS] Trying to re-project a folder of shapefiles using Python Script

arcmaparcpypython

I am trying to reproject multiple shapefiles in a folder. When I run my program this is the error I am getting:

line 8221, in Project
raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000670: output Output Dataset or Feature Class is same as input Input Dataset or Feature Class
Failed to execute (Project).

I checked my code and I'm not seeing what Im doing wrong. What could be the issue here?

# Import system modules
import arcpy
import os

# Set environment settings
arcpy.env.workspace = "C:\\users\\data\\shapefile_roads"
arcpy.env.overwriteOutput = True
outWorkspace = "C:\\users\\data\\shapefile_roads"

for infc in arcpy.ListFeatureClasses():

        # Determine if the input has a defined coordinate system, can't project it if it does not
    dsc = arcpy.Describe(infc)

    if dsc.spatialReference.Name == "Unknown":
        print ('skipped this fc due to undefined coordinate system: ' + infc)
    else:
        # Determine the new output feature class path and name
        outfc = os.path.join(outWorkspace, infc)

        # Set output coordinate system
        outCS = arcpy.SpatialReference('WGS 1984')

        # run project tool
        arcpy.Project_management(infc, outfc, outCS)

        # check messages
        print(arcpy.GetMessages())

Best Answer

Your output dataset has the same name as your input dataset. Try setting a different workspace for the output, like: outWorkspace = "C:\\users\\data\\shapefile_roads_projected"

Related Question