Skip to content
Permalink
Browse files

Merge pull request #1817 from mwtoews/resample

gdal2tiles.py: add remaining resample methods
  • Loading branch information...
rouault committed Sep 8, 2019
2 parents 6c20fa9 + 70a7dbc commit 9db5b21d022454af61a1fb3b570af639cc9e5038
@@ -103,6 +103,43 @@ def test_gdal2tiles_py_zoom_option():
assert ds is not None, 'did not get kml'


def test_gdal2tiles_py_resampling_option():

script_path = test_py_scripts.get_py_script('gdal2tiles')
if script_path is None:
pytest.skip()

resampling_list = [
'average', 'near', 'bilinear', 'cubic', 'cubicspline', 'lanczos',
'antialias', 'mode', 'max', 'min', 'med', 'q1', 'q3']
try:
from PIL import Image
import numpy
import osgeo.gdal_array as gdalarray
del Image, numpy, gdalarray
except ImportError:
# 'antialias' resampling is not available
resampling_list.remove('antialias')

out_dir = 'tmp/out_gdal2tiles_smallworld'

for resample in resampling_list:

shutil.rmtree(out_dir, ignore_errors=True)

test_py_scripts.run_py_script_as_external_script(
script_path,
'gdal2tiles',
'-q --resampling={0} {1} {2}'.format(
resample, '../gdrivers/data/small_world.tif', out_dir))

# very basic check
ds = gdal.Open('tmp/out_gdal2tiles_smallworld/0/0/0.png')
if ds is None:
pytest.fail('resample option {0!r} failed'.format(resample))
ds = None


def test_does_not_error_when_source_bounds_close_to_tiles_bound():
"""
Case where the border coordinate of the input file is inside a tile T but the first pixel is
@@ -42,11 +42,11 @@ can publish a picture without proper georeferencing too.

.. option:: -p <PROFILE>, --profile=<PROFILE>

Tile cutting profile (mercator,geodetic,raster) - default 'mercator' (Google Maps compatible).
Tile cutting profile (mercator, geodetic, raster) - default 'mercator' (Google Maps compatible).

.. option:: -r <RESAMPLING>, --resampling=<RESAMPLING>

Resampling method (average,near,bilinear,cubic,cubicspline,lanczos,antialias) - default 'average'.
Resampling method (average, near, bilinear, cubic, cubicspline, lanczos, antialias, mode, max, min, med, q1, q3) - default 'average'.

.. option:: -s <SRS>, --s_srs=<SRS>

@@ -114,7 +114,7 @@ Options for generated HTML viewers a la Google Maps

.. option:: -w <WEBVIEWER>, --webviewer=<WEBVIEWER>

Web viewer to generate (all,google,openlayers,leaflet,none) - default 'all'.
Web viewer to generate (all, google, openlayers, leaflet, none) - default 'all'.

.. option:: -t <TITLE>, --title=<TITLE>

@@ -64,7 +64,9 @@

__version__ = "$Id$"

resampling_list = ('average', 'near', 'bilinear', 'cubic', 'cubicspline', 'lanczos', 'antialias')
resampling_list = (
'average', 'near', 'bilinear', 'cubic', 'cubicspline', 'lanczos',
'antialias', 'mode', 'max', 'min', 'med', 'q1', 'q3')
profile_list = ('mercator', 'geodetic', 'raster')
webviewer_list = ('all', 'google', 'openlayers', 'leaflet', 'none')

@@ -645,6 +647,24 @@ def scale_query_to_tile(dsquery, dstile, tiledriver, options, tilefilename=''):
elif options.resampling == 'lanczos':
gdal_resampling = gdal.GRA_Lanczos

elif options.resampling == 'mode':
gdal_resampling = gdal.GRA_Mode

elif options.resampling == 'max':
gdal_resampling = gdal.GRA_Max

elif options.resampling == 'min':
gdal_resampling = gdal.GRA_Min

elif options.resampling == 'med':
gdal_resampling = gdal.GRA_Med

elif options.resampling == 'q1':
gdal_resampling = gdal.GRA_Q1

elif options.resampling == 'q3':
gdal_resampling = gdal.GRA_Q3

# Other algorithms are implemented by gdal.ReprojectImage().
dsquery.SetGeoTransform((0.0, tile_size / float(querysize), 0.0, 0.0, 0.0,
tile_size / float(querysize)))

0 comments on commit 9db5b21

Please sign in to comment.
You can’t perform that action at this time.