Skip to content

Commit

Permalink
Merge pull request #11283 from rouault/fix_11282
Browse files Browse the repository at this point in the history
GPKG: make CreateCopy() work on vector datasets
  • Loading branch information
rouault authored Nov 20, 2024
2 parents a00fbc1 + 759ddc8 commit 3cabd19
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
15 changes: 15 additions & 0 deletions autotest/ogr/ogr_gpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -10625,6 +10625,21 @@ def test_ogr_gpkg_ST_Length_on_ellipsoid(tmp_vsimem):
assert f[0] is None


###############################################################################
# Test that CreateCopy() works on a vector dataset
# Test fix for https://github.com/OSGeo/gdal/issues/11282


@gdaltest.enable_exceptions()
@pytest.mark.usefixtures("tpoly")
def test_ogr_gpkg_CreateCopy(gpkg_ds, tmp_vsimem):

tmpfilename = tmp_vsimem / "test_ogr_gpkg_CreateCopy.gpkg"

out_ds = gdal.GetDriverByName("GPKG").CreateCopy(tmpfilename, gpkg_ds)
assert out_ds.GetLayerCount() == 1


###############################################################################
# Test LAUNDER=YES layer creation option

Expand Down
18 changes: 16 additions & 2 deletions ogr/ogrsf_frmts/gpkg/ogrgeopackagedatasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6005,6 +6005,21 @@ GDALDataset *GDALGeoPackageDataset::CreateCopy(const char *pszFilename,
GDALProgressFunc pfnProgress,
void *pProgressData)
{
const int nBands = poSrcDS->GetRasterCount();
if (nBands == 0)
{
GDALDataset *poDS = nullptr;
GDALDriver *poThisDriver =
GDALDriver::FromHandle(GDALGetDriverByName("GPKG"));
if (poThisDriver != nullptr)
{
poDS = poThisDriver->DefaultCreateCopy(pszFilename, poSrcDS,
bStrict, papszOptions,
pfnProgress, pProgressData);
}
return poDS;
}

const char *pszTilingScheme =
CSLFetchNameValueDef(papszOptions, "TILING_SCHEME", "CUSTOM");

Expand All @@ -6018,7 +6033,6 @@ GDALDataset *GDALGeoPackageDataset::CreateCopy(const char *pszFilename,
apszUpdatedOptions.SetNameValue("RASTER_TABLE", osBasename);
}

const int nBands = poSrcDS->GetRasterCount();
if (nBands != 1 && nBands != 2 && nBands != 3 && nBands != 4)
{
CPLError(CE_Failure, CPLE_NotSupported,
Expand All @@ -6045,7 +6059,7 @@ GDALDataset *GDALGeoPackageDataset::CreateCopy(const char *pszFilename,

GDALGeoPackageDataset *poDS = nullptr;
GDALDriver *poThisDriver =
reinterpret_cast<GDALDriver *>(GDALGetDriverByName("GPKG"));
GDALDriver::FromHandle(GDALGetDriverByName("GPKG"));
if (poThisDriver != nullptr)
{
apszUpdatedOptions.SetNameValue("SKIP_HOLES", "YES");
Expand Down

0 comments on commit 3cabd19

Please sign in to comment.