| GDAL-VECTOR-SORT(1) | GDAL | GDAL-VECTOR-SORT(1) |
NAME
gdal-vector-sort - Spatially sort a vector dataset
Added in version 3.13.
SYNOPSIS
Usage: gdal vector sort [OPTIONS] <INPUT> <OUTPUT>
Spatially order the features in a layer
Positional arguments:
-i, --input <INPUT> Input vector datasets [required] [not available in pipelines]
-o, --output <OUTPUT> Output vector dataset [required] [not available in pipelines]
Common Options:
-h, --help Display help message and exit
--json-usage Display usage as JSON document and exit
--config <KEY>=<VALUE> Configuration option [may be repeated]
-q, --quiet Quiet mode (no progress bar or warning message) [not available in pipelines]
Options:
-l, --layer, --input-layer <INPUT-LAYER> Input layer name(s) [may be repeated] [not available in pipelines]
-f, --of, --format, --output-format <OUTPUT-FORMAT> Output format ("GDALG" allowed) [not available in pipelines]
--co, --creation-option <KEY>=<VALUE> Creation option [may be repeated] [not available in pipelines]
--lco, --layer-creation-option <KEY>=<VALUE> Layer creation option [may be repeated] [not available in pipelines]
--overwrite Whether overwriting existing output dataset is allowed [not available in pipelines]
--update Whether to open existing dataset in update mode [not available in pipelines]
--overwrite-layer Whether overwriting existing output layer is allowed [not available in pipelines]
--append Whether appending to existing layer is allowed [not available in pipelines]
Mutually exclusive with --upsert
--output-layer <OUTPUT-LAYER> Output layer name [not available in pipelines]
--skip-errors Skip errors when writing features [not available in pipelines]
--geometry-field <GEOMETRY-FIELD> Name of geometry field to use in sort
--method <METHOD> Geometry sorting algorithm. METHOD=hilbert|strtree (default: hilbert)
--use-tempfile Write features to a temporary file to avoid reading the entire input dataset into memory
Advanced Options:
--if, --input-format <INPUT-FORMAT> Input formats [may be repeated] [not available in pipelines]
--oo, --open-option <KEY>=<VALUE> Open options [may be repeated] [not available in pipelines]
--output-oo, --output-open-option <KEY>=<VALUE> Output open options [may be repeated] [not available in pipelines]
--upsert Upsert features (implies 'append') [not available in pipelines]
Mutually exclusive with --append
DESCRIPTION
gdal vector sort sorts the features in a vector dataset according to the position of its geometries. The sorting method can be specified via --method, with Hilbert and Sort-Tile-Recursive (STRTree) algorithms available.
Features that have null or empty geometries will be placed at the end of the sorted dataset.
This command can also be used as a step of gdal vector pipeline.
NOTE:
Use of the STRtree algorithm requires a GDAL build
against the GEOS library.
PROGRAM-SPECIFIC OPTIONS
- --geometry-field <GEOMETRY-FIELD>
- The name of the geometry field by which features should be sorted.
- --method <METHOD>
- Specifies the sorting method. Available options are:
- hilbert : default method. Geometries are sorted according to the Hilbert code of the center point of their bounding box
- strtree : Geometries are sorted by constructing a sort-tile-recursive tree using the GEOS library and performing a depth-first iteration.
- --use-tempfile
- Write the input features to a temporary file from which they can be read in sorted order. Avoids the need to load the entire input layer into memory.
RETURN STATUS CODE
The program returns status code 0 in case of success, and non-zero in case of error (non-blocking errors emitted as warnings are considered as a successful execution).
EXAMPLES
Example 1: Create a cloud-optimized Shapefile
$ gdal vector sort in.gpkg out.shp --method hilbert --lco SPATIAL_INDEX=YES
AUTHOR
Dan Baston <dbaston@gmail.com>
COPYRIGHT
1998-2026
| May 8, 2026 |