python-mapnik
python-mapnik copied to clipboard
RuntimeError: GDAL Plugin: 1191448000 is an invalid band, dataset only has 3bands
There are several problems when rendering an image:
- The image is not for the entire image size (the rest is transparent).
- Image is blurry
- If `<Parameter name =" band "> <! [CDATA [auto]]> </ Parameter> is set, then I periodically get an error like this:
ERROR 5: raster.tif: GDALDataset::GetRasterBand(1259353168) - Illegal band #
Traceback (most recent call last):
File "map.py", line 36, in <module>
mapnik.render(m, image)
RuntimeError: GDAL Plugin: 1259353168 is an invalid band, dataset only has 3bands
On version mapnik=3.0.13 and python-mapnik=3.0.x - all OK. Tested on Mac and Ubuntu.
- mapnik stable 3.0.20 (installed from brew)
- python-mapnik latest from 3.0.x
Code example:
import mapnik
PROJ = '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs'
style_xml = '<?xml version="1.0" encoding="utf-8"?> \
<!DOCTYPE Map[]> \
<Map srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs"> \
<Style name="raster" filter-mode="first"> \
<Rule> \
<RasterSymbolizer opacity="1" scaling="bilinear" /> \
</Rule> \
</Style> \
<Layer name="raster" \
srs="+proj=latlong +ellps=WGS84 +datum=WGS84 +no_defs"> \
<StyleName>raster</StyleName> \
<Datasource> \
<Parameter name="nodata"><![CDATA[0]]></Parameter> \
<Parameter name="file"><![CDATA[raster.tif]]></Parameter> \
<Parameter name="band"><![CDATA[auto]]></Parameter> \
<Parameter name="type"><![CDATA[gdal]]></Parameter> \
</Datasource> \
</Layer> \
</Map>'
m = mapnik.Map(256,256)
mapnik.load_map_from_string(m, style_xml.encode('utf-8'))
proj = mapnik.Projection(PROJ)
bbox = proj.forward(mapnik.Box2d(37.35145568847656, 55.68958466999194, 37.35179901123047, 55.68977819238148))
m.zoom_to_box(bbox)
image = mapnik.Image(m.width, m.height)
mapnik.render(m, image)
image.save('image.png')

After last update 3.0.20 i get this error. Ping @talaj @flippmoke
There is no such option as
<Parameter name="band">auto</Parameter>
The band parameter needs to be an integer - band number. It should give some sensible error however.
My only idea now is that some regression happened after the changes with overviews.
Can you offer the raster.tif file so I can reproduce it easily?
@talaj here archive with geotif and python script (138Mb) https://drive.google.com/open?id=1wF84PnNM8Tud6NvfCpY44eEkvU0_w_j3
UPD:
- when change to
<Parameter name="band">-1</Parameter>RuntimeError not show. - the image becomes blurry after 18 zoom levels

Thank you @winsento. I'm able to reproduce it now.
I've found and fixed the problem in https://github.com/mapycz/mapnik/commit/9a57592d7ba19686ea1a72d143fa675742a51d75. I haven't made a pull request to Mapnik yet as it needs some test coverage.
@winsento, can you build it with this patch yourself or should I try to merge it into Mapnik asap?
@talaj oh cool. I'll try to build and test.
@talaj it became better, but not completely fixed and rasters on small zoom became cloudy (before was sharp).

OK, I now noticed that the tiff is being reprojected "on the fly". I think I'm able to reproduce it:

Output seems fine when I reprojected the tiff to the Mercator by GDAL prior to rendering, including overviews:

@talaj yes the tiff reprojected "on the fly" from EPSG:4326 to EPSG:3857. If something else is needed you for the tests - let me know.
@winsento, I hopefully figured it out finally. Please, cherry-pick additional commits from https://github.com/mapycz/mapnik/commits/fix-overviews.
@talaj cool. I'm going to try now.
@talaj i confirm now everything is ok.
Great, I will try to merge it to Mapnik.
@talaj Excellent. when I'm will be in the Czech republic, pint's on me)
@winsento, fine, looking forward!
It would be also great reward if you can offer that tiff file as a test case for Mapnik. In much smaller resolution or a part of it.
@talaj maybe for not increase the amount of test data, to the existing geotiff (in test data) add overview via gdaladdo (http://www.gdal.org/gdaladdo.html)?
@winsento, you are right, that will be better.
GDALDataset::GetRasterBand(4) - Illegal band Nir = data.GetRasterBand(4).ReadAsArray().astype(np.float32) # near infrared AttributeError: 'NoneType' object has no attribute 'ReadAsArray'