Sort a feature table by geographic location

To sort in the direction with a bearing of a degrees east of north, precompute the unit direction vector as (sin(a), cos(a)).

With a field calculation, obtain the (projected) [X] and [Y] coordinates of features (use their centroids or whatever for non-point features) if they aren't already available and compute a new field equal to the distance along the bearing, given by the dot product of the direction vector with the coordinates:

z = sin(a) * [X] + cos(a) * [Y]

Sort the table on [z] in ascending order.

For example, for a north-to-south sort the bearing is 180 degrees, v = (sin(180), cos(180)) = (0, -1), and the resulting sort therefore is on -[Y], which arranges the records from largest [Y] (first) down to smallest [Y] (last), exactly as intended.


An "inner to outer" sort could mean many things, but one interpretation is that the sorting should be by distance relative to a central location. A similar solution applies, using the Pythagorean theorem to compute (squared) distance from a fixed point. (Applying the square root is unnecessary because it does not change the sort order.)


A more fanciful sort order is explained and illustrated at "One-dimensional map of the world."


To express whuber's answer in terms of tool use, here's a simple implementation of the North-South, East-West use case when using point data in Arcgis:

  • Add X and Y (or Lat and Long) columns to the attribute table, Calculate Geometry
  • export to Excel or whatever, sort by the column of interest (X for East-West, Y for North-South), and then bring back in with Add X/Y data.

courtesy of Esri Technical Article HowTo: Sort features North/South or East/West for Export

How to change the order of features in a shapefile? has solutions to do the table sorting part for both Arcgis and Qgis without need to export to an external program (though you still need to duplicate the table/feature class), and Sorting shapefile records on attribute to update new rank field using Python? has an arcpy method.