Skip to content

Add gdal vector unnest, or convert gdal vector explode-collections into gdal vector explode? #14454

@dbaston

Description

@dbaston

Feature description

I implemented a pipeline step to convert a single feature with array field(s) into multiple features with scalar field(s). You can convert multiple array fields, provided that they are all the same length in every feature. An example use case is with gdal raster zonal-stats, to get a table of the pixels covered by a polygon:

echo -e "wkt\n\"POINT (440720 3751320)\"" | gdal pipeline read --input-format CSV --oo GEOM_POSSIBLE_NAMES=wkt /vsistdin/ ! buffer 150 ! zonal-stats --input autotest/gcore/data/byte.tif --zones _PIPE_ --pixels fractional --stat center_x --stat center_y --stat values --stat coverage ! unnest --field center_x --field center_y --field values --field coverage ! write --of CSV /vsistdout/

which outputs

center_x,center_y,values,coverage
440750,3751290,107,1
440810,3751290,123,1
440870,3751290,132,0.423658132553101
440750,3751230,115,1
440810,3751230,132,0.88035124540329
440870,3751230,107,0.07479527592659
440750,3751170,115,0.423658132553101
440810,3751170,132,0.07479527592659

Then I started wondering if gdal vector explode-collections should instead be reworked to allow exploding geometry and/or array attribute fields, subject to the same constraint that everything being exploded must have the same number of parts/elements.

So

`gdal vector explode --geom`
`gdal vector explode --field array_1 --field array_2`
`gdal vector explode --geom --field array_1` 

But this turns out to be at odds from the current behavior of gdal vector explode-collections, where we get the cartesian product of the exploded fields rather than "zipping".

Any thoughts?

Additional context

The name "unnest" comes from the PostgreSQL function that does the same thing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgdal_cliAnything related to the new 3.11 "gdal" CLI frontendnot for AI loversSee https://gdal.org/en/stable/community/ai_tool_policy.html

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions