I am trying to convert the feature classes in data.gdb to a new PCS per the code on this webpage:
import arcpy
import os
arcpy.env.workspace = "G:/W135thStCopy/data.gdb"
arcpy.env.overwriteOutput = True
outWorkspace = "G:/W135thStCopy/data_WebMerc.gdb"
try:
for infc in arcpy.ListFeatureClasses():
dsc = arcpy.Describe(infc)
if dsc.spatialReference.Name == "Unknown":
print ('skipped this fc due to undefined coord sys: ')
print (infc)
else:
#Determine the new outpurt feature class
outfc = os.path.join(outWorkspace, infc)
#Set output coord sys
outCS = arcpy.SpatialReference('WGS 1984 Web Mercator Auxiliary Sphere')
break
#Run project tool
arcpy.Project_management(infc, outfc, outCS)
#Check messages
print(arcpy.GetMessages())
except arcpy.ExecuteError:
print(arcpy.GetMessages(2))
except Exception as ex:
print(ex.args[0])
ERROR 999999: Error executing function.
The error seems to be at the call to SpatialReference() since I don't get the error when I insert the break above that line. I have tried removing the underscores in the coordinate system name and still get the error. How can I fix this?
2 Answers 2
According to at least one reference, the spatial reference name has "Auxiliary Sphere" in parentheses.
This line worked without error:
testcs = arcpy.SpatialReference("WGS 1984 Web Mercator (Auxiliary Sphere)")
You could also use the EPSG code instead e.g. outCS = arcpy.SpatialReference(3857)
-
I changed the SpatialReference parameter to 3857: #Set output coord sys outCS = arcpy.SpatialReference(3857) and got: ERROR 000208: Error creating output feature class Failed to execute (Project). Looking up the error, arcpy is complaining about the name: "The name that has been specified is likely invalid. Correct the name and try again..." resources.arcgis.com/en/help/main/10.2/index.html#//… Seems strange because the field names in the infc should be valid. I'll try the ValidateFieldName method..Regulus– Regulus2019年05月15日 16:11:45 +00:00Commented May 15, 2019 at 16:11
-
Double-check the outfc to ensure it is not accidentally passing the old path.SMiller– SMiller2019年05月15日 16:17:42 +00:00Commented May 15, 2019 at 16:17
-
... outCS = arcpy.SpatialReference(3857) ... print ('outfc printed after call to SpatialReference' + outfc) returns this: outfc printed after call to SpatialReference G:\W135thStCopy\data_WebMerc.gdb\Street_Light_Pedestrial ERROR 000208: Error creating output feature class Failed to execute (Project). So it starts at the 5th-to-last feature class. There are 24 feature classes in the gdb. It does not print after ... arcpy.Project_management(infc, outfc, outCS) so that's where the error occurs.Regulus– Regulus2019年05月15日 16:35:22 +00:00Commented May 15, 2019 at 16:35
-
What is the name of the FC at which it fails?SMiller– SMiller2019年05月15日 16:45:44 +00:00Commented May 15, 2019 at 16:45
-
Street_Light_Pedestrial. It is the 19th FC in the GDB and its name is the only one that is printed by the diagnostic print.Regulus– Regulus2019年05月15日 16:51:37 +00:00Commented May 15, 2019 at 16:51
You'de better use EPSG codes in this context to be less prone to errors.
Try with outCS = arcpy.SpatialReference(3857)
and you should be good to go.
Explore related questions
See similar questions with these tags.
outCS = arcpy.SpatialReference(3857)
). Does it give you the same error?testcs = arcpy.SpatialReference("WGS 1984 Web Mercator (Auxiliary Sphere)")
.arcpy.SpatialReference
help page. To my understanding you should use something like "WGS_1984_Web_Mercator_Auxiliary_Sphere".