Geographic Information Systems Asked by soumik chakraborty on June 22, 2021
The name of my layer is "spat_join_output". So I have a field named ‘label’ and another two fields ‘end_point_x’ and ‘end_point_y’ for the same label values i want to check if the end_point_x and end_point_y values are same , i want to drop an error message in another field named as "Error".
I have my code as :-
array_fibre = arcpy.da.FeatureClassToNumPyArray("spat_join_output", ["label", "end_point_x", "end_point_y", "OBJECTID"], skip_nulls = True)
# arcpy.AddMessage(array_fibre)
for data in array_fibre:
arcpy.AddMessage(str(data))
if arcpy.Exists("spat_join_output"):
arcpy.AddField_management("spat_join_output", "Error", "Text", 100)
with arcpy.da.UpdateCursor("spat_join_output", ["label", "end_point_x", "end_point_y", "Error"]) as cursor:
for row in cursor:
if row[0] != None and row[1] != None and row[2] != None:
data = self.find_endpoints(array_fibre, row[0])
if len(data) > 0:
arcpy.AddMessage(data[0])
del cursor
I am trying to build a function for this, using an array method,
def find_endpoints(self, array, id):
count = 0
array_id = []
end_point_X_y = []
array_label = []
if len(array) > 0:
array_count = 0
for data in array:
if len(array_label) == 0 and id in data[0]:
array_label.append(data[0])
elif len(array_label) > 0 and id in data[0]:
array_label.append(data[0])
This is how my array looks:-
(‘CAS/C003’, ‘-877644.7019000016’, ‘6893765.545000002’, 2)
(‘CAS/C003’, ‘-877939.7175000012’, ‘6893358.312799998’, 3)
(‘CAS/C003’, ‘-877244.6374999993’, ‘6893426.772500001’, 4)
How about:
import arcpy
fc = r'C:Default.gdbspat_join_output'
fields = ['Label','end_point_x','end_point_y','Error']
data = set()
with arcpy.da.UpdateCursor(fc, fields) as cursor:
for row in cursor:
key = ' '.join([str(i) for i in row[:-1]]) #'CAS/C003 -877244.6374999993 6893426.772500001'
if key in data:
row[-1] = 'Duplicate found'
cursor.updateRow(row)
data.add(key)
Answered by BERA on June 22, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP