hello , i have 8 points with Z value .
each 2 points is a pair ( see the colors in the image attached).
i created a new feild calles "Delta" that in their i want the result of the difference between a pair..
for example the difference between point 2 to 1 is 4.66 meters..
is there a way to do this via while or for loop ?
thanks for the help!
Solved! Go to Solution.
I hate that error so much... And it could have any number of reasons.
Try a different approach:
Calculate the field, switch language to Arcade, use the script below. Be sure to clear selections!
var partner_oid = $feature.OBJECTID
if($feature.OBJECTID % 2 == 0) {
partner_oid -= 1
} else {
partner_oid += 1
}
var partner = First(Filter($featureset, "OBJECTID = @partner_oid"))
if(partner == null) { return null }
return Abs(partner.Z - $feature.Z)
I would use a SearchCursor to read all of the Z values into a python dict - indexed by the objectid. Then loop through the feature class with an UpdateCursor calculating the Delta value for each row and writing the result
Hey, i dont have a clue how to start writing the code...
can you please help me with that ?
thanks..!
Open the Python window:
Copy the script below, paste it into the Python window, edit the first line, run it
fc_path_or_layer_name = "PointsWithZValues"
fields = ["OBJECTID", "Z", "Delta"]
z_dict = {r[0]: r[1] for r in arcpy.da.SearchCursor(fc_path_or_layer_name, fields)}
with arcpy.da.UpdateCursor(fc_path_or_layer_name, fields) as cursor:
for oid, z, delta in cursor:
# if OBJECTID is even, the partner oid is oid - 1
# if OBJECTID is odd, the partner id is oid + 1
partner_oid = oid + (-1 if oid % 2 == 0 else 1)
delta = abs(z - z_dict[partner_oid])
cursor.updateRow([oid, z, delta])
Here, I used DoubleField as Z and TextField as Delta:
!!! The script assumes that your screenshot shows exactly what your table looks like, especially that the pairs are always odd and even ObjectID. If this isn't the case, the script gets a little more complicated (but not much) !!!
hey ,
thanks for your response.
i tried to run the script, but it wont run..
here is the messege :
what went wrong?
thanks!
It couldn't find OBJECTID 2.
Clear all selections and try again. If it still doesn't work, you need the slightly more complicated script.
this time i get the following mmessege :
I hate that error so much... And it could have any number of reasons.
Try a different approach:
Calculate the field, switch language to Arcade, use the script below. Be sure to clear selections!
var partner_oid = $feature.OBJECTID
if($feature.OBJECTID % 2 == 0) {
partner_oid -= 1
} else {
partner_oid += 1
}
var partner = First(Filter($featureset, "OBJECTID = @partner_oid"))
if(partner == null) { return null }
return Abs(partner.Z - $feature.Z)
that worked well!
thank you so much!
but it still interesting why the python code didnt work...