ArcGIS for Desktop

  • Documentation
  • Pricing
  • Support

  • My Profile
  • Help
  • Sign Out
ArcGIS for Desktop

ArcGIS Online

The mapping platform for your organization

ArcGIS for Desktop

A complete professional GIS

ArcGIS for Server

GIS in your enterprise

ArcGIS for Developers

Tools to build location-aware apps

ArcGIS Solutions

Free template maps and apps for your industry

ArcGIS Marketplace

Get apps and data for your organization

  • Documentation
  • Pricing
  • Support
Esri
  • Sign In
user
  • My Profile
  • Sign Out

Help

  • Home
  • Get Started
  • Map
  • Analyze
  • Manage Data
  • Tools
  • More...

Sort

  • Summary
  • Illustration
  • Usage
  • Syntax
  • Code sample
  • Environments
  • Licensing information

Summary

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.

Learn more about how Sort works

Illustration

Sort by three attributes

Usage

  • Feature classes can be spatially reordered, or sorted. The Shape field must be used as the sort field for spatial sorting. There are a number of spatial sort methods that arrange the features differently based on their location.

  • Geodatabase feature classes, shapefiles, feature layers, tables, and table views are valid inputs. Individual components of CAD and SDC datasets are also valid inputs.

  • If any input records are selected, only the subset of selected records are sorted and written to the output.

  • If more than one field is set as a sort field, rows are first sorted by the first field and within that order sorted by the second field, and so on.

  • Polygon features can be sorted by their area using the Shape_Area field of a geodatabase feature class. Similarly, polyline features can be sorted by their length using the Shape_Length field. If you want to sort polygon features in a shapefile add a new field, calculate the area into the new field using Calculate Field, and run Sort using the new field.

  • License:

    For the Field(s) parameter, sorting by the Shape field or by multiple fields is only available with an Advanced license. Sorting by any single attribute field (excluding Shape) is available at all license levels.

Syntax

Sort_management (in_dataset, out_dataset, sort_field, {spatial_sort_method})
ParameterExplanationData Type
in_dataset

The input dataset whose records will be reordered based on the field values in the sort field(s).

Table View
out_dataset

The output feature class or table.

Feature Class; Table
sort_field
[[sort_field, direction],...]

Specifies the field(s) whose values will be used to reorder the input records, and the direction the records will be sorted.

  • ASCENDING —Records are sorted from low value to high value.
  • DESCENDING —Records are sorted from high value to low value.
Value Table
spatial_sort_method
(Optional)

Specifies how features are spatially sorted. Sort method is only enabled when the Shape field is selected as one of the sort fields.

  • UR —Sorting starts at upper right corner. This is the default.
  • UL —Sorting starts at upper left corner.
  • LR —Sorting starts at lower right corner.
  • LL —Sorting starts at lower left corner.
  • PEANO —Sorting uses a space filling curve algorithm, also known as a Peano curve.
String

Code sample

Sort example 1 (Python window)

The following Python window script demonstrates how to use Sort to order features by the values of a field.

import arcpy
from arcpy import env

env.workspace = "C:/data/city.gdb"

arcpy.Sort_management("crime", "crime_Sort", [["DATE_REP", "ASCENDING"]])
Sort example 2 (stand-alone Python script)

The following Python script demonstrates how to use the Sort in a stand-alone script.

# Name: Sort_example2.py
# Description: Sorts wells by location and well yield.
# Author: ESRI

# Import system modules
import arcpy
from arcpy import env

try:
    # Set workspace environment
    env.workspace = "C:/data/newfoundland.gdb"

    # set local variables
    in_dataset = "wells"
    out_dataset = "wells_Sort"

    # Order features first by location (Shape) and then by WELL_YIELD
    sort_fields = [["Shape", "ASCENDING"], ["WELL_YIELD", "DESCENDING"]]

    # Use Peano algorithm
    sort_method = "PEANO"

    # execute the function
    arcpy.Sort_management(in_dataset, out_dataset, sort_fields, sort_method)
    
    print arcpy.GetMessages()

except arcpy.ExecuteError:
    # Print error messages
    print arcpy.GetMessages(2)
    
except Exception as ex:
    print ex.args[0]

Environments

  • Current Workspace
  • Scratch Workspace
  • Output Coordinate System
  • Geographic Transformations
  • Extent
  • XY Resolution
  • XY Tolerance
  • Output has M values
  • M Resolution
  • M Tolerance
  • Output has Z values
  • Default Output Z Value
  • Z Resolution
  • Z Tolerance
  • Qualified Field Names
  • Output XY Domain
  • Output M Domain
  • Output Z Domain

Licensing information

  • ArcGIS for Desktop Basic: Limited
  • ArcGIS for Desktop Standard: Limited
  • ArcGIS for Desktop Advanced: Yes

Related topics

  • An overview of the General toolset

ArcGIS for Desktop

  • Home
  • Documentation
  • Pricing
  • Support

ArcGIS Platform

  • ArcGIS Online
  • ArcGIS for Desktop
  • ArcGIS for Server
  • ArcGIS for Developers
  • ArcGIS Solutions
  • ArcGIS Marketplace

About Esri

  • About Us
  • Careers
  • Insiders Blog
  • User Conference
  • Developer Summit
Esri
Tell us what you think.
© Copyright 2016 Environmental Systems Research Institute, Inc. | Privacy | Legal