POST
|
I have a filed that I need to find records in a layer that have a number that should not be there. Not really sure on how to do this. Rec field has length of 10. In the example below the first and fourth records has 0 in the 9th space (it could be a different digit) and some records will have an alph character in the 9th space, which is ok as long as it's an alph character. I would like to somehow mark the records. Essentially, I need to find which records have a digit(skip if alph character is there) on the 9th space of the records. Hopefully this makes sense. Rec mark 12345678 0 ok ( or 1) 22345108A0 ok ( or 0) 6523148000 Not ok ( or 0) 62315010 9 Ok ( or 1) 6218921801 Not ok ( or 0)
... View more
04-21-2023
12:08 PM
|
0
|
6
|
456
|
POST
|
I was able to solve the empty geometry, by adding ['Shape@'] in the field names. I also included the sql_clause you had. Based on I am seeing and the print out, the script is just adding all the features from sourcFC and not acutally comparing and inserting the missing ones. Would it be best to compare two or three fields, if so how? dsc = arcpy.Describe(targetFC)
fields = dsc.fields
out_fields = ['OID@', 'Duplicate', 'GlobalID']
fieldnames = [field.name if field.name != 'Shape' else 'SHAPE@' for field in fields if field.name not in out_fields]
#print(out_fields)
#print(fieldnames)
keepList = []
# Switched from fc1 to targetFC
# You want to check the final product first
with arcpy.da.SearchCursor(targetFC, ['SHAPE@'] + fieldnames, sql_clause = (None, "ORDER BY PermitNum")) as cursor:
for row in cursor:
keepList.append(row) #Appended row, not row[0].
#Otherwise they might not check for the same thing
print("Keeplist length: ", len(keepList))
del cursor
#list of values from fc1 to inject into targetFC
ids = []
#Check for missing values comparing by row in total.
with arcpy.da.SearchCursor(fc1, ['SHAPE@'] + fieldnames, sql_clause = (None, "ORDER BY PermitNum")) as cursor:
for row in cursor:
if row not in keepList:
ids.append(row)
print("ids: ", ids, len(ids))
del cursor
#import all fields
#create insert cursor variable
with arcpy.da.InsertCursor(targetFC, ['SHAPE@'] + fieldnames) as insCursor:
for rows in ids:
insCursor.insertRow(rows)
... View more
04-03-2023
03:24 PM
|
0
|
2
|
648
|
POST
|
Oh wow. I looked back at my original data and there no empty geometry. I think I might have shared one (targetFC),that must have corrupted after testing, my apologies. I have attached a copy of the original data(targetFC), with the unnecessary fields removed. I verified there were no empty geometry, again my apologies. After verifying that both dataset had no empty geometry and verified with the code you attached. 0
Break
0 I ran the code below, but it created empty geometry on the target feature class. It appears to that the empty geometry ones are the missing ones that are being inserted into the targetFC. dsc = arcpy.Describe(targetFC)
fields = dsc.fields
out_fields = ['OID@', 'Shape_Leng', 'Shape_Area', 'Duplicate', 'GlobalID']
fieldnames = [field.name if field.name != 'Shape' else 'SHAPE@' for field in fields if field.name not in out_fields]
#print(out_fields)
#print(fieldnames)
keepList = []
# Switched from fc1 to targetFC
# You want to check the final product first
with arcpy.da.SearchCursor(targetFC, fieldnames) as cursor:
for row in cursor:
keepList.append(row) #Appended row, not row[0].
#Otherwise they might not check for the same thing
print("Keeplist length: ", len(keepList))
del cursor
#list of values from fc1 to inject into targetFC
ids = []
#Check for missing values comparing by row in total.
with arcpy.da.SearchCursor(fc1, fieldnames) as cursor:
for row in cursor:
if row not in keepList:
ids.append(row)
print("ids: ", ids, len(ids))
del cursor
#import all fields
#create insert cursor variable
with arcpy.da.InsertCursor(targetFC,fieldnames) as insCursor:
for rows in ids:
insCursor.insertRow(rows)
print ('Done', arcpy.management.GetCount(targetFC))
... View more
04-03-2023
02:49 PM
|
0
|
0
|
648
|
POST
|
I have these in a file geodatabase, and I removed all the none important fields. Thanks I really appreciate your help.
... View more
04-03-2023
10:08 AM
|
0
|
5
|
664
|
POST
|
I wasn't sure if you meant, if in the script or the layers, I removed the GlobalID from both feature classes and I am still getting doubles. Would you like me to share some of the data?
... View more
03-31-2023
08:23 AM
|
0
|
7
|
679
|
POST
|
I was running this outside Pro and thought maybe that was why I was getting different results but no. I put the info in Pro and ran the code. Here are my results I thought maybe I had something wrong in the code, so I copied the code you posted and ran it. aprx = arcpy.mp.ArcGISProject("CURRENT")
mp = aprx.activeMap
fc1 = mp.listLayers("Source")[0] # Copy in the Edit GDB, contains 25096 records
targetFC = mp.listLayers("target")[0] #Copy in the Published GDB, contains 11396 records
dsc = arcpy.Describe(targetFC)
fields = dsc.fields
out_fields = [dsc.OIDFieldName, dsc.lengthFieldName, dsc.areaFieldName, 'Field1','Field2', 'Field3']
fieldnames = [field.name if field.name != 'Shape' else 'SHAPE@' for field in fields if field.name not in out_fields]
#print(out_fields)
#print(fieldnames)
keepList = []
# Switched from fc1 to targetFC
# You want to check the final product first
with arcpy.da.SearchCursor(targetFC, fieldnames) as cursor:
for row in cursor:
keepList.append(row) #Appended row, not row[0].
#Otherwise they might not check for the same thing
print("Keeplist length: ", len(keepList))
del cursor
#list of values from fc1 to inject into targetFC
ids = []
#Check for missing values comparing by row in total.
with arcpy.da.SearchCursor(fc1, fieldnames) as cursor:
for row in cursor:
if row not in keepList:
ids.append(row)
print("ids: ", ids, len(ids))
del cursor
#import all fields
#create insert cursor variable
with arcpy.da.InsertCursor(targetFC,fieldnames) as insCursor:
for rows in ids:
insCursor.insertRow(rows)
print ('Done', arcpy.management.GetCount(targetFC))
... View more
03-30-2023
01:28 PM
|
0
|
9
|
791
|
POST
|
The current codes insert all the features in fc1 into the targetFc, at least for me. It doesn't appear to only insert the missing ones. If I run the code again, it just adds the total number of features in fc1again. I appreciate your input.
... View more
03-30-2023
09:10 AM
|
0
|
11
|
805
|
POST
|
I made the following changes. line 24 was if row[0] not in keepList: should be; if row not in keepList: Line 32 was InsertCursor .insertRow(rows) Should have been insCursor.insertRow(rows) fc1 = "lyTB"
targetFC = "lyA_2"
dsc = arcpy.Describe(targetFC)
fields = dsc.fields
out_fields = [dsc.OIDFieldName, dsc.lengthFieldName, dsc.areaFieldName, 'Field1','Field2', 'Field3']
fieldnames = [field.name if field.name != 'Shape' else 'SHAPE@' for field in fields if field.name not in out_fields]
keepList = []
with arcpy.da.SearchCursor(fc1, fieldnames) as cursor:
for row in cursor:
keepList.append(row[0])
#print(keepList)
del cursor
#list of values from fc1 to inject into targetFC
ids = []
with arcpy.da.SearchCursor(fc1, fieldnames) as cursor:
for row in cursor:
#print (row)
if row not in keepList:
ids.append(row)
del cursor
#import all fields
#create insert cursor variable
with arcpy.da.InsertCursor(targetFC,fieldnames) as insCursor:
for rows in ids:
insCursor.insertRow(rows)
print ('Done') How can I check using two other fields other than just the OID?
... View more
03-29-2023
02:28 PM
|
0
|
13
|
865
|
POST
|
I guess I mixed up append and merge. Append will append all feature in one layer to the other making duplicates, which is what I am trying to avoid.
... View more
03-29-2023
02:11 PM
|
0
|
1
|
878
|
POST
|
I need to insert missing features from one layer to another. I don't want to use the append tool because I don't want a new dataset, I just want to insert the missing features. Both are polygons and have pretty much the same fields except for 3 fields ('Field1','Field2', 'Field3'). I have the following but I get no error when I run it. import arcpy
fc1 = "lyTB"
targetFC = "lyA_2"
dsc = arcpy.Describe(targetFC)
fields = dsc.fields
out_fields = [dsc.OIDFieldName, dsc.lengthFieldName, dsc.areaFieldName, 'Field1','Field2', 'Field3']
fieldnames = [field.name if field.name != 'Shape' else 'SHAPE@' for field in fields if field.name not in out_fields]
keepList = []
with arcpy.da.SearchCursor(fc1, fieldnames) as cursor:
for row in cursor:
keepList.append(row[0])
#print(keepList)
del cursor
#list of values from fc1 to inject into targetFC
ids = []
with arcpy.da.SearchCursor(fc1, fieldnames) as cursor:
for row in cursor:
#print (row)
if row[0] not in keepList:
ids.append(row)
del cursor
#import all fields
#create insert cursor variable
with arcpy.da.InsertCursor(targetFC,fieldnames) as insCursor:
for rows in ids:
insertCursor.insertRow(rows)
print ('Done')
... View more
03-29-2023
02:00 PM
|
0
|
18
|
1580
|
POST
|
That was the issue, for some reason I thought I need the "search_feats" on line 16.
... View more
02-16-2023
01:50 PM
|
1
|
0
|
567
|
POST
|
I am trying to use dictionary to help update a field. I have the following but I am getting an error. Basically, if field "Type" has PVT, I want it to update with "Private" and if Pub, I want it to update with "Public". the filed doesn't get updated. I am assuming that dict is wrong? import arcpy
fc = r"C:\Temp\test.gdb\Testb"
search_feats ={f[0]:(f[:1] for f in arcpy.da.SearchCursor(fc,"Type")}
print(search_feats) #'OID@', 'Type'
place_dict = {"PVT": "Private",
"Pub": "Public"
}
with arcpy.da.UpdateCursor(fc,"Type") as upd_cur:
for upd_row in upd_cur:
if upd_row[0] in place_dict:
upd_row[0] = place_dict.get(search_feats[upd_row[0]], upd_row[0])
upd_cur.updateRow(upd_row)
... View more
02-16-2023
12:08 PM
|
0
|
5
|
606
|
POST
|
After setting up the model to use the delete tool and create file geodatabase tool, then scheduling it to run this morning, I get the warnings, the geodatabase already exists and so does the PI_Tax feature class. So nothing was deleted.
... View more
01-20-2023
07:19 AM
|
0
|
0
|
702
|
POST
|
I guess there is not in this particular situation, I could delete the geodatabase with the delete tool and then create a new one. I would still like to know why it's not delete with the Calculate Value Tool, if I run it through the task scheduler in Pro.
... View more
01-19-2023
01:29 PM
|
0
|
0
|
720
|
Title | Kudos | Posted |
---|---|---|
1 | 10-27-2022 11:37 AM | |
1 | 10-31-2023 10:16 AM | |
1 | 02-16-2023 01:50 PM | |
1 | 08-11-2021 11:13 AM | |
1 | 01-06-2021 10:45 AM |
Online Status |
Offline
|
Date Last Visited |
01-23-2024
11:04 AM
|