OSGeo / gdal

GDAL is an open source MIT licensed translator library for raster and vector geospatial data formats.
https://gdal.org
Other
4.91k stars 2.56k forks source link

Forcing a geometry type as output doesn't seem to work on multipolygons #11068

Open theroggy opened 3 weeks ago

theroggy commented 3 weeks ago

What is the bug?

When gdal.VectorTranslate with option geometryType is ran on a file with (also) multipolygons, for most geometrytypes being specified the conversion is not happening:

PS: Sorry for the stupid bug reports, but I'm cleaning up warnings in my unit tests ;-)...

Steps to reproduce the issue

from osgeo import gdal

gdal.UseExceptions()

for geometrytype in ["MULTILINESTRING", "LINESTRING", "MULTIPOINT", "POINT"]:
    options = gdal.VectorTranslateOptions(geometryType=geometrytype)
    ds_output = gdal.VectorTranslate(
        srcDS="/vsicurl/https://github.com/geofileops/geofileops/raw/main/tests/data/polygon-parcel.gpkg",
        destNameOrDestDS=f"C:/temp/force_type_{geometrytype}.gpkg",
        options=options,
    )

Versions and provenance

Windows 11 with gdal 3.9.2 installed from conda-forge

Additional context

No response

rouault commented 3 weeks ago

You are running into implementation limits of https://gdal.org/en/latest/doxygen/ogr__api_8h.html#a4e5f995d159279739909196d45ba09e5 . The doc doesn't say much as this would be extremely tedious. The doc is looking at the implementation for all (source, target) tuples that are implemented

theroggy commented 3 weeks ago

I had a look at the more specified functions that are probably used by ForceTo.

Indeed, for e.g. for ForceToPolygon: the doc mentions polygons will be changed to a collection of linestrings (one per ring). , but MultiPolygons are not mentioned at all... so implicitly it seems to be behaving according to the documentation...