AnsweredAssumed Answered

Conditional Statement with ArcPy.GetParameters as Text, Need to Update Latitude and Longitude Based on User Pref

Question asked by hwigell_extenetsystems on Jan 18, 2017
Latest reply on Jan 20, 2017 by rvburton

#python #ArcPy #for syntaxerror

 

I am updating this tool that calculates the latitude and longitude values for all node poles. Originally the user could select Original Latitude and Longitude or Adjusted Latitude and Longitude.  The selection was for one or the other.  The update allows the user to select both.  It utilizes #arcpy.GetParametersAsText .  I created a new variable for the selection of Both, Original and Adjusted.  In doing this, I created a syntax error in my conditional statement ( line 49), and I cannot figure out how to fix it.  Any help on the error (or completing the tool, I imagine I have a few more errors left) would be much appreciated.

 

#########################################################################################################################
# Name: Calculate Node - Locations
# Author: Heather Wigell
# Description: This tool calculates the latitude and longitude values for all node poles
##################################################################
#########################
# Import system modules
#########################
import arcpy


#########################
# Set universal variables
#########################
nodeFeatures = r'OSP Mapping Layers\Node Locations'
inTable = nodeFeatures
orig_adj = arcpy.GetParameterAsText(0)
mxd = map.MapDocument("CURRENT")
################
#parameters
arcpy.GetParameterAsText(0) = "Original or Adjusted Lat Long"
orig_adj = arcpy.GetParameterAsText(0)
name = 'orig_adj'
displayName = "Original or Adjusted Lat Long"
datatype = 'String'
direction = 'Input'
filters[0].list = ['Original', 'Adjusted', 'Both']
filters[1].type = 'ValueList'

######################
#local variables
latField = "OriginalLatitude"
longField = "OriginalLongitude"
adlatField = "AdjustedLatitude"
adlongField = "AdjustedLongitude"
btlatField = "OriginalLatitude" + "AdjustedLatitude"
btlongField = "OriginalLongitude" + "AdjustedLongitude"
mxd = map.MapDocument("CURRENT")
###########
#add message about coordinate options

arcpy.AddMessage("Are you updating the Original or Adjusted coordinates?")


#############
#Print Parameter Value (User Input {Original, Adjusted, Both}) on Line 49.

arcpy.GetParameterAsText(0)

arcpy.SetParameterAsText(0,x)

x


###############
#pick original, adjusted, or both and match it to ValueList
def(x)
if:
                x == "Original" = 'true'
    and x == "Original" = 'true'
            latField = "OriginalLatitude"
            longField = "OriginalLongitude";

elif x == "Adjusted" = 'true'
    and x = "Adjusted" = 'true'
               adlatField = "AdjustedLatitude"
               adlongField = "AdjustedLongitude";

    else: x == "Both" = 'true'
            btlatField == "BothLatitude"
              btlongField = "BothLongitude"


#########################
# Calulate latitude
#########################

# Start message
arcpy.AddMessage("Calculating the latitude values for all node features...")


# Set local variables
expression = "!Shape.Centroid.Y!"


# Execute CalculateField
arcpy.CalculateField_management(inTable, latField, adlatField, btlatField, expression, "PYTHON_9.3", "")


# End message
arcpy.AddMessage("The latitude values have been calculated for all node features!")
arcpy.AddMessage("...")
arcpy.AddMessage("...")


#########################
# Calculate Longitude
#########################
# Start message
arcpy.AddMessage("Calculating the longitude values for all node features...")

# Set local variables
expression = "!Shape.Centroid.X!"


# Execute CalculateField
arcpy.CalculateField_management(inTable, longField, adlongField, btlongField, expression, "PYTHON_9.3", "")


# End message
arcpy.AddMessage("The longitude values have been calculated for all node features!")
arcpy.AddMessage("...")


arcpy.AddMessage("...")

################################################################################ Name: Calculate Node - Locations# Author: Heather Wigell# Description: This tool calculates the latitude and longitude values for all node poles############################################################################################ Import system modules#########################import arcpy########################## Set universal variables#########################nodeFeatures = r'OSP Mapping Layers\Node Locations'inTable = nodeFeaturesorig_adj = arcpy.GetParameterAsText(0)mxd = map.MapDocument("CURRENT")#################parametersarcpy.GetParameterAsText(0) = "Original or Adjusted Lat Long"orig_adj = arcpy.GetParameterAsText(0)name = 'orig_adj',displayName = "Original or Adjusted Lat Long",datatype = 'String',direction = 'Input',filters[0].list = ['Original', 'Adjusted', 'Both']filters[1].type = 'ValueList'#######################local variableslatField = "OriginalLatitude"longField = "OriginalLongitude"adlatField = "AdjustedLatitude"adlongField = "AdjustedLongitude"btlatField = "OriginalLatitude" + "AdjustedLatitude"btlongField = "OriginalLongitude" + "AdjustedLongitude"mxd = map.MapDocument("CURRENT")############add message about coordinate optionsarcpy.AddMessage("Are you updating the Original or Adjusted coordinates?")##############pick original, adjusted, or both and match it to ValueListarcpy.GetParameterAsText(0)    for "Original or Adjusted Lat Long"arcpy.SetParameterAsText(0)    for "Original or Adjusted Lat Long"if ValueList:                "Original"    and "Original or Adjusted Lat Long":                  "Original"       latField = "OriginalLatitude"    longField = "OriginalLongitude";elif ValueList = "Adjusted":    and adj = "Adjusted"               adlatField = "AdjustedLatitude"               adlongField = "AdjustedLongitude"    else: ValueList = "Both"            btlatField == "BothLatitude"              btlongField = "BothLongitude"########################## Calulate latitude########################## Start messagearcpy.AddMessage("Calculating the latitude values for all node features...")# Set local variablesexpression = "!Shape.Centroid.Y!"# Execute CalculateFieldarcpy.CalculateField_management(inTable, latField, adlatField, btlatField, expression, "PYTHON_9.3", "")# End messagearcpy.AddMessage("The latitude values have been calculated for all node features!")arcpy.AddMessage("...")arcpy.AddMessage("...")########################## Calculate Longitude########################## Start messagearcpy.AddMessage("Calculating the longitude values for all node features...")# Set local variablesexpression = "!Shape.Centroid.X!"# Execute CalculateFieldarcpy.CalculateField_management(inTable, longField, adlongField, btlongField, expression, "PYTHON_9.3", "")# End messagearcpy.AddMessage("The longitude values have been calculated for all node features!")arcpy.AddMessage("...")arcpy.AddMessage("...")

Outcomes