Reprojecting a GDB in arcpy

by Regulus   Last Updated May 15, 2019 16:22 PM

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:/Verizon_OneFiber/Data/Internal/utility georefs/MuniProvidedShapefiles/Plainfield/W135thStCopy\data.gdb"
... arcpy.env.overwriteOutput = True
... outWorkspace = "G:/Verizon_OneFiber/Data/Internal/utility georefs/MuniProvidedShapefiles/Plainfield/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?



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)

smiller
smiller
May 15, 2019 15:44 PM

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.

umbe1987
umbe1987
May 15, 2019 15:48 PM

Related Questions


Updated June 14, 2018 14:22 PM

Updated April 09, 2015 19:09 PM

Updated November 07, 2017 04:22 AM

Updated April 04, 2016 08:09 AM

Updated March 29, 2017 23:22 PM