Skip to content

Commit

Permalink
Work with newer python-mapnik
Browse files Browse the repository at this point in the history
  • Loading branch information
manthey committed Jun 18, 2024
1 parent 2ac5834 commit 740efb9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 7 additions & 4 deletions sources/mapnik/large_image_source_mapnik/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 740efb9

Please sign in to comment.