diff --git a/apps/test_ogrsf.cpp b/apps/test_ogrsf.cpp index 777964088bfd..5983650038fe 100644 --- a/apps/test_ogrsf.cpp +++ b/apps/test_ogrsf.cpp @@ -4436,6 +4436,25 @@ static int TestOGRLayer(GDALDataset *poDS, OGRLayer *poLayer, int bIsSQLLayer) /* -------------------------------------------------------------------- */ if (LOG_ACTION(poLayer->TestCapability(OLCRandomWrite))) { + if (!poDS->GetDriver()->GetMetadataItem(GDAL_DCAP_UPDATE)) + { + printf("ERROR: Driver %s does not declare GDAL_DCAP_UPDATE\n", + poDS->GetDriver()->GetDescription()); + bRet = false; + } + else + { + const char *pszItems = + poDS->GetDriver()->GetMetadataItem(GDAL_DMD_UPDATE_ITEMS); + if (!pszItems || !strstr(pszItems, "Features")) + { + printf("ERROR: Driver %s does not declare Features in " + "GDAL_DMD_UPDATE_ITEMS\n", + poDS->GetDriver()->GetDescription()); + bRet = false; + } + } + bRet &= TestOGRLayerRandomWrite(poLayer); } diff --git a/autotest/gcore/misc.py b/autotest/gcore/misc.py index 54fd91bfde6e..1a562b2a71f8 100755 --- a/autotest/gcore/misc.py +++ b/autotest/gcore/misc.py @@ -19,7 +19,7 @@ import gdaltest import pytest -from osgeo import gdal +from osgeo import gdal, osr ############################################################################### @@ -118,6 +118,8 @@ def get_filename(drv, dirname): filename += ".kmz" elif drv.ShortName == "RRASTER": filename += ".grd" + elif drv.ShortName == "KEA": + filename += ".kea" return filename @@ -314,6 +316,55 @@ def misc_6_internal(datatype, nBands, setDriversDone): dst_ds.GetMetadataItem("", None) dst_ds = None + if ( + has_succeeded + and nBands > 0 + and "DCAP_UPDATE" in md + and drv.ShortName not in ("VRT",) + ): + ds = gdal.Open(filename, gdal.GA_Update) + assert ds, (drv.ShortName, filename) + + flags_str = drv.GetMetadataItem(gdal.DMD_UPDATE_ITEMS) + if ds.RasterCount and "RasterValues" in flags_str: + assert ( + ds.GetRasterBand(1).WriteRaster( + 0, 0, 1, 1, b"\x00", buf_type=gdal.GDT_Byte + ) + == gdal.CE_None + ), (drv.ShortName, filename) + + if "GeoTransform" in flags_str and drv.ShortName not in ("netCDF",): + assert ds.SetGeoTransform([0, 1, 0, 0, 0, -1]) == gdal.CE_None, ( + drv.ShortName, + filename, + ) + + if "SRS" in flags_str and drv.ShortName not in ("netCDF",): + srs = osr.SpatialReference() + srs.SetFromUserInput("WGS84") + assert ds.SetSpatialRef(srs) == gdal.CE_None, ( + drv.ShortName, + filename, + ) + + if ds.RasterCount and "NoData" in flags_str: + assert ds.GetRasterBand(1).SetNoDataValue(0) == gdal.CE_None, ( + drv.ShortName, + filename, + ) + + if "DatasetMetadata" in flags_str: + assert ds.SetMetadata({"FOO": "BAR"}) == gdal.CE_None, ( + drv.ShortName, + filename, + ) + + if ds.RasterCount and "BandMetadata" in flags_str: + assert ( + ds.GetRasterBand(1).SetMetadata({"FOO": "BAR"}) == gdal.CE_None + ), (drv.ShortName, filename) + size = 0 stat = gdal.VSIStatL(filename) if stat is not None: @@ -400,6 +451,7 @@ def misc_6_internal(datatype, nBands, setDriversDone): "USGSDEM", "KMLSUPEROVERLAY", "GMT", + "NULL", ]: dst_ds = drv.CreateCopy( filename, ds, callback=misc_6_interrupt_callback_class().cbk @@ -440,6 +492,7 @@ def misc_6_internal(datatype, nBands, setDriversDone): ) ) pytest.fail(reason) + ds = None diff --git a/autotest/gcore/test_driver_metadata.py b/autotest/gcore/test_driver_metadata.py index b8907c47e938..0d106228eb27 100644 --- a/autotest/gcore/test_driver_metadata.py +++ b/autotest/gcore/test_driver_metadata.py @@ -643,3 +643,30 @@ def test_metadata_creation_field_defn_flags(driver_name): if flags_str is not None: for flag in flags_str.split(" "): assert flag in supported_flags + + +@pytest.mark.parametrize("driver_name", ogr_driver_names) +def test_metadata_update_items(driver_name): + """Test if DMD_UPDATE_ITEMS metadataitem returns valid flags""" + + supported_flags = { + "GeoTransform", + "SRS", + "GCPs", + "NoData", + "ColorInterpretation", + "RasterValues", + "DatasetMetadata", + "BandMetadata", + "Features", + "LayerMetadata", + } + + driver = gdal.GetDriverByName(driver_name) + flags_str = driver.GetMetadataItem(gdal.DMD_UPDATE_ITEMS) + if flags_str is not None: + assert driver.GetMetadataItem(gdal.DCAP_UPDATE) + for flag in flags_str.split(" "): + assert flag in supported_flags + else: + assert not driver.GetMetadataItem(gdal.DCAP_UPDATE)