I have a shapefile and I want to change the order of the features.

Is that possible?

I want to sort the features in the shapefile because I'm embedding this shapefile in a mobile app. The app will display a list of features, and although I could do the sorting at load time, I'd prefer to have them sorted.

  • 4
    The goal is legitimate, the mean is not. If you need them sorted, use the result of a query, don't assume they are and will remain sorted.
    – GuillaumeC
    Feb 8 '11 at 7:49

You can always open the attribute table in ArcMap and right click the columns header and select Sort Ascending.../Descending... for single fields.

For multiple fields you would instead click Advanced Sorting to select multiple fields.

NOTE: Adding, for instance, a sequential ID field based on the current sorting (which is temporary, stored only in this map/mxd) when using the above method will be ordered by the original OID/ObjectID of the feature class.

There is an ArcScripts available that will sort records permanently and output a new shapefile: http://arcscripts.esri.com/details.asp?dbid=16771

I do hope that when you state 'order of features' that this is the order found in the attribute table and not drawing order for the table of contents/symbology levels.


For QGIS there is a Sort plugin: http://michaelminn.com/linux/mmqgis/

enter image description here


Here is a solution to rewrite a new and sorted shapefile using the GDAL/OGR command-line tool ogr2ogr.

For example, a shapefile orig.shp has a numeric field volume to sort on. This particular SQL statement does a reverse sort (with DESC) so that features with large volume values are drawn before (underneath) features with small values:

ogr2ogr -sql "SELECT * FROM orig ORDER BY volume DESC" sorted.shp orig.shp

You can use the Sort in the (Data Management toolbox) which:

Reorders, in ascending or descending order, records in a feature class or table based on one or multiple fields. The reordered result is written to a new dataset.


An utility software of MapServer (free and open-source) can sort shapes according to attributes values :



A very, very FAST and easy method to sort a shapefile layer( using various fields) .

1 - Export shapefile to CSV (select good separator, like semicolon) and add GEOMETRY using "layer options" -> "AS WKT"

enter image description here

2 - Open file.csv with LIBREOFFICE (calc) and use MENU->DATA->SORT (very intuitive, powerfull and VERY FAST (Sort on the fly 50000 features using 3 columns like sort-key, ascending and descending options, and i have a very slow notebook ;) )

3 - Save again file from LIBREOFFICE (calc) as "Text CSV" ( mark "Edit filter settings" and choose separator as 'semicolon', don't matter warning from libreoffice, save like CSV and select 'semicolon' as separator )

4 - From Qgis open the new file.csv (and sorted) from 'Add Layer" menu -> Add Delimiter Text Layer.

PROS: - Very,very fast, sort from various fields - Works ok with UTF_8 encoded data

CONS: - Need LIBREOFFICE (but is it open source software)

Alternative method to sort (sustitute points 2 and 3, and is the most fast) using console (BASH)

  • Open console and go where you have file.csv

    Suppose you want sort file with the key:


    so the command will be:

    sort -t';' -k6,6r -k1,1 -k3,3r file.csv > file_sort.csv


    • you can add -kn,n for every column number 'n' (field) you needed add to your "sort key"
    • adding 'r' after every n,n will sort in reverse mode (descent)
    • Must pass the character separator used into csv file with -t param
  • Alternative method to sort without LibreOffice, using bash (console): Nov 24 '16 at 11:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.