Skip to content

Commit

Permalink
Merge pull request #11513 from rouault/GDALRasterizeLayers
Browse files Browse the repository at this point in the history
GDALRasterizeLayers(): do not emit warning about missing SRS if the target raster dataset has no SRS
  • Loading branch information
rouault authored Dec 19, 2024
2 parents 77cfe37 + 5ff3f2f commit e7b6c09
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
16 changes: 11 additions & 5 deletions alg/gdalrasterize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1645,11 +1645,17 @@ CPLErr GDALRasterizeLayers(GDALDatasetH hDS, int nBandCount, int *panBandList,
OGRSpatialReference *poSRS = poLayer->GetSpatialRef();
if (!poSRS)
{
CPLError(CE_Warning, CPLE_AppDefined,
"Failed to fetch spatial reference on layer %s "
"to build transformer, assuming matching coordinate "
"systems.",
poLayer->GetLayerDefn()->GetName());
if (poDS->GetSpatialRef() != nullptr ||
poDS->GetGCPSpatialRef() != nullptr ||
poDS->GetMetadata("RPC") != nullptr)
{
CPLError(
CE_Warning, CPLE_AppDefined,
"Failed to fetch spatial reference on layer %s "
"to build transformer, assuming matching coordinate "
"systems.",
poLayer->GetLayerDefn()->GetName());
}
}
else
{
Expand Down
13 changes: 7 additions & 6 deletions autotest/alg/rasterize.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ def test_rasterize_2():
burn_values=[200, 220, 240],
options=["ALL_TOUCHED=TRUE"],
)
assert (
"Failed to fetch spatial reference on layer cutline to build transformer, assuming matching coordinate systems"
in gdal.GetLastErrorMsg()
)

assert err == 0, "got non-zero result code from RasterizeLayer"

Expand All @@ -130,20 +134,15 @@ def test_rasterize_2():

def test_rasterize_3():

# Setup working spatial reference
sr_wkt = 'LOCAL_CS["arbitrary"]'
sr = osr.SpatialReference(sr_wkt)

# Create a memory raster to rasterize into.

target_ds = gdal.GetDriverByName("MEM").Create("", 100, 100, 3, gdal.GDT_Byte)
target_ds.SetGeoTransform((1000, 1, 0, 1100, 0, -1))
target_ds.SetProjection(sr_wkt)

# Create a memory layer to rasterize from.

rast_ogr_ds = ogr.GetDriverByName("Memory").CreateDataSource("wrk")
rast_mem_lyr = rast_ogr_ds.CreateLayer("poly", srs=sr)
rast_mem_lyr = rast_ogr_ds.CreateLayer("poly")

# Add polygons and linestrings.
wkt_geom = [
Expand All @@ -160,13 +159,15 @@ def test_rasterize_3():

# Run the algorithm.

gdal.ErrorReset()
err = gdal.RasterizeLayer(
target_ds,
[3, 2, 1],
rast_mem_lyr,
burn_values=[10, 10, 55],
options=["BURN_VALUE_FROM=Z"],
)
assert gdal.GetLastErrorMsg() == ""

assert err == 0, "got non-zero result code from RasterizeLayer"

Expand Down

0 comments on commit e7b6c09

Please sign in to comment.