I'm trying to build a set that consists of spatial reference names using .name method from the arcpy.SpatialRefernce() class. When I do this for a single prj file there is no issue, but when I try to do it for a set of prjs as a loop it returns a 999999 error:

import arcpy

#overwrite existing output from previuous trials
arcpy.env.overwriteOutput = True

#create output file location through arcpy.env.workspace
arcpy.env.workspace = r"C:\RS_Data\Python\Geog485\Lesson2"

#designate shapefile that has the desired projection
outPRJ = r"C:\RS_Data\Python\Geog485\Lesson2\StateRoutes.shp"

#call on the prj file to get the spatial reference object and name
targetPrj = outPRJ[:-3]+"prj"
SpRef = arcpy.SpatialReference(targetPrj)
SpRefName = SpRef.name
print SpRef.name

#create list of fc prjs and remove .shp file names from previous trials
x = "_projected.shp"
inFiles = arcpy.ListFeatureClasses()
for file in inFiles:
    if x in file:

inPuts = set()
for file in inFiles:
    file = file[:-3]+"prj"
    print file

for prj in inFiles:
    sr = arcpy.SpatialReference(prj)
    if sr.name != SpRef:

here is the error:

Traceback (most recent call last):
  File "C:\Python27\ArcGIS10.2\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 323, in RunScript
    debugger.run(codeObject, __main__.__dict__, start_stepping=0)
  File "C:\Python27\ArcGIS10.2\Lib\site-packages\pythonwin\pywin\debugger\__init__.py", line 60, in run
    _GetCurrentDebugger().run(cmd, globals,locals, start_stepping)
  File "C:\Python27\ArcGIS10.2\Lib\site-packages\pythonwin\pywin\debugger\debugger.py", line 654, in run
    exec cmd in globals, locals
  File "N:\Python\Reproject.py", line 1, in <module>
    import arcpy
  File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\arcobjects\mixins.py", line 927, in __init__
RuntimeError: ERROR 999999: Error executing function.
  • 2
    inFiles.remove(file) looks suspect ... stackoverflow.com/questions/1207406/… – Kirk Kuykendall Apr 18 '16 at 21:59
  • Why are you not calling the .shp directly? e.g. sr = arcpy.Describe(shp).spatialReference.name – Aaron Apr 18 '16 at 22:14
  • I was under the impression I had to use a prj file – geoJshaun Apr 18 '16 at 22:17
  • And inFiles.remove(file) is not causing the issue – geoJshaun Apr 18 '16 at 22:17
  • That did it. I had to change a few other things but that was the main hang up. Thanks! – geoJshaun Apr 18 '16 at 22:29

I would take a different approach and describe the spatial reference by directly calling the shapefile. For example:

import arcpy

arcpy.env.workspace = r'C:\your\workspace'
shps = arcpy.ListFeatureClasses()

for shp in shps:
    print arcpy.Describe(shp).spatialReference.name
  • I did major refactoring but here is the bit of code that fixed my last problem: sr = arcpy.Describe(file).spatialReference.name – geoJshaun Apr 19 '16 at 20:28

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.