|
POST
|
Adding the print statement give the following error. print (search_feats[upd_row[0]]) error KeyError: <PointGeometry object at 0x3900e790[0x3900e620]>
... View more
08-04-2022
08:58 AM
|
0
|
1
|
2966
|
|
POST
|
apologizes for the delay response, I got busy with something else. The print(search_feats), prints {u'Ros': ()} I have attached the data I am working with, if it helps. I changed the parcel data to City limits to help with the size of the up loaded file. I need to update the pointLayer = EMS points2 SiteCity field with the Parcels = CityLimits1 SiteCity field pointLayer = 'EMS_Points2'
city = 'CityLimits1'
sjpoints = "In_memory\sjpoints"
ptCount = int(arcpy.GetCount_management(pointLayer).getOutput(0))
dsc = arcpy.Describe(pointLayer)
selection_set = dsc.FIDSet
if len(selection_set) == 0:
print "There are no features selected"
elif ptCount >= 1:
#Run the Spatial Join tool, using the defaults for the join operation and join type
arcpy.SpatialJoin_analysis(pointLayer, city, sjpoints)
search_feats ={f[0]:(f[0]) for f in arcpy.da.SearchCursor(sjpoints,'SiteCity_1')}
print(search_feats)
## with arcpy.da.UpdateCursor(pointLayer,["SHAPE@","SiteCity"]) as upd_cur:
## for upd_row in upd_cur:
## try:
## if search_feats[upd_row[0]][1] == "Sea":
## upd_row[1] = "Seattle"
## elif search_feats[upd_row[0]][1] == "Spo":
## upd_row[1] = "Spokane"
## elif search_feats[upd_row[0]][1] == "Tac":
## upd_row[1] = "Tacoma"
## upd_cur.updateRow(upd_row)
## except:
## continue
place_dict = {"Sea":"Seattle", "Spo":"Spokane", "Ros":"Roslyn"}
with arcpy.da.UpdateCursor(pointLayer,["SHAPE@","SiteCity"]) as upd_cur:
for upd_row in upd_cur:
try:
upd_row[1] = place_dict.get(search_feats[upd_row[0]][1], upd_row[1])
upd_cur.updateRow(upd_row)
except:
continue
... View more
08-04-2022
08:20 AM
|
0
|
0
|
631
|
|
POST
|
i have tried the following and get this error. Runtime error SyntaxError: can't assign to operator (<string>, line 35) Not sure what that means but one thing I did find out about that field is that there is domains to that field. pointLayer = 'EMS'
parcel = 'Ass_Parcels'
ptCount = int(arcpy.GetCount_management(pointLayer).getOutput(0))
dsc = arcpy.Describe(pointLayer)
selection_set = dsc.FIDSet
if len(selection_set) == 0:
print "There are no features selected"
elif ptCount >= 1:
arcpy.SpatialJoin_analysis(pointLayer, parcel, sjpoints)
search_feats ={f[0]:(f[1:]) for f in arcpy.da.SearchCursor(sjpoints,'SiteCity_1')}
print(search_feats)
## with arcpy.da.UpdateCursor(pointLayer,["SHAPE@","SiteCity"]) as upd_cur:
## for upd_row in upd_cur:
## try:
## if search_feats[upd_row[0]][1] == "Sea":
## upd_row[1] = "Seattle"
## elif search_feats[upd_row[0]][1] == "Spo":
## upd_row[1] = "Spokane"
## elif search_feats[upd_row[0]][1] == "Tac":
## upd_row[1] = "Tacoma"
## upd_cur.updateRow(upd_row)
## except:
## continue
place_dict = {"Sea":"Seattle", "Spo":"Spokane", "Tac":"Tacoma"}
with arcpy.da.UpdateCursor(pointLayer,["SHAPE@","SiteCity"]) as upd_cur:
for upd_row in upd_cur:
try:
upd_row[1] = place_dict.get(search_feats[upd_row[0]][1], upd_row[1])
upd_cur.updateRow(upd_row)
except:
continue
... View more
07-28-2022
08:16 AM
|
0
|
3
|
3015
|
|
POST
|
I did catch that after I posted, but I still get the same thing. No errors but nothing is updated. I did look into the field a little and found that the pointLayer "SiteCity" field has domains, not sure if this has any effect or not.
... View more
07-28-2022
07:45 AM
|
0
|
1
|
3021
|
|
POST
|
I have a two layers, I need to transfer a field attribute to the other layer of the selected feature. The EMS layer has a filed "SiteCity" and so does the "Ass_Parcels" layer. I need to transfer the Ass_Parcels SiteCity attribute to the EMS's SiteCity field. I have the following but I am not able to get it to work. I don't get an error, but the EMs's SiteCity field doesn't get populated. pointLayer = 'EMS'
parcel = 'Ass_Parcels'
ptCount = int(arcpy.GetCount_management(pointLayer).getOutput(0))
dsc = arcpy.Describe(pointLayer)
selection_set = dsc.FIDSet
if len(selection_set) == 0:
print "There are no features selected"
elif ptCount >= 1:
elif ptCount >= 1:
arcpy.SpatialJoin_analysis(pointLayer, parcel, sjpoints)
search_feats ={f[0]:(f[1:]) for f in arcpy.da.SearchCursor(sjpoints,'SiteCity_1')}
print(search_feats)
with arcpy.da.UpdateCursor(pointLayer,["SHAPE@","SiteCity"]) as upd_cur:
for upd_row in upd_cur:
try:
if search_feats[upd_row[0]][1] == "Sea":
upd_row[1] == "Seattle"
elif search_feats[upd_row[0]][1] == "Spo":
upd_row[1] == "Spokane"
elif search_feats[upd_row[0]][1] == "Tac":
upd_row[1] == "Tacoma"
upd_cur.updateRow(upd_row)
except:
continue
... View more
07-27-2022
08:58 AM
|
0
|
10
|
3695
|
|
POST
|
Try remove the "r" from r"\city of westervill.mdb" and r"\westerville.gdb". Are both the mdb and gdb in the same folder "c:\esritraining\mapscripting? Include arcpy.env.workspace I have always done something like this. mxd = arcpy.mapping.MapDocument("CURRENT")#mxd = arcpy.mapping.MapDocument(mxd)
mxd.findAndReplaceWorkspacePaths(r"Database Connections\Connection to OLD_sqlexpress.sde", r"Database Connections\Connection to New_sqlexpress.sde") #Database Servers\***.gds
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.name == "CITY_LIMITS":
lyr.replaceDataSource(r"C:\Users\***\AppData\Roaming\ESRI\Desktop10.7\ArcCatalog\***.gds", "SDE_WORKSPACE", "***.DBO.City_Limits","")
print "Successfully updated CITY_lIMITS data sources" https://desktop.arcgis.com/en/arcmap/10.6/analyze/arcpy-mapping/updatingandfixingdatasources.htm
... View more
06-15-2022
03:57 PM
|
0
|
0
|
1757
|
|
POST
|
Thank you and I appreciate the replay. I guess I am still stuck on if I add this to my current code and if so how or do I completely do a separate updatecursor. When I posted the ValueDict got cut off. valueDict = {r[0]:(r[1:]) for r in arcpy.da.SearchCursor(sjpoints1, sourceFieldsList)}
sourceFieldsList = ['TARGET_FID', poly,'Field1_1','Field2_1','Field3_1','Field4_2','Field4_1','Field5_1','Field6_1']
# define the field list to the original points
updateFieldsList = ['OID@', Pnt,'Field1','Field2','Field3','Field4','Field5','Field6']
#Run the Spatial Join tool, using the defaults for the join operation and join type
arcpy.SpatialJoin_analysis(ptSelection, parcel, sjpoints)
with arcpy.da.UpdateCursor(ptSelection, updateFieldsList) as updateRows:
for updateRow in updateRows:
# store the Join value of the row being updated in a keyValue variable
keyValue = updateRow[0]
# verify that the keyValue is in the Dictionary
if keyValue in valueDict:
# transfer the values stored under the keyValue from the dictionary to the updated fields.
for n in range (1,len(sourceFieldsList)):
updateRow[n] = valueDict[keyValue][n-1]
updateRows.updateRow(updateRow)
... View more
04-29-2022
11:13 AM
|
0
|
1
|
1274
|
|
POST
|
I am trying to pass some attributes from my layer to another but I am having an issue is with passing attributes from field 'Field4', the attributes from the layer sjpoints field 'Field4_1' doesn't match so the fc_dest layer 'Field4' and doesn't get updated. The issue is FIELD4_1 has abbreviations and fc_dest has domains. How can modify my current code to check that field and if it has certain abbreviations to update with certain text, or would it be best to do a separate updatecursor and if so how can I pass the nest dictionary from the spatial join to update the fc_dest layer? sjpoints - the spatial join has this TARGET_FID FIELD4_1 32145 MH 13245 SFR fc_dest - I need this OID FIELD4 32145 MOBILE HOME 12345 SINGLE FAMILY RES sourceFieldsList = ['TARGET_FID', poly,'Field1_1','Field2_1','Field3_1','Field4_2','Field4_1','Field5_1','Field6_1']
# define the field list to the original points
updateFieldsList = ['OID@', Pnt,'Field1','Field2','Field3','Field4','Field5','Field6]
#Run the Spatial Join tool, using the defaults for the join operation and join type
arcpy.SpatialJoin_analysis(ptSelection, parcel, sjpoints)
with arcpy.da.UpdateCursor(fc_dest, updateFieldsList) as updateRows:
for updateRow in updateRows:
# store the Join value of the row being updated in a keyValue variable
keyValue = updateRow[0]
# verify that the keyValue is in the Dictionary
if keyValue in valueDict:
# transfer the values stored under the keyValue from the dictionary to the updated fields.
for n in range (1,len(sourceFieldsList)):
updateRow[n] = valueDict[keyValue][n-1]
updateRows.updateRow(updateRow)
... View more
04-27-2022
03:29 PM
|
0
|
3
|
1355
|
|
POST
|
This did technically work but only if I add the Table path to the code, Table = "C:\temp\temp.gdb\table" with arcpy.da.SearchCursor(Table,['ParcelNum1','Permit_Count','PermitNum']) as cursor: Does not work with the Add Field output "TableTest6". with arcpy.da.SearchCursor("TableTest6",['ParcelNum1','Permit_Count','PermitNum']) as cursor:
... View more
03-17-2022
02:06 PM
|
0
|
0
|
3909
|
|
POST
|
Thank you for the replay, the example table I posted was incorrect and I have corrected it. I have verified that the fields are in the table and the code. The fields are 'PermitNum','ParcelNum1' & 'Permits". I have struggled with calculate fields calculations so I apologize if I am not understanding correctly. I have re-validated the entire model and re-ran it. This is in ArcCatolog and not in ArcMap or Pro. I have the following based on comments but I am still getting the error. def update():
dict1 = dict()
with arcpy.da.SearchCursor("TableTest6",['ParcelNum1','Permit_Count','PermitNum']) as cursor:
for row in cursor:
if row[0] not in (None, "", " "):
dict1.setdefault(row[0],[]).append(str(row[2]))
if key in dict1t:
x = ",".join(dict1[key])
return x Error: ERROR 000539: Error running expression: update() Traceback (most recent call last): File "<expression>", line 1, in <module> File "<string>", line 3, in update RuntimeError: cannot open 'TableTest6' Failed to execute (Calculate Field (5)).
... View more
03-17-2022
08:43 AM
|
0
|
0
|
3927
|
|
POST
|
I have re-validated and re-ran the model. What do you mean by re-run the tool(s) that generated the input, example ?
... View more
03-16-2022
03:57 PM
|
0
|
0
|
3957
|
|
POST
|
Thanks for the response Jake but I was trying to this in Model Build with Calculate field.
... View more
03-16-2022
01:42 PM
|
0
|
2
|
3985
|
|
POST
|
I have a model that I would like to use the the following code to update a field "Permits" based on how many text occurrences are in "ParcelNum1" field based on the "PermitNum" field. I get the following error and need help figuring out what the issues is and all fields are text fields. I need this in model builder. Example OBJECTID PermitNum ParcelNum1 Permits 1 aa1123 12345 12345, 12346 2 aa1123 12346 3 BB3361 67891 67891, 67892, 37893 4 BB3361 67892 5 BB3361 67893 6 UU9832 11123 11123 7 PP2225 6989 6988, 6989 8 PP2225 6988 Pre-Logic Script code: dict1 = dict()
with arcpy.da.SearchCursor('TableTest6',['ParcelNum1','Permit_Count','PermitNum']) as cursor:
for row in cursor:
if row[0] not in (None, "", " "):
dict1.setdefault(row[0],[]).append(str(row[2]))
def concat(nf):
x = None
if nf in dict1t:
x = ",".join(dict1[nf])
return x Permits = conact(!ParcelNum1! ) Error. ERROR 000539: Runtime error Traceback (most recent call last): File "<string>", line 2, in <module> RuntimeError: cannot open 'TableTest6' Failed to execute (Calculate Field (4)).
... View more
03-16-2022
11:08 AM
|
0
|
11
|
5007
|
|
POST
|
If I wanted to update another field (3rd) from that same table how would I do that? sourceFC = "C:/Temp/Temp.gdb/Table1"
where_clause = "MU LIKE '%TZ%'"
search_feats ={f[0]:(f[1:]} for f in arcpy.da.SearchCursor(sourceFC,["OBJECTID",'MU', 'KL'],where_clause)}
#searchVals = set(search_feats)
#print(search_feats)
with arcpy.da.UpdateCursor(sourceFC,["OBJECTID","MU_update", "KL_update"]) as upd_cur:
for upd_row in upd_cur:
try:
upd_row[1] = search_feats[upd_row[0]]
upd_row[2] = search_feats[upd_row[0]][2] ????
upd_cur.updateRow(upd_row)
except:
continue
... View more
03-07-2022
01:04 PM
|
0
|
1
|
1613
|
|
POST
|
I am trying to transfer attributes within a table from field "MU" to "MU_update" field but I get this error and I think it is because of my were_Clause but I am not 100% sure. "upd_row[1] = search_feats[upd_row[0]] KeyError: 1" import arcpy
env.workspace = "C:/Temp/PermitTest/PermitsTestData1/Permits.gdb"
sourceFC = "C:/Temp/Temp.gdb/Table1"
where_clause = "MU LIKE '%TZ%'"
search_feats ={f[0]:f[1] for f in arcpy.da.SearchCursor(sourceFC,["OBJECTID",'MU'],where_clause)}
#searchVals = set(search_feats)
#print(search_feats)
with arcpy.da.UpdateCursor(sourceFC,["OBJECTID","MU_update"]) as upd_cur:
for upd_row in upd_cur:
upd_row[1] = search_feats[upd_row[0]]
upd_cur.updateRow(upd_row)
... View more
03-07-2022
11:13 AM
|
0
|
4
|
1658
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 08-01-2024 07:19 AM | |
| 1 | 07-26-2024 09:38 AM | |
| 1 | 01-08-2024 09:44 AM | |
| 1 | 03-07-2023 11:46 AM | |
| 1 | 11-02-2020 08:24 AM |
| Online Status |
Offline
|
| Date Last Visited |
02-12-2026
12:36 PM
|