POST
|
I want to use the NAME field's values to be the value in the dictionary and a numeric value starting at 0 as the key if that is possible? I am unfortunately still using ArcGIS for Desktop and thus do not have access to python 3.6.
... View more
03-29-2018
06:14 AM
|
0
|
11
|
5086
|
POST
|
So I am currently working on a tool that the user needs to apply a query in order to the run the tool for the queried data. I am trying to get around that by creating a blank dictionary in the script and then appending data to it. The data comes from a field in a feature class. I have never done this before but in theory it should work the same as appending to lists correct? hubFeatures = r'hub_locations'
hubDict = {} These are my working variables for this. The field that I want the data from to append to the dictionary is called 'NAME' in the hubFeatures FC. I was thinking of using cursors to achieve this. Unless there is an alternative approach. The idea is to then use the items in the dictionary to apply a query to the necessary layers and complete the functionality of the tool using a for loop. That part I can do. Need some assistance in setting up the dictionary.
... View more
03-27-2018
01:36 PM
|
0
|
15
|
6723
|
POST
|
My first thought to solve this is have the first parameter as text set with an index of 0. input_FC = arcpy.GetParameterAsText(0)
inField = arcpy.GetParameterAsText(1)
theFName = arcpy.GetParameterAsText(2)
outFolder = arcpy.GetParameterAsText(3)
output = arcpy.SetParameterAsText(4, outFolder)
script = sys.argv[0] See if that solves it.
... View more
03-22-2018
09:49 AM
|
2
|
0
|
1448
|
POST
|
Wow, that was such a simple fix... I thought it would be much more complex than that. Thank you so much James!
... View more
03-19-2018
01:36 PM
|
0
|
0
|
1253
|
POST
|
Hello, So I am first running a summary statistics to get the information I need and then the next step of the tool is to modify the table fields so I can get the field alias I want. This is done by creating new fields, doing calculations, etc. Here is my code: import arcpy
import os
import arcpy.mapping as map
from arcpy import env
import datetime
arcpy.env.overwriteOutput = True
fiberFeatures = r'sdm_Fiber Segments'
date = datetime.date.today()
reportsGDB = r'C:\Users\vshah\Desktop\Test Folder\test_output.gdb'
reportsFolder = r'C:\Users\vshah\Desktop\Test Folder'
inLayer = fiberFeatures
outputName = 'fiber_summary'
outLayer = reportsGDB + "/" + outputName
statsFields = [["Feet", "SUM"], ["Miles", "SUM"]]
caseFields = ["NetworkID", "ProjectID"]
arcpy.Statistics_analysis(inLayer, outLayer, statsFields, caseFields)
in_table = reportsGDB +"\\" + 'fiber_summary'
deleteField = "FREQUENCY"
fieldList = arcpy.ListFields(in_table)
length = len(fieldList) - 2 ##subtracting 2 to account for the field being deleted when the modification is executed and to not count the Object ID field.
arcpy.DeleteField_management(in_table, deleteField)
alias_dict = {1: 'Network ID', 2: 'Project ID', 3: 'Total Feet', 4: 'Total Miles'}
for i, field in enumerate(fieldList):
if field.type != 'OID' and i <= length:
newfield = '{}new'.format(field.name)
arcpy.AddField_management(in_table, newfield, field.type, field.precision,
field.scale, field.length, alias_dict[i], field.isNullable, field.required, field.domain)
arcpy.CalculateField_management(in_table, newfield, '!{}!'.format(field.name), "PYTHON_9.3")
arcpy.DeleteField_management(in_table, field.name) After this will be a simple export to excel sheet. However when I get to this portion of the script, I get ERROR 000539: Invalid field FREQUENCY even though it is being deleted before it gets to creating new fields. Any thoughts on how to solve this or any help you can offer?
... View more
03-19-2018
01:23 PM
|
0
|
2
|
2119
|
POST
|
Thank you for the help! It was greatly appreciated!
... View more
03-14-2018
10:29 AM
|
0
|
0
|
3684
|
POST
|
That did the trick Joshua. Changing it from arcpy.UpdateCursor to arcpy.da.UpdateCursor.
... View more
03-14-2018
10:17 AM
|
0
|
0
|
3684
|
POST
|
cursor = arcpy.UpdateCursor(fiberFeatures, fields)
for row in cursor:
if not (None in row[:-1]):
row[2] = row[0] * row[1]
cursor.updateRow(row) Tried this and got TypeError: 'Row' object has no attribute '__getitem__'
... View more
03-14-2018
09:42 AM
|
0
|
0
|
436
|
POST
|
I found this article by Charles Nagy Python error: AttributeError: __exit__ | Charles Nagy but my code has a few difference and I do not know how to re engineer my code to go along the lines of what Charles has to eliminate the error. Any help on this?
... View more
03-14-2018
09:17 AM
|
0
|
0
|
436
|
POST
|
Dan, I just tried it with the code you had listed but within the with statement: with arcpy.UpdateCursor(fiberFeatures, fields) as cursor:
if not(None in row[:-1]):
row[2] = row[0] * row[1]
cursor.updateRow(row) This still gives me the AttributeError: __Exit__
... View more
03-14-2018
08:59 AM
|
0
|
2
|
3684
|
POST
|
I am open to anything Dan as long as it does what I need it to do. The path I am taking is to sort through the strandsField to first see if there are any NULL values, if there are any, return a message saying Insufficient Data. If there are no NULL values, then multiple the strandsField with the milesField. But I want the first conditional to run to inform users if there is insufficient data. Hopefully that makes sense!
... View more
03-14-2018
08:42 AM
|
0
|
0
|
3684
|
POST
|
Apologies Rebecca, my code actually has the quote at the end. I forgot to type that in. But that doesn't seem to cause the error. Any other ideas?
... View more
03-14-2018
08:40 AM
|
0
|
2
|
3684
|
POST
|
Hello, So I am new to working with cursors and need a little help with my code as I am getting an AttributeError: __exit__ when i run my script. Here's what my code looks like: inTable = r'Layer\Fiber'
routeMilesField = "RouteMiles"
strandsField = "cableSize"
milesField = "FiberMiles"
fields = [strandsField, milesField, routeMilesField]
with arcpy.UpdateCursor(fiberFeatures, fields) as cursor:
for row in cursor:
if None in row[:-1]:
arcpy.AddMessage("Insufficient Strand Data!")
break
else:
row[2] = row[0] * row[1]
cursor.updateRow(row) Any help is greatly appreciated! Edit: Revised script based on this article: cursor - AttributeError: __exit__ when trying to use arcpy.UpdateCursor - Geographic Information Systems Stack Exchange cursor = arcpy.UpdateCursor(fiberFeatures, fields)
for row in cursor:
if None in row[:-1]:
arcpy.AddMessage("Insufficient Strand Data")
break
else:
row[2] = row[0] * row[1]
cursor.updateRow(row) This returns a TypeError: 'Row' object has no attribute '__getitem__' error. I'm new to cursors and what not and definitely need help with this code. Edit 2: Solution based on Joshua's feedback: with arcpy.da.UpdateCursor(fiberFeatures, fields) as cursor:
for row in cursor:
if None in row[:-1]:
arcpy.AddError("Insufficient Strand Data!")
break
else:
row[2] = row[0] * row[1]
cursor.updateRow(row)
... View more
03-14-2018
07:05 AM
|
0
|
12
|
5694
|
POST
|
Never mind. I found a working solution. nodeIDField = "COUNT_ID"
fieldList = arcpy.ListFields(in_table)
length = len(fieldList) - 2
arcpy.DeleteField_management(in_table, nodeIDField)
alias_dict = {1: 'Network ID', 2: 'Project ID', 3: 'Municipality', 4: 'Node Count'}
for i, field in enumerate(fieldList):
if field.type != 'OID' and i <= length:
newfield = '{}new'.format(field.name)
arcpy.AddField_management(in_table, newfield, field.type, field.precision,
field.scale, field.length, alias_dict[i], field.isNullable, field.required, field.domain)
arcpy.CalculateField_management(in_table, newfield, '!{}!'.format(field.name), "PYTHON_9.3")
arcpy.DeleteField_management(in_table, field.name) The original length of the fieldlist was 6, hence why i got KeyError: 5. It was looking for the 5th key in the dictionary. I am subtracting 2 because I do not want to count the ObjectID field or the field I am deleting using arcpy.DeleteField_management.
... View more
03-13-2018
11:24 AM
|
0
|
0
|
2072
|
Title | Kudos | Posted |
---|---|---|
1 | 07-26-2018 09:12 AM | |
1 | 07-18-2017 01:12 PM | |
1 | 03-09-2017 09:57 AM | |
2 | 03-22-2018 09:49 AM | |
1 | 09-19-2017 01:18 PM |