POST
|
Thank you, Randy. 57-71 is what I was referring to in my question with syntax. Do you have any specific advice on this section? Or anyone else?
... View more
01-20-2017
08:18 AM
|
0
|
1
|
977
|
POST
|
Joshua, Thank you for your comments. Here is the zip file. The original project file has CP at the end. You will see, I changed directions a few times. Zip file Regards, Heather
... View more
01-19-2017
03:01 PM
|
0
|
1
|
977
|
POST
|
Originally, the error was on error Line 54. I added to the code and now I am getting an error on 53 also. They are both generating the same errors.
... View more
01-18-2017
12:21 PM
|
0
|
1
|
977
|
POST
|
#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("...")
... View more
01-18-2017
10:17 AM
|
0
|
8
|
2036
|
POST
|
Currently, I am attempting to write a script in #python 2.7.11 using arcpy.da.update.cursor Essentially, I have an original script that works, which I need to rewrite and shorten. The original script is posted below. The script is for a tool in ArcGIS used to calculate a desired number of Circuit ID's for the appropriate carrier. Based on the input, the IDs are written back on to a table. Any help with the rewrite would be much appreciated. The question with this script is, should there be additional parameters in the line <cursor.da.updateRow(row)>. The major issue, populating data back, seems to be with the with arcpy.da.cursor.update. Additional info: I wrote both of the scripts utilizing itertools (iterate), thinking I could replicate the pattern of the table quickly. The rest of the code, other than the update of the CircuitIDs, is identical. : 1) Attempt. Updated from last post. Uses itertools combination_with_replacement. itertools python doc for more info. with arcpy.da.UpdateCursor(nodeFeatures, fields) as cursor: for row in cursor: def combinations_with_replacement(iterable, 10): if numIDs >= "1" and if numIDs <="10" # combination_with_replacement(10,(1,'02')) --> 1,'03' 3,'05' 4,'06' 5,'07' 6,'04' 7,'05' 8,'06' 9,'07' 10,'08' pool = tuple(iterable) n = 1 r = 10 len(s)=75 range(i)==numIDs cycles=range(n, n+1) indices(i) = row[i+3] = ["(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (%02i)" %(i+1) else: return: elif numIDs =="0": row[3] = None row[4] = None row[5] = None row[6] = None row[7] = None row[8] = None row[9] = None row[10] = None row[11] = None row[12] = None else: cursor.updateRow(row): 2)The original code(My work only fills in for the section of "Update the appropriate number of Circuit ID fields"): # ################################################################################################### # Import system modules # ################################################################################################### import arcpy # ################################################################################################### # Set universal variables # ################################################################################################### nodeFeatures = r'OSP Mapping Layers\Node Locations' numIDs = arcpy.GetParameterAsText(0) fields = ['ExteNetNodeID', 'ProjectHub', 'ProjectCarrier', 'CircuitID1', 'CircuitID2', 'CircuitID3', 'CircuitID4', 'CircuitID5', 'CircuitID6', 'CircuitID7', 'CircuitID8', 'CircuitID9', 'CircuitID10'] # ######################### # Update the appropriate number of Circuit ID fields # ######################### with arcpy.da.UpdateCursor(nodeFeatures, fields) as cursor: for row in cursor: if numIDs == "1": row[3] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (01)" cursor.updateRow(row) elif numIDs == "2": row[3] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (01)" row[4] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (02)" cursor.updateRow(row) elif numIDs == "3": row[3] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (01)" row[4] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (02)" row[5] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (03)" cursor.updateRow(row) elif numIDs == "4": row[3] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (01)" row[4] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (02)" row[5] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (03)" row[6] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (04)" cursor.updateRow(row) elif numIDs == "5": row[3] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (01)" row[4] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (02)" row[5] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (03)" row[6] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (04)" row[7] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (05)" cursor.updateRow(row) elif numIDs == "6": row[3] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (01)" row[4] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (02)" row[5] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (03)" row[6] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (04)" row[7] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (05)" row[8] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (06)" cursor.updateRow(row) elif numIDs == "7": row[3] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (01)" row[4] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (02)" row[5] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (03)" row[6] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (04)" row[7] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (05)" row[8] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (06)" row[9] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (07)" cursor.updateRow(row) elif numIDs == "8": row[3] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (01)" row[4] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (02)" row[5] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (03)" row[6] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (04)" row[7] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (05)" row[8] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (06)" row[9] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (07)" row[10] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (08)" cursor.updateRow(row) elif numIDs == "9": row[3] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (01)" row[4] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (02)" row[5] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (03)" row[6] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (04)" row[7] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (05)" row[8] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (06)" row[9] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (07)" row[10] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (08)" row[11] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (09)" cursor.updateRow(row) elif numIDs == "10": row[3] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (01)" row[4] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (02)" row[5] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (03)" row[6] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (04)" row[7] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (05)" row[8] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (06)" row[9] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (07)" row[10] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (08)" row[11] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (09)" row[12] = "(" + row[0] + ") - (" + row[1] + ") - (" + row[2] + ") - (10)" cursor.updateRow(row) elif numIDs =="0": row[3] = None row[4] = None row[5] = None row[6] = None row[7] = None row[8] = None row[9] = None row[10] = None row[11] = None row[12] = None cursor.updateRow(row) else: pass Like Show 0 Likes (0) • Share Hide new activityMark unread 5 comments4 new updates Heather Wigell 1 day ago The question with this script is, should there be additional parameters in the line <cursor.updateRow(row)>. The major issue, populating data back, seems to be with the with cursor.update. Additional info: I wrote both of the scripts utilizing itertools, thinking I could replicate the pattern of the table quickly. The rest of the code, other than the update of the CircuitIDs, is identical. <a href>UpdateCursor—Help | ArcGIS for Desktop </>
... View more
11-15-2016
10:27 AM
|
0
|
2
|
1150
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|