Select to view content in your preferred language

Python: Output Dataset or Feature Class is same as input Input Dataset

3684
4
06-30-2015 07:23 AM
awei
by
Occasional Contributor

I want to project certain vectors in my folder so I wrote the following code. It gives me error message:

  File "F:/soil/python/code-project", line 34, in <module>

    arcpy.Project_management(infc, outfc, outCS)

  File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\management.py", 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'm pretty sure my input and output workspace is not the same. Here's the code:

import arcpy
import os


arcpy.env.workspace = "F:/soil/python"
arcpy.env.overwriteOutput = True
outWorkspace = "D:/soil/project"
feature_classes = []
outCS = arcpy.SpatialReference()
outCS.factoryCode = 3174
outCS.create()


walk = arcpy.da.Walk(arcpy.env.workspace, datatype="FeatureClass", type="Polygon")


for dirpath, dirnames, filenames in walk:
        if "Subbasin" in filenames:
            filenames.remove('Subbasin')
        for filename in filenames:
            feature_classes.append(os.path.join(dirpath, filename))
            
print feature_classes


           
for infc in feature_classes:
    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)


        # project data
        arcpy.Project_management(infc, outfc, outCS)

Thanks for any help!!!

0 Kudos
4 Replies
TomSellsted
MVP Regular Contributor

a wei,

Do the coordinate systems have a different datum?  If so, it might be necessary to include a transform method in your parameters.

Regards,

Tom

0 Kudos
JakeSkinner
Esri Esteemed Contributor

Hi Wei,

I think the problem is with how you are setting the outfc variable.  It looks like you are joining "D:/soil/project" to the full path of the infc.  I would add a print statement for the outfc.  I believe it's going to be:

D:\soil\project\F:\soil\python\[feature class]

0 Kudos
awei
by
Occasional Contributor

It's not. It's the original location of the input file.

0 Kudos
JakeSkinner
Esri Esteemed Contributor

Try the following:

for infc in feature_classes:
    infc = infc.split("\\")[-1]
    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)  
  
        # project data  
        arcpy.Project_management(infc, outfc, outCS)