0

I have to assign shapes without a spatial reference a coordinate system. Therefore I build a model which goes through different folders. But I need this Python script for if then else: if the shape has no spatial reference it should get one, else should be done nothing.

I nearly can take the script of the ESRI support http://desktop.arcgis.com/en/arcmap/10.3/analyze/modelbuilder/using-if-then-else-logic-for-branching.htm

but there is this error: "AttributeError: DescribeData: Method spatialReference does not exist"

I use ArcMap 10.2.2 and Python 2.7.5 shell. Here is my script:

# Import modules
import arcpy
import sys
import traceback


# Set local variables
prj = "" 
indata = "Y:/Koordinatenumstellung_Test/mit_und_Ohne_Koo" 
dsc = arcpy.Describe(indata) 
sr = dsc.spatialReference 
prj = sr.name.lower()

try:

   # check if indata is in StatePlane, has no PRJ, or one other than StatePlane
   if prj.find("_unknown_") > -1:
       # Set the Is Unknown parameter to FALSE, and the Is StatePlane parameter to TRUE
       arcpy.SetParameterAsText(1,"true") #The first parameter refers to the "Is Unknown" variable

       arcpy.AddMessage("Coordinate system unknown") 


   else:
       # Set the Is Unknown parameter to FALSE, and the Is StatePlane parameter to FALSE
       arcpy.SetParameterAsText(1,"false") 

       arcpy.AddMessage("Coordinate system is known") 

except Exception as e:
    AddPrintMessage(e[0], 2)
4
  • Possible duplicate of this
    – reevesii
    Nov 16, 2018 at 11:16
  • Thank you @reevesii I already saw this post, but it didn´t help me at all.
    – Karamell
    Nov 16, 2018 at 12:29
  • 1
    It is a violation of best practice to place so much code inside a try block, especially during code development, and this portion of the code is unnecessary for the question, since the error is caused on what should be the fifth line of code. All you need to do is test whether the describe object supports spatialReference. Part of the problem may be the ancient releases of ArcGIS and Python (10.2 will be retired in six weeks)
    – Vince
    Nov 16, 2018 at 12:52
  • Thank you, vince. So I tried the code at the end of this. But it didn´t work. This ist, what I get: "IOError: "D:\050307_bohransatz_GK" does not exist" I have to give up for today.
    – Karamell
    Nov 16, 2018 at 14:15

1 Answer 1

1

If your input is a shapefile you will want to append .shp to the end of your indata variable:

indata = "Y:/Koordinatenumstellung_Test/mit_und_Ohne_Koo.shp"

Also, you will want to replace "__unknown_" with "unknown" within your IF statement.

1
  • Yes, that´s it. Now, I have the next Problem to get the data of different shapes in a folder respectevely subfolders.
    – Karamell
    Nov 19, 2018 at 9:16

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.