|
POST
|
Hi Joe, I thought I was renaming in the last line of my script. Line # 15. I guess I am really lost with this one...
... View more
04-30-2020
12:29 PM
|
0
|
4
|
3283
|
|
POST
|
Hello! I recently posted a question about python dictionaries and here I am again struggling with them.. I am now trying to use them to change feature class names. Problem: I have a list of 77 feature classes and I need to change their names from codes to names using a python dictionary. For example: Feature class name: T14_single_points New name that I need: Alachua I am not getting any errors when running this code but I am not getting any results either. import arcpy
# script to change fc name using a dictionary
arcpy.env.workspace = r"D:\APRX_MXDS\USA_Parcels_2019_Project\test.gdb"
arcpy.env.overwriteOutput = True
fc_list = arcpy.ListFeatureClasses("points*") # list of fc that end with points
# dictionary
county_codes = {14 : "Bradford", 15 : "Brevard", 16 : "Broward"}
for fc in fc_list: # loop through the feature classes
key = "{[1:3]}".format(fc.name) # let the second and third characters in the fc name be the key
if key in county_codes:
fc = county_codes.get(key) # assign the value in the dictionary as the new feature class name thank you!
... View more
04-30-2020
08:48 AM
|
0
|
11
|
4147
|
|
POST
|
that's a great idea! I've been saving every python script in the same folder but there are so many by now that it is getting very hard to find what I've done in the past. I'll make sure to create a "Python Development" folder as well.
... View more
04-23-2020
03:49 PM
|
0
|
0
|
690
|
|
POST
|
Thank you Joe for your response. I was able to run the code and it worked! I now understand how dictionaries work in ArcGIS. This was extremely helpful.
... View more
04-23-2020
03:02 PM
|
0
|
2
|
7110
|
|
POST
|
I even include the image containing the field/column name in the attribute table of my feature class.
... View more
04-23-2020
11:50 AM
|
0
|
0
|
7110
|
|
POST
|
I understand that is the error but the column name is correct and it exists in my feature class. I even include a line of code in my script that prints all of the field names. When I run the line of code it prints out the field names that supposedly don't exist.
... View more
04-23-2020
11:49 AM
|
0
|
1
|
7110
|
|
POST
|
Can You explain a little bit further what you mean by baseName? Also, should I write if row[1] in useskey:
... View more
04-23-2020
10:30 AM
|
0
|
1
|
7110
|
|
POST
|
Hello, I am trying to use python dictionaries to change the feature values of different fields. I created the script below to change the feature values of a field called "DOR_UC" and as you can see there is a list of other fields where I need to do something similar - that's why there is a long list of other fields. import arcpy
# script to assign values to features in one field based on a value in the dictionary
arcpy.env.workspace = r"D:\APRX_MXDS\USA_Parcels_2019_Project\test_featureclasses.gdb"
arcpy.env.overwriteOutput = True
# feature class
fc = "testing_fc"
# printing all fields in fc
fields = [f.name for f in arcpy.ListFields(fc)]
print(fields)
# dictionary
uses = {"000" : "Vacant Residential – with/without extra features", "001" : "Single Family", "002": "Mobile Homes",
"003" : "Multi-family - 10 units or more",
"004" : "Condominiums",
"005" : "Cooperatives",
"006" : "Retirement Homes not eligible for exemption",
"007" : "Miscellaneous Residential (migrant camps, boarding homes, etc.)",
"008" : "Multi-family - fewer than 10 units",
"009" : "Residential Common Elements/Areas",
"010" : "Vacant Commercial - with/without extra features",
"011" : "Stores, one story",
"012" : "Mixed use - store and office or store and residential combination",
}
# dictionary keys to list
usesKey = list(uses.keys())
# dictionary values to list
usesvalues = list(uses.values())
# List of fields
fields = ["BAS_STRT", "DOR_UC", "TEST", "PAR_SPLT", "CONST_CLASS", "IMP_QUAL", "M_PAR_SAL1", "QUAL_CD1"]
with arcpy.da.UpdateCursor(fc, fields) as cursor:
for row in cursor:
if usesKey in row[1]:
row[2] = usesvalues
cursor.updateRow() Field DOR_UC currently has some codes that I need to convert into a sentence. See image below for fc attribute's table: Each of those codes has a meaning in the form of a sentence. I need to assign their meaning and delete the codes. To do this I've created a dictionary where the key is the code and the value is the sentence (See attached csv). To start testing the script I created a field called "TEST" where I want to put the value part of the dictionary. So the code would go something like this: If a feature in field DOR_UC is equal to 000 then the feature value in field TEST would be "Vacant Residential - with/without extra features". When I try to run the code I am getting this first error: Traceback (most recent call last):
File "D:/APRX_MXDS/USA_Parcels_2019_Project/Scripts/Dictionary Key() method_2.py", line 44, in <module>
for row in cursor:
RuntimeError: A column was specified that does not exist. The weird thing is that I have both of the columns. Not sure how to solve this. Also, not sure if the overall code has more errors. Could someone help me with this? I need to finish this today and I have no idea on how to continue. thank you!
... View more
04-23-2020
09:52 AM
|
0
|
10
|
7900
|
|
POST
|
Thank you Joe! The problem was with the data type of my field. I did not know that I had to set it as GUID. Once I changed it my code ran without errors.
... View more
04-06-2020
10:25 AM
|
0
|
2
|
2310
|
|
POST
|
Hello! I need to add unique ID's to a specific field in multiple feature classes that are inside a geodatabase. I have created the code below but it is not working. When I run, it I get the following error message: Traceback (most recent call last): File "D:/APRX_MXDS/USA_Parcels_2019_Project/Scripts/UniqueID_2.py", line 15, in <module> for row in cursor: RuntimeError: A column was specified that does not exist. Process finished with exit code 1 The error is referring to a column that does not exist. Is column the same as field? The field "UNIQUE_ID_PYTHON" was created before running the code, and so it should run. import arcpy
import uuid
# Script to add unique Id's
featureGDB = r"D:\APRX_MXDS\USA_Parcels_2019_Project\test_featureclasses.gdb"
arcpy.env.workspace = featureGDB
arcpy.env.overwriteOutput = True
List_fc = arcpy.ListFeatureClasses("*single") # get a list of feature classes that end with the word single.
List = ["UNIQUE_ID_PYTHON"] # Field where I want to add the unique ids
for fc in List_fc: # loop through each feature class in the list and add unique ID to the specified field.
with arcpy.da.UpdateCursor(fc, List) as cursor:
for row in cursor:
row[0] = '{' + str(uuid.uuid4()) + '}'
cursor.updateRow(row) Not sure how to fix this. Can somebody guide me ? Thank you
... View more
04-06-2020
07:47 AM
|
0
|
5
|
2369
|
|
POST
|
Thank you again! Will keep on learning and using the online tools
... View more
03-31-2020
04:38 PM
|
0
|
0
|
1060
|
|
POST
|
Joe, the code worked!! I am so happy! thank you so much! I was really stuck and needed to do this automatically. I used to do all of this manually for such a long time and I am learning to automate this with your help and with as many videos I can find online. Actually, do you know of a good course that would teach me python applied to arcgis ? All I find are separate videos each one teaching different things. I would love to find something that goes from the very beginning until more advanced processes. Anyways.. thank you again!
... View more
03-31-2020
02:50 PM
|
0
|
0
|
1060
|
|
POST
|
Great thanks!! I will run the code in a little bit. Will let you know how that goes
... View more
03-31-2020
02:28 PM
|
0
|
1
|
4255
|
|
POST
|
Perfect Joe, I understand and I will try it as you suggest with the print statements to better see what I am doing. Before I do that I have one last question though .. in line 17 we are using slicing right: tableNum = table [3:7]
would 3 to 7 give us: 11F2 ? wouldn't it be [3:5] ? Sorry if I am being stubborn, I really want to understand it.
... View more
03-31-2020
02:18 PM
|
0
|
1
|
4255
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 11-15-2018 02:42 PM | |
| 2 | 03-06-2020 09:18 AM | |
| 2 | 11-15-2018 03:02 PM |
| Online Status |
Offline
|
| Date Last Visited |
12-14-2020
03:44 PM
|