Skip to content

Commit

Permalink
Do not pass -projwin to gdal_translate when given rectangle is Null
Browse files Browse the repository at this point in the history
Update testcase accordingly
  • Loading branch information
strk committed Oct 8, 2023
1 parent 3f471a7 commit bcf83c1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
17 changes: 10 additions & 7 deletions python/plugins/processing/algs/gdal/ClipRasterByExtent.py
Expand Up @@ -130,13 +130,16 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, out)

arguments = [
'-projwin',
str(bbox.xMinimum()),
str(bbox.yMaximum()),
str(bbox.xMaximum()),
str(bbox.yMinimum()),
]
arguments = []

if not bbox.isNull():
arguments.extend([
'-projwin',
str(bbox.xMinimum()),
str(bbox.yMaximum()),
str(bbox.xMaximum()),
str(bbox.yMinimum()),
])

crs = inLayer.crs()
if override_crs and crs.isValid():
Expand Down
14 changes: 7 additions & 7 deletions python/plugins/processing/tests/GdalAlgorithmsRasterTest.py
Expand Up @@ -320,7 +320,7 @@ def testClipRasterByExtent(self):
'EXTENT': extent,
'OUTPUT': outdir + '/check.jpg'}, context, feedback),
['gdal_translate',
'-projwin 0.0 0.0 0.0 0.0 -of JPEG ' +
'-of JPEG ' +
source + ' ' +
outdir + '/check.jpg'])
# with NODATA value
Expand All @@ -330,7 +330,7 @@ def testClipRasterByExtent(self):
'NODATA': 9999,
'OUTPUT': outdir + '/check.jpg'}, context, feedback),
['gdal_translate',
'-projwin 0.0 0.0 0.0 0.0 -a_nodata 9999.0 -of JPEG ' +
'-a_nodata 9999.0 -of JPEG ' +
source + ' ' +
outdir + '/check.jpg'])
# with "0" NODATA value
Expand All @@ -340,7 +340,7 @@ def testClipRasterByExtent(self):
'NODATA': 0,
'OUTPUT': outdir + '/check.jpg'}, context, feedback),
['gdal_translate',
'-projwin 0.0 0.0 0.0 0.0 -a_nodata 0.0 -of JPEG ' +
'-a_nodata 0.0 -of JPEG ' +
source + ' ' +
outdir + '/check.jpg'])
# with "0" NODATA value and custom data type
Expand All @@ -351,7 +351,7 @@ def testClipRasterByExtent(self):
'DATA_TYPE': 6,
'OUTPUT': outdir + '/check.jpg'}, context, feedback),
['gdal_translate',
'-projwin 0.0 0.0 0.0 0.0 -a_nodata 0.0 -ot Float32 -of JPEG ' +
'-a_nodata 0.0 -ot Float32 -of JPEG ' +
source + ' ' +
outdir + '/check.jpg'])

Expand All @@ -363,7 +363,7 @@ def testClipRasterByExtent(self):
'DATA_TYPE': 0,
'OUTPUT': outdir + '/check.jpg'}, context, feedback),
['gdal_translate',
'-projwin 0.0 0.0 0.0 0.0 -of JPEG -co COMPRESS=DEFLATE -co PREDICTOR=2 -co ZLEVEL=9 ' +
'-of JPEG -co COMPRESS=DEFLATE -co PREDICTOR=2 -co ZLEVEL=9 ' +
source + ' ' +
outdir + '/check.jpg'])

Expand All @@ -375,7 +375,7 @@ def testClipRasterByExtent(self):
'DATA_TYPE': 0,
'OUTPUT': outdir + '/check.jpg'}, context, feedback),
['gdal_translate',
'-projwin 0.0 0.0 0.0 0.0 -of JPEG -s_srs EPSG:4326 -tps -tr 0.1 0.1 ' +
'-of JPEG -s_srs EPSG:4326 -tps -tr 0.1 0.1 ' +
source + ' ' +
outdir + '/check.jpg'])

Expand All @@ -386,7 +386,7 @@ def testClipRasterByExtent(self):
'OVERCRS': True,
'OUTPUT': outdir + '/check.jpg'}, context, feedback),
['gdal_translate',
'-projwin 0.0 0.0 0.0 0.0 -a_srs EPSG:4326 -of JPEG ' +
'-a_srs EPSG:4326 -of JPEG ' +
source + ' ' +
outdir + '/check.jpg'])

Expand Down

0 comments on commit bcf83c1

Please sign in to comment.