0

I've written a script in Python for ArcGIS 10.1 in order to migrate from an outdated coordinate system to a newer one while at the same time updating from personal geodatabases (.mdb) to file geodatabases (.gdb)- Everything works fine except:

When the tool tries to copy OR reproject (which I guess has to copy data as well) from a database containing a feature class with the same name as the featuredataset it fails, giving a 000171 Error 'Failed to open output workspace.

Changing the name of the feature dataset to something else will make it work (i.e. database.gdb\different\same Changing the name of the feature class to something else will make it work (i.e. database.gdb\same\different)

I can see an easy workaround by just renaming stuff a couple of times, but I want to get to the bottom of it if possible- It's a very fringe case that doesn't affect many of the databases so I want to avoid more code just to handle this case if possible. It seems OK to create these duplicate names using normal methods (i.e. ArcCatalog won't stop you) and the inbuilt geo-processing tools in ArcToolbox (i.e. Project) don't fail in the same situation....it's just the arcpy library it seems?

(edit code added - Thanks to KimOs suggestion, the copy portion under the else statement now works- The projection still doesn't. All data has its projection defined correctly.)

            FCs =arcpy.ListFeatureClasses('*','All',dataset) # list feature classes within this feature dataset
            arcpy.AddMessage("Found these feature classes: " + str(FCs))
            for FC in FCs: # for the feature classes within a feature dataset
                descFC= arcpy.Describe(FC)
                if descFC.spatialReference.name == 'GD_1949_New_Zealand_Map_Grid': # reproject only NZMG data
                    arcpy.AddMessage(FC + " is NZMG, reprojecting to: " + newFD + descFC.baseName)
                    logging.info(FC + " is NZMG, reprojecting to: " + newFD + descFC.baseName)
                    arcpy.Project_management(FC, newFD + descFC.baseName, prjFile, 'New_Zealand_1949_To_NZGD_2000_3_NTv2', descFC.spatialReference)
                else: # else just copy it across
                    arcpy.AddMessage(FC + " is in " + str(descFC.spatialReference.name) + " , copying instead: " + newFD+ descFC.baseName)
                    logging.info(FC + " is in " + str(descFC.spatialReference.name) + " , copying instead: " + newFD+ descFC.baseName)
                    arcpy.Copy_management(FC,newFD + descFC.baseName, "FeatureClass")
  • Can you post a code snippet that we can follow to try and reproduce your problem, please? It should only need half a dozen or so lines I think. – PolyGeo Aug 14 '13 at 7:48
1

To copy a featureclass into a featuredataset it must have the same projection definition. You will need to define the projection when you create the featuredataset otherwise it will be undefined and so will not allow a featureclass with a projection to be added.

SR = arcpy.Describe(feature_class).spatialReference
arcpy.CreateFeatureDataset(workspace,fds_name,SR)

If you name the featureclass with the same name as the featuredataset you need to add an additional parameter "FeatureClass" to the Copy command:

arcpy.management.Copy(source_fc,"samename/samename","FeatureClass")

Better not to confuse humans by making them the same name, let alone confusing the computer software.

Project works just as well if the featuredataset is defined first with the correct spatial reference. The key is to create the featuredataset separately from the Copy or Project.

# copy demo Kimo
import arcpy
ws = "c:/workspace/scratch.gdb"
arcpy.env.workspace = "c:/workspace/scratch.gdb"
print arcpy.ListFeatureClasses()
print arcpy.ListDatasets()
# use earthquake in WGS84 and copy or project to a featuredataset with the same name
print arcpy.Describe("earthquake").spatialReference.name
# new spatial reference (NZTM)
sr = arcpy.SpatialReference(2193)
print sr.name
same = "nztm"
if not arcpy.Exists(same):
    arcpy.management.CreateFeatureDataset(ws,same,sr) # must have same spatial reference as contents
print arcpy.ListFeatureClasses("*","",same)
# copy or project featureclass into featuredataset
# arcpy.management.Copy("earthquake",same'/'+same,"FeatureClass") # must have data_type if same == same
arcpy.management.Project("earthquake",same+'/'+same,sr)
print arcpy.ListFeatureClasses("*","",same)
  • Project worked just fine, provided that the featuredataset was created first with the correct projection. Trying to get Project to create a featuredataset with a projection as well as copy a featureclass is apparently not supported. – KimO Aug 17 '13 at 21:47

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.