GDAL-VECTOR-EXPLODE-COLLECTIONS(1)

πŸ“¦
version 3.13.3 Β· 4 versions
, in alpine 3.24, arch rolling, ubuntu stonking

✨ NAME ✨

gdal-vector-explode-collections β€” the tool that explodes geometries of type collection of a vector dataset. That's it, that's the whole job description, bestie. (You'll see this page catalogued as GDAL-VECTOR-EXPLODE-COLLECTIONS(1) in the GDAL manual, section 1, for all your citation needs πŸ’…)

She's Added in version 3.12. β€” brand new, fresh out the box, we love a new arrival πŸŽ€


🌸 SYNOPSIS 🌸

Usage: gdal vector explode-collections [OPTIONS] <INPUT> <OUTPUT>

Explode geometries of type collection of a vector dataset.

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]
  --active-layer <ACTIVE-LAYER>                        Set active layer (if not specified, all)
  --active-geometry <ACTIVE-GEOMETRY>                  Geometry field name to which to restrict the processing (if not specified, all)
  --geometry-type <GEOMETRY-TYPE>                      Geometry type
  --skip-on-type-mismatch                              Skip feature when change of feature geometry type failed

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

Okay so the vibe check on that block 🫢:

  • Positional arguments β€” -i/--input <INPUT> and -o/--output <OUTPUT> are both required, both [not available in pipelines]. You literally cannot run this without handing it an input and an output. Non-negotiable, like my iced coffee order.
  • Common Options β€” -h/--help, --json-usage (spits the usage as a JSON document then dips), --config <KEY>=<VALUE> (repeatable, obvi), and -q/--quiet (no progress bar, no warning message β€” [not available in pipelines]).
  • Options β€” the layer/format/creation-option crowd: -l/--layer/--input-layer <INPUT-LAYER>, -f/--of/--format/--output-format <OUTPUT-FORMAT> (heads up: "GDALG" is allowed ✨), --co/--creation-option <KEY>=<VALUE>, --lco/--layer-creation-option <KEY>=<VALUE>, --overwrite, --update, --overwrite-layer, --append (mutually exclusive with --upsert), --output-layer <OUTPUT-LAYER>, --skip-errors, --active-layer <ACTIVE-LAYER>, --active-geometry <ACTIVE-GEOMETRY>, --geometry-type <GEOMETRY-TYPE> and --skip-on-type-mismatch.
  • Advanced Options β€” --if/--input-format <INPUT-FORMAT>, --oo/--open-option <KEY>=<VALUE>, --output-oo/--output-open-option <KEY>=<VALUE>, and --upsert (which implies 'append' and is mutually exclusive with --append).

Also, tiny detail that matters: almost everything up there is [not available in pipelines] except the handful of flags that are. Don't @ me, just read the brackets πŸ™ˆ


πŸ’– DESCRIPTION πŸ’–

So like. gdal vector explode-collections produces one feature for each geometry in any kind of geometry collection. One geometry in β†’ one feature out. That's the entire personality, and honestly? Iconic. πŸ‘‘

Example time, because examples are how brains work. If a feature contains a geometry MULTIPOINT(1 2,3 4), then two corresponding target features get generated: one with geometry POINT(1 2), and another one with geometry POINT(3 4). Two for the price of one, we ate πŸ”₯

But bestie, hear me: collections are not recursively exploded. So a GEOMETRYCOLLECTION(GEOMETRYCOLLECTION(POINT (1 2),POINT(3 4)) gets exploded as GEOMETRYCOLLECTION(POINT (1 2),POINT(3 4)). It handles the outer level and stops. No going deeper. She said "one layer of peeling, that's my limit." πŸ“ (and yes, that's literally how it's written above, I'm not touching the parentheses, not my business πŸ’€)

It can also be used as a step of gdal vector pipeline, so you can slot her into a whole little assembly line of processing. Very teamwork, very main character energy 🌈


πŸ¦‹ GDALG OUTPUT (ON-THE-FLY / STREAMED DATASET) πŸ¦‹

Okay this part is genuinely cool. This program supports serializing the command line as a JSON file using the GDALG output format. You know how you just typed out this whole entire pipeline and now you gotta remember it forever? No you don't. It gets written down for you. ✨

That resulting file can then be opened as a vector dataset using the GDALG: GDAL Streamed Algorithm driver, and it will apply the specified pipeline in a on-the-fly / streamed way. Streamed meaning it just... happens, as you go, like a vibe that flows. No intermediate dataset hoarding, no disk drama. Obsessed πŸ¦‹


πŸ‘‘ PROGRAM-SPECIFIC OPTIONS πŸ‘‘

--geometry-type <GEOMETRY-TYPE>

Change the geometry type of exploded geometries to be one of these, exactly: GEOMETRY, POINT, LINESTRING, POLYGON, CIRCULARSTRING, COMPOUNDCURVE, CURVEPOLYGON, POLYHEDRALSURFACE or TIN.

You can also append Z, M or ZM suffixes to any of those values to say what dimensionality you want β€” that's the flavor of the geometry, if you will πŸ’…

⚠️ Now the cautionary tale: the presence of geometries that cannot be coerced to the specified type will cause an error, unless you pass --skip-on-type-mismatch. So either she converts or she screams. There is no third option (well, the third option is --skip-on-type-mismatch, that's literally it 😭).

--skip-on-type-mismatch

Do not generate output features when their target geometry type does not match the one specified by --geometry-type. Basically: mismatched features just quietly don't show up to the party. No error, no feature, no problem 🫢


🌈 STANDARD OPTIONS 🌈

--active-geometry <ACTIVE-GEOMETRY>

Set the active geometry field from its name. When it's specified, only the specified geometry field is subject to the processing, and the other geometry fields will be not modified. If you don't specify it, then all geometry fields are subject to the processing. (Yes, all of them. She's thorough like that.)

This one can be combined together with --active-layer β€” duo, not versus 🌸

--active-layer <ACTIVE-LAYER>

Set the active layer. When specified, only the layer you named is subject to the processing, and the other layers will be not modified. If it's not specified, all layers are subject to the processing. So it's the "ma'am, just this one please" knob ✨

--append

Whether appending features to existing layer(s) is allowed. This also creates the output dataset if it does not exist yet β€” so it's giving "append, but make it constructive" πŸŽ€

--co, --creation-option <NAME>=<VALUE>

Many formats have one or more optional dataset creation options that can be used to control particulars about the file created. For instance, the GeoPackage driver supports creation options to control the version. (How very specific of it.)

May be repeated.

The dataset creation options available vary by format driver, and some simple formats have no creation options at all. You can list the options supported for a format with the --formats command line option, but the documentation for the format is the definitive source of information on driver creation options. See Vector drivers format specific documentation for legal creation options for each format.

πŸ’‘ Note that dataset creation options are different from layer creation options. Do not mix them up, do not pass one where the other goes, I'm begging πŸ™ˆ

--if, --input-format <format>

Format/driver name to be attempted to open the input file(s). It is generally not necessary to specify it β€” but it can be used to skip automatic driver detection, for when that detection fails to select the appropriate driver. Rude of it, honestly.

This option can be repeated several times to specify several candidate drivers. Note that it does not force those drivers to open the dataset. In particular, some drivers have requirements on file extensions. So it's a suggestion, not a summon πŸ’…

May be repeated.

--input-layer <INPUT-LAYER>

Specifies the name of one or more layers to process. By default, all layers will be processed. And if you want to read and write all layers but only dive into a subset, use --active-layer instead. Different flag, different job, keep up bestie 🫢

--lco, --layer-creation-option <NAME>=<VALUE>

Many formats have one or more optional layer creation options that can be used to control particulars about the layer created. For instance, the GeoPackage driver supports layer creation options to control the feature identifier or geometry column name, setting the identifier or description, etc. So many little sliders, we love a customization moment 🎚️

May be repeated.

The layer creation options available vary by format driver, and some simple formats have no layer creation options at all. A list of options supported for a format can be listed with the --formats command line option, but the documentation for the format is the definitive source of information on driver creation options. See Vector drivers format specific documentation for legal creation options for each format.

πŸ’‘ And again, for the people in the back: layer creation options are different from dataset creation options.

--oo, --open-option <NAME>=<VALUE>

Dataset open option (format specific).

May be repeated.

-f, --of, --format, --output-format <OUTPUT-FORMAT>

Which output vector format to use. Allowed values may be given by:

gdal --formats | grep vector | grep rw | sort

Pipe it, grep it, sort it, slay it πŸ”₯

--output-layer <NAME>

Specifies the name of the layer to which features will be written. If you don't specify it, output layer names will be the same as input layer names β€” she copies the whole look, no notes ✨

--output-open-option, --output-oo <NAME>=<VALUE>

Added in version 3.12.

Dataset open option for output dataset (format specific).

May be repeated.

--overwrite

Allow the program to overwrite an existing target file or dataset. Otherwise β€” and this is the default, so pay attention β€” gdal errors out if the target file or dataset already exists. She will not bulldoze anything without permission. Very respectful πŸ’…

--overwrite-layer

Whether overwriting the existing output vector layer is allowed. Layer-level, not dataset-level. Two different levels of chaos, two different flags πŸ‘‘

--skip-errors

Added in version 3.12.

Whether failures to write feature(s) should be ignored.

⚠️ Real talk though: this option sets the size of the transaction unit to one feature at a time, which may cause severe slowdown when inserting into databases. So it's forgiving, but it's not free. Choose your battles 😭

--update

Whether to open an existing output dataset in update mode. In-place editing energy, go off πŸ¦‹

--upsert

Added in version 3.12.

Variant of --append where the OGRLayer::UpsertFeature() operation is used to insert or update features, instead of appending with OGRLayer::CreateFeature().

This is currently implemented only in a few drivers: GPKG β€” GeoPackage vector, Elasticsearch: Geographically Encoded Objects for Elasticsearch, and MongoDBv3 (drivers that implement upsert expose the GDAL_DCAP_UPSERT capability).

The upsert operation uses the FID of the input feature, when it is set (and the FID column name is not the empty string), as the key to update existing features.

🚨 It is crucial to make sure that the FID in the source and target layers are consistent. Like, actually crucial. Not "crucial" in the casual way. In the this-will-bite-you way πŸ’€

For the GPKG driver, it is also possible to upsert features whose FID is unset or non-significant (the --unset-fid option of gdal vector edit can be used to ignore the FID from the source feature), when there is a UNIQUE column that is not the integer primary key. Very situational, very specific, very her ✨


okay bestie, and that's not even the whole page β€” more incoming, don't you dare close the tab 🫢

πŸ’– RETURN STATUS CODE πŸ’–

okay so bestie, here's the vibe check on how this thing says goodbye πŸ‘‹

  • Success β€” the program returns status code 0. slay. that's the one we want πŸ’…
  • Error β€” the program returns a non-zero status code. sad girl hours 😭
🫢 little plot twist tho: non-blocking errors that get emitted as warnings still count as a successful execution. so like, a lil warning won't break your exit code, it's giving "noted but we move" ✨

🌸 EXAMPLES 🌸

✨ Example 1: Only retain parts of geometry collections that are of type Point. ✨

the assignment: your geometry collection got a whole friend group in it, and you only want the Point girlies to make it to the output. iconic. here's the exact command, no cap:

$ gdal vector explode-collections --geometry-type=POINT --skip-on-type-mismatch in.gpkg points.shp --overwrite

so we're reading from in.gpkg, filtering down to <rainbow>POINT</rainbow> with --geometry-type=POINT, politely skipping anything that isn't that type with --skip-on-type-mismatch (no tantrums, just vibes πŸ™ˆ), writing the whole thing out to points.shp, and hitting it with --overwrite so it ruthlessly replaces whatever was already sitting there. periodt. πŸ‘‘


πŸŽ€ AUTHOR πŸŽ€

Even Rouault <even.rouault@spatialys.com> πŸ’œ

1998-2026


and that's the whole page bestie, we ATE πŸ“πŸ’… the footer's out here telling us this is the GDAL-VECTOR-EXPLODE-COLLECTIONS(1) manual, dated Aug 18, 202 β€” so go forth, explode those collections, and collect your points πŸ¦‹βœ¨ byeee πŸ’–

πŸ“¦ where this page comes from