Skip to content

Commit

Permalink
Merge pull request OSGeo#8049 from rouault/fix_8023
Browse files Browse the repository at this point in the history
gdalwarp: make -cutline to work again with PostGIS datasources (fixes 3.7.0 regression, fixes OSGeo#8023)
  • Loading branch information
rouault authored Jul 4, 2023
2 parents f11a55b + d30e734 commit a590be4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion apps/gdalwarp_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3212,7 +3212,7 @@ static CPLErr LoadCutline(const std::string &osCutlineDSName,
/* Open source vector dataset. */
/* -------------------------------------------------------------------- */
auto poDS = std::unique_ptr<GDALDataset>(
GDALDataset::Open(osCutlineDSName.c_str()));
GDALDataset::Open(osCutlineDSName.c_str(), GDAL_OF_VECTOR));
if (poDS == nullptr)
{
CPLError(CE_Failure, CPLE_AppDefined, "Cannot open %s.",
Expand Down
42 changes: 42 additions & 0 deletions autotest/utilities/test_gdalwarp_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,48 @@ def test_gdalwarp_lib_21():
ds = None


###############################################################################
# Test cutline from PostGIS (mostly to check that we open the dataset in
# vector mode, and not in raster mode, which would cause the PostGISRaster
# driver to be used)


@pytest.mark.require_driver("PostgreSQL")
@pytest.mark.skipif(
gdal.GetConfigOption("OGR_PG_CONNECTION_STRING", None) is None,
reason="OGR_PG_CONNECTION_STRING not defined",
)
def test_gdalwarp_lib_cutline_postgis():

postgis_ds_name = "PG:" + gdal.GetConfigOption("OGR_PG_CONNECTION_STRING", None)
cutline_ds = ogr.Open(postgis_ds_name, update=1)
srs = osr.SpatialReference()
srs.ImportFromEPSG(26711)
cutline_lyr = cutline_ds.CreateLayer("cutline", srs=srs)
f = ogr.Feature(cutline_lyr.GetLayerDefn())
f.SetGeometry(
ogr.CreateGeometryFromWkt(
"POLYGON((400000 3000000,400000 4000000,500000 4000000,500000 3000000,400000 3000000))"
)
)
cutline_lyr.CreateFeature(f)
cutline_ds = None

try:
ds = gdal.Warp(
"",
"../gcore/data/byte.tif",
format="MEM",
cutlineDSName=postgis_ds_name,
cutlineSQL="SELECT * FROM cutline",
)
assert ds is not None
assert ds.GetRasterBand(1).Checksum() == 4672
finally:
cutline_ds = ogr.Open(postgis_ds_name, update=1)
cutline_ds.ExecuteSQL("DELLAYER:cutline")


###############################################################################
# Test cutline whose extent is larger than the source data

Expand Down

0 comments on commit a590be4

Please sign in to comment.