From 740efb9a492cb9658b1e32d0c2aef3f06fd5fce2 Mon Sep 17 00:00:00 2001 From: David Manthey Date: Tue, 18 Jun 2024 08:26:46 -0400 Subject: [PATCH] Work with newer python-mapnik --- CHANGELOG.md | 8 ++++++++ sources/mapnik/large_image_source_mapnik/__init__.py | 11 +++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65f42bb89..073ae2481 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Change Log +## 1.29.1 + +### Improvements +- Improved zarr sink metadata handling ([#1508](../../pull/1508)) + +### Changes +- Work with newer python-mapnik ([#1550](../../pull/1550)) + ## 1.29.0 ### Features diff --git a/sources/mapnik/large_image_source_mapnik/__init__.py b/sources/mapnik/large_image_source_mapnik/__init__.py index 70d06db8b..e9661d051 100644 --- a/sources/mapnik/large_image_source_mapnik/__init__.py +++ b/sources/mapnik/large_image_source_mapnik/__init__.py @@ -273,7 +273,7 @@ def _addStyleToMap(self, m, layerSrs, colorizer=None, band=-1, extent=None, sym = mapnik.RasterSymbolizer() if colorizer is not None: sym.colorizer = colorizer - rule.symbols.append(sym) + getattr(rule, 'symbols', getattr(rule, 'symbolizers', None)).append(sym) style = mapnik.Style() style.rules.append(rule) if composite is not None: @@ -286,8 +286,9 @@ def _addStyleToMap(self, m, layerSrs, colorizer=None, band=-1, extent=None, if hasattr(self, '_netcdf') and isinstance(band, tuple): gdalband = band[1] gdalpath = self._netcdf['datasets'][band[0]]['name'] - lyr.datasource = mapnik.Gdal( - base=None, file=gdalpath, band=gdalband, extent=extent, nodata=nodata) + params = dict(base=None, file=gdalpath, band=gdalband, extent=extent, nodata=nodata) + params = {k: v for k, v in params.items() if v is not None} + lyr.datasource = mapnik.Gdal(**params) lyr.styles.append(styleName) m.layers.append(lyr) @@ -387,7 +388,9 @@ def getTile(self, x, y, z, **kwargs): m.zoom_to_box(mapnik.Box2d(xmin, ymin, xmax, ymax)) img = mapnik.Image(self.tileWidth + overscan * 2, self.tileHeight + overscan * 2) mapnik.render(m, img) - pilimg = PIL.Image.frombytes('RGBA', (img.width(), img.height()), img.tostring()) + pilimg = PIL.Image.frombytes( + 'RGBA', (img.width(), img.height()), + getattr(img, 'tostring', getattr(img, 'to_string', None))()) if overscan: pilimg = pilimg.crop((1, 1, pilimg.width - overscan, pilimg.height - overscan)) return self._outputTile(pilimg, TILE_FORMAT_PIL, x, y, z, applyStyle=False, **kwargs)