---
name: "sortshp"
section: "1"
platform: "linux"
package: "mapserver-bin"
version: "8.4.0-4+deb13u2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/sortshp"
---

# sortshp(1)

sort a Shape data set

## NAME

sortshp - sort a Shape data set

## SYNOPSIS

FC**sortshp**F\[0\]  \[ *infile* *outfile*  *item*  \[*ascending* \| *descending*\] \| FC**-v**F\[0\]\]

## DESCRIPTION

**sortshp** sorts a Shape data set based on a single column in ascending or descending order. Supports INTEGER, DOUBLE and STRING column types. Useful for prioritizing shapes for rendering and/or labeling.

The idea here is that if you know that you need to display a certain attribute classed by a certain value, it will be faster for MapServer to access that value if it is at the beginning of the attribute file.

## OPTIONS

- *infile*

  The name of the .shp file

- *outfile*

  The name of the .shp/.shx and .dbf files to create

- *item*

  Name of the field to sort on

- *ascending*, *descending*

  Sort order (default: ascending)

- FC**-v**F\[0\]

  Display mapserver version and build options.

## EXAMPLE

This example uses a roads file ('roads\_ugl') that has a field with road classes in integer format ('class1').

```
FC
       sortshp roads_ugl roads-sort class1 ascending
      F[0]
```

Result:

A new Shape data set named 'roads-sort.shp' is created with shapes sorted in ascending order, according to the values in the 'class1' field.

**Figure 1: Attributes Before sortshp**\
  ⟨http://mapserver.org/\_images/sortshp-before.png⟩

**Figure 2: Attributes After sortshp**\
  ⟨http://mapserver.org/\_images/sortshp-after.png⟩

## SEE ALSO

[**map2img**(1)](/map2img/1.md), [**shptree**(1)](/shptree/1.md), [**shptreetst**(1)](/shptreetst/1.md), [**shptreevis**(1)](/shptreevis/1.md)
