0

I included coordinateSystem = arcpy.SpatialReference(4283) and it works when I point the workspace path to a GHB file. However I get an error below when including multiple GHB folders into the workspace z:/temp.

name 'inData' is not defined.

My code is below. Can somebody suggest a fix?

import arcpy
from arcpy import env
import os

arcpy.env.workspace = "Z:/temp"
fcs = arcpy.ListFeatureClasses('*', "ALL")

for file in fcs:
   print arcpy.env.workspace, file

try:
    for file in fcs:
      inData = file
     coordinateSystem = arcpy.SpatialReference(4283)

 # updates/overwrites coordinate system information and map projection stored with a dataset
# accepts dataset and coordinate system information
      arcpy.DefineProjection_management(inData, coordinateSystem)

except arcpy.ExecuteError:
   print arcpy.GetMessages(2)
   arcpy.AddError(arcpy.GetMessages(2))
except Exception as e:
   print e.args[0]
   arcpy.AddError(e.args[0]) 

The ghb folders and shape files are stored in their folders as per the screenshots. enter image description here enter image description here

3
  • 1
    It's GDA94 isn't it? Perhaps coordinateSystem = arcpy.SpatialReference(4283) would work better. 4283 is the EPSG/SRID code for GDA94/Geographic spatialreference.org/ref/epsg/4283 I note that your indentation is inconsistent, the try: should be indented but that may be in your copy/paste. Is it possible there's a broken shapefile in that folder? I've seen much mischief and face-palm caused by a missing .dbf or .shx file. Commented Aug 15, 2016 at 4:33
  • Welcome to GIS SE! As a new user be sure to take the 2-minute Tour to learn about our focussed Q&A format. Something I find useful when presenting questions here and testing is to remove any try/except statements because they can mask Python errors that are often useful when trying to debug.
    – PolyGeo
    Commented Aug 15, 2016 at 11:21
  • I'm also trying to figure out why coordinateSystem's value contains two GEOGCS objects and a space. Try taking out the second GEOGCS object. Are you trying to add a vertical coordinate system too?
    – mkennedy
    Commented Aug 16, 2016 at 17:29

1 Answer 1

1

You need to make your coordinate system variable into a spatial reference object. Do this with arcpy.SpatialReference(EPSG Num or Name) - 4283 for GDA94.

If you need a custom spatial reference, create it in ArcMap and save as a .prj file. You can then point to the prj file like this:

arcpy.SpatialReference("C:/Data/SpatialRef/Custom_GDA94.prj")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.