# Sorting polygons by latitude?

We have a set of polygons which we would like to sort and number according to their latitude. This will make it easier for local authorities to relate to the numbers of the objects.

Any suggestions for how to solve this using Esri tools or open source tools are interesting.

-
What is the key X,Y location on your polygons? The centroid or the northernmost vertex? – PolyGeo Jan 22 '13 at 9:42
Is Your polys living in a database? Why don't you use PostGIS functions to make this? – Magno C Jan 22 '13 at 9:57
Using the centroid would be ok. This time I need this to have the object names in a proper order. – ragnvald Jan 22 '13 at 10:17
Polygons residing in shapefiles only. I am aware of a solution available using PostGIS: gis.stackexchange.com/questions/32052/… – ragnvald Jan 22 '13 at 10:27

For an automated ArcGIS solution, try the following in model builder:

1. Add a new field "Latitude".
2. Calculate the "Latitude" field using Calculate Field: `!SHAPE.FirstPoint.Y!` (see attached field calculator screenshot). This calculation is based on the centroid of each polygon.
3. Create a new shapefile using Sort. Note that the new shapefile will have a new OBJECTID based on the sorted Latitude values.

Or, to loop through a workspace and perform the tasks on multiple shapefiles, here is an automated python approach:

``````# Import arcpy module
import arcpy
from arcpy import env

env.overwriteOutput = 1

env.workspace = r"C:\temp"
Dir = env.workspace

# List shapefiles
fclist = arcpy.ListFeatureClasses()

for fc in fclist:

arcpy.AddField_management(fc, "Latitude", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")

# Process: Calculate Field
arcpy.CalculateField_management(fc, "Latitude", "!SHAPE.FirstPoint.Y!", "PYTHON_9.3", "")

# Process: Sort
arcpy.Sort_management(fc, Dir + "\\" + fc + "_sort.shp", "Latitude ASCENDING", "UR")
``````

-
1. Assuming your data has a projected coordinate system: Set data frame to a geographic coordinate system (WGS84). Add your data. (Set datum transformation if nessesary.)
2. Add a new field (ycoordinate). Right click field ycoordinate and calculate y-coordinate of centroid (use coordinate system of data frame for calculation.)
3. Export data to Excel
4. In Excel: sort field y-coordinate. In a new field (orderxls) calculate sequential numbers
5. Join excel table to your data in ArcMap.
6. Add a new field (order) in ArcMap. Use field calculator to copy values from orderxls to order.
-

One way to do this is to measure each polygons individual distance to a known point in the north. The North pole could be relevant here. This could be done making a script which iterates through all the polygons, makes a calculation of the distance to the North-Pole, and writes it to the file in a designated field.

A script solving this problem should be straight forward using arcpy.

-
Won't the distance (at least in Decimal Degrees) to the North Pole, if your polygons are all in the Northern Hemisphere, just be (90 - latitude)? – PolyGeo Jan 22 '13 at 9:44
An alternate approach to this would be to create a linestring to the north of your points, then use an order by distance() to create the output order you need. – BradHards Jan 22 '13 at 9:59
The latitude, also in decimal degrees, will wary according to the objects latitude. I believe the sketch solution above is valid. But if other options are there (for ArcGIS or QGIS I am all ears. – ragnvald Jan 22 '13 at 10:41