I am writing a code to loop through all the files in a folder and reproject them, using a raster as the spatial reference. I have a suspicion that there is a different way to get the coordinate system from a raster. This is my code so far:
#Import system modules
import arcpy
import os
#Set environment
arcpy.env.workspace = "D:/Project/Joined"
arcpy.env.overwriteOutput = True
#Get list of files in Joined folder
fileList = arcpy.ListFeatureClasses()
print fileList
#Set raster as basis for coordinate system
base = "D:/Project/Data/Development.tif"
base2 = arcpy.Describe(base)
out_coor_system = arcpy.SpatialReference(base2)
#Loop through shapefiles in fileList and reproject
for fc in fileList:
outName = fc + '_rprj.shp'
new = arcpy.Project_management(fc, outName, out_coor_system)
This is the error I am receiving:
File "D:/Project/Data/Reproject.py", line 16, in <module>
out_coor_system = arcpy.SpatialReference(base2)
File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\arcobjects\mixins.py", line 949, in __init__
self._arc_object.createFromFile(item)
RuntimeError: ERROR 999999: Error executing function.
From what I've read, this is a pretty generic error for Python IDLE to throw.
I made the code print out out_coor_system
and I am getting: <geoprocessing spatial reference object object at 0x0D2CE830>
printed out to me. Could this be the problem?
I also wanted to add that the projection I am trying to use is a custom one that my organization uses. I don't know if that's relevant (it seems it shouldn't be) but I wanted to throw that in.
<geoprocessing spatial reference object object at 0x0D2CE830>
is just because ESRI failed to define a goodrepr
(the function on Python objects that is called to get a string when the object is fed intoprint
). All it means that there is a non-None
object there; it could have any data. You would have to examine the attributes of that object to learn more about its contents.