Skip to main content
edited tags
Link
Fezter
  • 22k
  • 11
  • 71
  • 126
edited tags
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345
corrected code.
Source Link
Fezter
  • 22k
  • 11
  • 71
  • 126

I have a python script in ArcGIS 10.1 which takes in a few inputs from the user. One of the inputs is a coordinate system. I would like to test whether the coordinate system the user chose was projected or geographic.

A sample of the code is:

input1 = arcpy.GetParameterAsText(0)
input2 = arcpy.GetParameterAsText(1)
coordsys = arcpy.GetParameterAsText(2)

desc1 = arcpy.Describe(input1)
desc2 = arcpy.Describe(input2)
descCoordSys = arcpy.Describe(coordsys)

The code runs fine until the last line.

I have forced the user to enter a coordinate system in the third line: enter image description here

What am I missing here?


EDIT:

I've tried to implement the changes proposed by @dmahr but it still doesn't work. It isn't getting to the nested try statement. It just quits with the error "There was an error with an input file. Please run again." I'm not sure what I'm doing wrong. I've tried with both projected and geographic coordinate systems.

input1 = arcpy.GetParameterAsText(0)
input2 = arcpy.GetParameterAsText(1)
coordsys = arcpy.GetParameter(2)

try:
    desc1 = arcpy.Describe(input1)
    desc2 = arcpy.Describe(input2)

    try:
        coordsys_linearunit = coordsys.linearUnitName
    except:
        arcpy.addErrorAddError("Input coordinate system is not projected.")
        sys.exit("Exiting.")

except:
    arcpy.AddError("There was an error with an input file.  Please run again.")
    sys.exit("Exiting.")

I have a python script in ArcGIS 10.1 which takes in a few inputs from the user. One of the inputs is a coordinate system. I would like to test whether the coordinate system the user chose was projected or geographic.

A sample of the code is:

input1 = arcpy.GetParameterAsText(0)
input2 = arcpy.GetParameterAsText(1)
coordsys = arcpy.GetParameterAsText(2)

desc1 = arcpy.Describe(input1)
desc2 = arcpy.Describe(input2)
descCoordSys = arcpy.Describe(coordsys)

The code runs fine until the last line.

I have forced the user to enter a coordinate system in the third line: enter image description here

What am I missing here?


EDIT:

I've tried to implement the changes proposed by @dmahr but it still doesn't work. It isn't getting to the nested try statement. It just quits with the error "There was an error with an input file. Please run again." I'm not sure what I'm doing wrong. I've tried with both projected and geographic coordinate systems.

input1 = arcpy.GetParameterAsText(0)
input2 = arcpy.GetParameterAsText(1)
coordsys = arcpy.GetParameter(2)

try:
    desc1 = arcpy.Describe(input1)
    desc2 = arcpy.Describe(input2)

    try:
        coordsys_linearunit = coordsys.linearUnitName
    except:
        arcpy.addError("Input coordinate system is not projected.")
        sys.exit("Exiting.")

except:
    arcpy.AddError("There was an error with an input file.  Please run again.")
    sys.exit("Exiting.")

I have a python script in ArcGIS 10.1 which takes in a few inputs from the user. One of the inputs is a coordinate system. I would like to test whether the coordinate system the user chose was projected or geographic.

A sample of the code is:

input1 = arcpy.GetParameterAsText(0)
input2 = arcpy.GetParameterAsText(1)
coordsys = arcpy.GetParameterAsText(2)

desc1 = arcpy.Describe(input1)
desc2 = arcpy.Describe(input2)
descCoordSys = arcpy.Describe(coordsys)

The code runs fine until the last line.

I have forced the user to enter a coordinate system in the third line: enter image description here

What am I missing here?


EDIT:

I've tried to implement the changes proposed by @dmahr but it still doesn't work. It isn't getting to the nested try statement. It just quits with the error "There was an error with an input file. Please run again." I'm not sure what I'm doing wrong. I've tried with both projected and geographic coordinate systems.

input1 = arcpy.GetParameterAsText(0)
input2 = arcpy.GetParameterAsText(1)
coordsys = arcpy.GetParameter(2)

try:
    desc1 = arcpy.Describe(input1)
    desc2 = arcpy.Describe(input2)

    try:
        coordsys_linearunit = coordsys.linearUnitName
    except:
        arcpy.AddError("Input coordinate system is not projected.")
        sys.exit("Exiting.")

except:
    arcpy.AddError("There was an error with an input file.  Please run again.")
    sys.exit("Exiting.")
added horizontal rule.
Source Link
Fezter
  • 22k
  • 11
  • 71
  • 126
Loading
edited code
Source Link
Fezter
  • 22k
  • 11
  • 71
  • 126
Loading
added revised code and issues after dmahr's suggestion
Source Link
Fezter
  • 22k
  • 11
  • 71
  • 126
Loading
Source Link
Fezter
  • 22k
  • 11
  • 71
  • 126
Loading