From 190d3ff2c4dfd95b173ed5de59716b104b1e74bf Mon Sep 17 00:00:00 2001 From: David Manthey Date: Wed, 13 Nov 2019 16:07:31 -0500 Subject: [PATCH] Change the mapnik style defaults. When a band is specified without a scheme or a palette, use linear and greyscale. Closes #376. --- .../mapnik/large_image_source_mapnik/__init__.py | 15 +++++++-------- test/test_source_mapnik.py | 3 +++ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/sources/mapnik/large_image_source_mapnik/__init__.py b/sources/mapnik/large_image_source_mapnik/__init__.py index bed18d3cf..15a23a303 100644 --- a/sources/mapnik/large_image_source_mapnik/__init__.py +++ b/sources/mapnik/large_image_source_mapnik/__init__.py @@ -122,9 +122,7 @@ def __init__(self, path, projection=None, style=None, unitsPerPixel=None, **kwar the reported minimum or maximum. scheme: one of the mapnik.COLORIZER_xxx values. Case insensitive. Possible values are at least 'discrete', - 'linear', and 'exact'. If palette is unspecified and the - band was specified as a string, this defaults to 'linear'. - Otherwise it defaults to 'discrete'. + 'linear', and 'exact'. This defaults to 'linear'. palette: either a list of two or more color strings, a string with a dotted class name from the python palettable package, or 'colortable' to use the band's color table @@ -133,8 +131,8 @@ def __init__(self, path, projection=None, style=None, unitsPerPixel=None, **kwar unspecified and the band is one of 'red', 'green', 'blue', gray', or 'alpha', this defaults to an appropriate band pair. Otherwise, this defaults to the band's color table - (palette) if it has one and 'cmocean.diverging.Curl_10' if - it does not. + (palette) if it has one and a black-to-white palette if it + does not. nodata: the value to use for missing data. 'auto' to use the band reported value, if any. null or unset to not use a nodata value. @@ -613,7 +611,7 @@ def _colorizerFromStyle(self, style): :returns: a mapnik raster colorizer. """ try: - scheme = style.get('scheme', 'discrete') + scheme = style.get('scheme', 'linear') mapnik_scheme = getattr(mapnik, 'COLORIZER_{}'.format(scheme.upper())) except AttributeError: mapnik_scheme = mapnik.COLORIZER_DISCRETE @@ -638,7 +636,7 @@ def _colorizerFromStyle(self, style): for value, color in enumerate(bandInfo['colortable']): colorizer.add_stop(value, mapnik.Color(*color)) else: - colors = style.get('palette', 'cmocean.diverging.Curl_10') + colors = style.get('palette', ['#000000', '#ffffff']) if not isinstance(colors, list): colors = self.getHexColors(colors) else: @@ -792,7 +790,8 @@ def addStyle(self, m, layerSrs, extent=None): for styleBand in style: if styleBand['band'] != -1: colorizer = self._colorizerFromStyle(styleBand) - composite = getattr(mapnik.CompositeOp, styleBand.get('composite', 'lighten')) + composite = getattr(mapnik.CompositeOp, styleBand.get( + 'composite', 'multiply' if styleBand['band'] == 'alpha' else 'lighten')) nodata = styleBand.get('nodata') if nodata == 'auto': nodata = bands.get('nodata') diff --git a/test/test_source_mapnik.py b/test/test_source_mapnik.py index 846466163..16fd268ef 100644 --- a/test/test_source_mapnik.py +++ b/test/test_source_mapnik.py @@ -95,6 +95,7 @@ def testTileStyleFromGeotiffs(): testDir = os.path.dirname(os.path.realpath(__file__)) imagePath = os.path.join(testDir, 'test_files', 'rgb_geotiff.tiff') style = json.dumps({'band': 1, 'min': 0, 'max': 100, + 'scheme': 'discrete', 'palette': 'matplotlib.Plasma_6'}) source = large_image_source_mapnik.MapnikFileTileSource( imagePath, projection='EPSG:3857', style=style) @@ -207,6 +208,7 @@ def testPixel(): # Test with styles style = json.dumps({'band': 1, 'min': 0, 'max': 100, + 'scheme': 'discrete', 'palette': 'matplotlib.Plasma_6'}) source = large_image_source_mapnik.MapnikFileTileSource( imagePath, projection='EPSG:3857', style=style) @@ -216,6 +218,7 @@ def testPixel(): # Test with palette as an array of colors style = json.dumps({'band': 1, 'min': 0, 'max': 100, + 'scheme': 'discrete', 'palette': ['#0000ff', '#00ff00', '#ff0000']}) source = large_image_source_mapnik.MapnikFileTileSource( imagePath, projection='EPSG:3857', style=style)