Select to view content in your preferred language

Arcpy to extract the YMax coordinate and its X pair from polygon

842
3
07-04-2023 02:04 AM
Labels (2)
EmiliaBoc
New Contributor

Hello! I need a little bit of help!

I have to extract from a polygon feature class the YMax coordinate value and its corresponding X value ( which is not necessary equal to XMax). I need them in two fields in attribute table "YMax" and "X". 

I tried with field calculator for YMax, it worked, but i have problems with its pair, X coordinate. 

Thank you in advance!

0 Kudos
3 Replies
JohannesLindner
MVP Alum

Field Calculator, switch to Arcade. Edit the last line to return the X or Y coordinate.

function sort_by_y (p1, p2) {
    return p1.Y < p2.Y
}

var vertices = Geometry($feature).rings[0]
var v_YMax = First(Sort(vertices, sort_by_y))
return v_YMax.X

Have a great day!
Johannes
DanPatterson
MVP Esteemed Contributor

You can get many geometry attributes directly for a whole featureclass using this tool

Calculate Geometry Attributes (Data Management)—ArcGIS Pro | Documentation

these include extent parameters amongst other things


... sort of retired...
0 Kudos
JohannesLindner
MVP Alum

Yeah, getting YMax is easy. Would also be a one-liner with Arcade/Python. But Calculate Geometry Attributes won't give you the X coordinate of the northern-most vertex.


Have a great day!
Johannes
0 Kudos