|
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
|
1429
|
|
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
|
1014
|
|
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
|
1095
|
|
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
|
2505
|
|
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
|
2523
|
|
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
|
2553
|
|
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
|
2581
|
|
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
|
3298
|
|
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
|
1240
|
|
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
|
1285
|
|
POST
|
Man I could not get the field calculator to work, I kept getting that I have a syntax error. I ended up just using the python window with updatecursor. import arcpy
fc = "layer"
with arcpy.da.UpdateCursor(fc,["SC","SC2"]) as cursor:
for row in cursor:
if row[0] not in (None, "", " "):
if row [0] == "GR":
row [1]= "GRAIN"
elif row [0] == "WR":
row [1] = "WRITE"
elif row [0] == "PL":
row [1] = "PLACE"
cursor.updateRow(row)
else:
pass
... View more
01-19-2022
09:19 AM
|
1
|
0
|
402
|
|
POST
|
Using what you posted if SC is not None: but still have me the error "The field is not nullable". So I check the attributes filed and there are some blanks and nulls. I am trying to run this on the how feature class table not just the selected features. def Reclass(SC):
if SC not in [None, "", " "]:
if (SC == "GR"):
return "GRAIN"
elif (SC == "WR"):
return "WRITE"
elif (SC == "PL"):
return "PLACE"
updateField = Reclass(!SC!)
... View more
01-14-2022
01:14 PM
|
0
|
1
|
1854
|
|
POST
|
It was in vbscript, so I though I had it figured out but I guess not. The following only works with one if but when adding more elif I get an error that field is not nullable. How do I handle Nulls and blanks in field calculator? The SC field dose have some nulls and blanks. def Reclass(SC):
if (SC == "GR"):
return "GRAIN"
elif (SC == "WR"):
return "WRITE"
elif (SC == "PL"):
return "PLACE"
updateField = Reclass(!SC!)
... View more
01-14-2022
12:06 PM
|
0
|
3
|
1876
|
|
POST
|
Total rookie mistake, I forgot to check the python parser box.
... View more
01-14-2022
11:41 AM
|
1
|
0
|
1881
|
|
POST
|
I have tried it with quotes and still get the syntax error. def Reclass(SC):
if (SC == "GR"):
return "GRAIN"
if (SC == "WR"):
return "WRITE"
if (SC == "PL"):
return "PLACE"
updateField = Reclass(!SC!)
... View more
01-14-2022
11:37 AM
|
0
|
0
|
1881
|
| 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 |
07-14-2025
07:49 AM
|