POST
|
I tried you function but I couldn't get it to work right. pre-logic script code: def mark_records(records):
result = []
for rec in records:
# Check if the 9th character (index is an alphabetic character
if rec[8].isalpha() or rec[8].isspace():
# Mark as ok
result.append({"Rec": rec, "Mark": "ok"})
elif rec[8].isdigit():
# Mark as Not ok
result.append({"Rec": rec, "Mark": "Not ok"})
else:
# If neither alphabetic nor digit nor space, mark as Invalid
result.append({"Rec": rec, "Mark": "Invalid"})
return result Field = (!rec!)
... View more
04-24-2023
07:29 AM
|
0
|
0
|
534
|
POST
|
oh I see, line 9 (row[0])[8].isnumeric. Thanks for the help.
... View more
04-24-2023
07:24 AM
|
0
|
0
|
536
|
POST
|
This worked in Arcmap, but how can run it outside. I tired the following but I get "Parameters are not valid." or with updatecursor? import arcpy
inTable = "fc"
fieldName = "rec"
expression = "digitron(rec)"
codeblock = """
def digitron(rec):
try:
if rec[8].isnumeric():
return 'Not OK'
else:
return 'OK'
except:
return 'Some error' """
arcpy.management.CalculateField(inTable, fieldName, expression, "PYTHON3", codeblock)
... View more
04-21-2023
02:52 PM
|
0
|
2
|
583
|
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
|
626
|
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
|
881
|
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
|
881
|
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
|
897
|
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
|
912
|
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
|
1098
|
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
|
1112
|
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
|
1172
|
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
|
1185
|
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
|
2120
|
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
|
755
|
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 |
2 weeks ago
|