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.55k forks source link

Change in GPKG driver CopyDataSource behavior in 3.10.0 #11282

Open davemfish opened 4 hours ago

davemfish commented 4 hours ago

What is the bug?

The following usage of the geopackage driver CopyDataSource worked in 3.9.3 but does not work in 3.10.0. I'm trying to copy a geopackage vector, but CreateCopy seems to always expect a raster dataset.

I looked at the 3.10.0 changelog but didn't see anything that would necessarily explain this change, so I thought it might be unexpected. Thanks for taking a look!

Steps to reproduce the issue

from osgeo import ogr

ogr.UseExceptions()

driver = ogr.GetDriverByName('GPKG')
vector = driver.CreateDataSource('foo.gpkg')
layer = vector.CreateLayer('foo', geom_type=ogr.wkbPoint)
feature = ogr.Feature(layer.GetLayerDefn())
geometry = ogr.CreateGeometryFromWkt('POINT (0 0)')
feature.SetGeometry(geometry)
layer.CreateFeature(feature)

source_vector = ogr.Open('foo.gpkg')
driver.CopyDataSource(source_vector, 'copy.gpkg')
<class 'osgeo.gdal.Dataset'>
Traceback (most recent call last):
  File "C:\Users\dmf\projects\repro\gdal_gpkg\gpgk_vector_copy.py", line 21, in <module>
    driver.CopyDataSource(source_vector, 'copy.gpkg')
  File "C:\Users\dmf\projects\invest\env-gdal310\Lib\site-packages\osgeo\gdal.py", line 3992, in CopyDataSource
    return self.CreateCopy(utf8_path, ds, options = options or [])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\dmf\projects\invest\env-gdal310\Lib\site-packages\osgeo\gdal.py", line 3892, in CreateCopy
    return _gdal.Driver_CreateCopy(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Only 1 (Grey/ColorTable), 2 (Grey+Alpha), 3 (RGB) or 4 (RGBA) band dataset supported

Versions and provenance

Windows 10 GDAL 3.10.0, released 2024/11/01 raises the error GDAL 3.9.3, released 2024/10/07 does not

Additional context

No response

rouault commented 3 hours ago

Fix in https://github.com/OSGeo/gdal/pull/11283 Easy workaround: gdal.VectorTranslate(out_filename, source_dataset) where source_dataset may be a string or a Dataset object.

davemfish commented 3 hours ago

Thank you! Great to know about VectorTranslate