Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the mapnik style defaults. #395

Merged
merged 1 commit into from
Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions sources/mapnik/large_image_source_mapnik/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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')
Expand Down
3 changes: 3 additions & 0 deletions test/test_source_mapnik.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down