Select to view content in your preferred language

Calculating the Max N/S/E/W of polygon

14021
19
06-15-2016 03:42 AM
Emma_Cunliffe
New Contributor

Hi all

I have ARC 10.2.1.

I have a shapefile of polygons, and the I need the maximum N / S / E / W points for each polygon (not the centre point)

Is there a way to do this?

(I can use the tools etc, but have no knowledge of scripts or anything like that, so I would need some pretty basic instructions if that's what's required)

(Geometric attributes / extent only gives 2 max/min extents which do not reflect the actual shape of the polygon, not all 4)

Thanks

Tags (3)
0 Kudos
19 Replies
DanPatterson_Retired
MVP Emeritus

sorry, misread... you need the extent then, which can be done in the field calculator since it will produce the min x, max x, min y, max y

These won't formulate a point, but if you need the minimum X regardless of y and max X regardless of y and their y equivalents, then that is different

0 Kudos
FC_Basson
MVP Regular Contributor

Hi Dan Patterson​, yes I think Emma wants the coordinate/point for the vertice that represents each side of the bounding extent.

0 Kudos
DanPatterson_Retired
MVP Emeritus

Then that will make it much simpler, it is unfortunate that the field calculator doesn't return those points as options as well since the minx may be associated with another point other than the min y (ie the min_xy and max_xy rarely form a point in the actual polygon)

0 Kudos
Emma_Cunliffe
New Contributor

I've been asked for (for 430 polygons)

Latitude of Easternmost edge of site

Decimal degrees

The four ‘bounding coordinates’ of the site should be its easternmost, southernmost, westernmost and northernmost point.

Longitude of Easternmost edge of site

Decimal degrees

Latitude of Southernmost edge of site

Decimal degrees

Longitude of Southernmost edge of site

Decimal degrees

Latitude of Westernmost edge of site

Decimal degrees

Longitude of Westernmost edge of site

Decimal Degrees

Latitude of Northernmost edge of site

Decimal degrees

Longitude of Northernmost edge of site

Decimal degrees

0 Kudos
DanPatterson_Retired
MVP Emeritus

They are the extent values... you can get those in an existing table using Add Geometry Attributes—Help | ArcGIS for Desktop so you don't want an actual point... you want the coordinates that produce the bounds... as pointed out earlier, this is quite a bit different than what you originally asked for

0 Kudos
DarrenWiens2
MVP Honored Contributor

Looking at the table, I don't think extent will do. For example, using the extent rectangle, how can you describe the "longitude of the Northernmost edge of site" (although I don't think "edge" is quite the right word)?

0 Kudos
DanPatterson_Retired
MVP Emeritus

yes... perhaps.... didn't see the table in the email section.  So as I said earlier, this isn't done out of the box but as what i think, you have done, extract all the points for the shape, and pull out the min/max x/y which may not be an actual point, just half of a coordinate.  This is where a picture would help I agree 'site' is not well defined, nor is 'edge'

0 Kudos
RichardFairhurst
MVP Honored Contributor

While Darren's code only checks one coordinate axis to determine if the current vertex being examined is more extreme in a certain direction, he actually replaces the point associated with that compass direction with the full vertex point coordinate pair from the polygon boundary.  So all of the points listed in his table are real coordinates that fall on the polygon boundary.

I believe the extent pairs of min/max coordinates are correct for a single axis of each point in Dennis's list, but the other axis of the coordinate does not have to fall on the extent rectangle boundary corners.  So while the westerly most point has to match the min X value of the extent, the Y value can be anywhere along the western edge of the extent polygon (min Y <= West point Y <= max Y) as long as it is on a vertex of the original polygon (or a point along a true curve).  So as long as there are no true curves it seems like you could search through the vertices of the polygon and find any and all points that matched on the appropriate axis from the extent (which in the end should be what Dennis's code effectively does).  It can be accomplished by creating the extent rectangle for each polygon and doing an intersect to get the polygon points that actually touch the extent edge as a multipoint, but Python is easier since each polygon has to only intersect its own extent which would require iteration in ModelBuilder (inefficient).  See the picture below.  She wants the red points for the polygon below.

If the polygon included any true curves that could touch an edge of the polygon extent between the ends of the curve, you would have to use the intersect tool or the geometry intersect approach to find the real point for that compass direction, since the point along the extent boundary would not be a vertex of the polygon in that case.

DarrenWiens2
MVP Honored Contributor

Robert: yes, my code iterates through each vertex and pushes the points out until they are the most extreme case possible (or rather, first of most extreme points), on the extent rectangle. Whether or not you can shave some nanoseconds off with GP, I don't know.

0 Kudos
DarrenWiens2
MVP Honored Contributor

Here's how you can do it using Python:

1.) Add fields to polygon feature class (could also do in Python, if you want):

2.) Run script

>>> fc = 'all_aoi' # change to your layer name or feature class path
... fields = ['SHAPE@','N_X','N_Y','E_X','E_Y','S_X','S_Y','W_X','W_Y'] # pay attention to order
... with arcpy.da.UpdateCursor(fc,fields) as cursor: # loop through polygons
...    for row in cursor: # for each polygon
...        N = arcpy.Point(0,float('-inf')) # dummy coordinates
...        E = arcpy.Point(float('-inf'),0) # dummy coordinates
...        S = arcpy.Point(0,float('inf')) # dummy coordinates
...        W = arcpy.Point(float('inf'),0) # dummy coordinates
...        for part in row[0]: # loop through polygon parts
...            for pnt in part: # loop through vertices
...                if pnt.Y > N.Y: # test coordinates
...                    N = pnt # remember coordinates if vertex is more extreme               
...                if pnt.X > E.X: # test coordinates
...                    E = pnt # remember coordinates if vertex is more extreme
...                if pnt.Y < S.Y: # test coordinates
...                    S = pnt # remember coordinates if vertex is more extreme
...                if pnt.X < W.X: # test coordinates
...                    W = pnt # remember coordinates if vertex is more extreme
...        new_row = [row[0],N.X,N.Y,E.X,E.Y,S.X,S.Y,W.X,W.Y] # build new row data, same order as fields list
...        cursor.updateRow(new_row) # write row