mapbox / rio-mbtiles

A plugin command for the Rasterio CLI that exports a raster dataset to an MBTiles 1.1 SQLite file
MIT License
125 stars 36 forks source link

Error when source has alpha band #26

Closed andrewharvey closed 5 years ago

andrewharvey commented 7 years ago

When I run the following:

rio --verbose mbtiles --force-overwrite --title ''  --description '' --overlay --format PNG --zoom-levels 1..20 -j 4 --src-nodata 0 raster.tif output.mbtiles

where raster.tif has an Alpha band

For example using NE2_50M_SR and running:

gdalwarp -of GTiff -dstalpha NE2_50M_SR/NE2_50M_SR.tif raster.tif

creating a 4th alpha band:

Band 1 Block=10800x1 Type=Byte, ColorInterp=Red
  Mask Flags: PER_DATASET ALPHA 
Band 2 Block=10800x1 Type=Byte, ColorInterp=Green
  Mask Flags: PER_DATASET ALPHA 
Band 3 Block=10800x1 Type=Byte, ColorInterp=Blue
  Mask Flags: PER_DATASET ALPHA 
Band 4 Block=10800x1 Type=Byte, ColorInterp=Alpha

rio produces the output:

Traceback (most recent call last):
  File "/usr/local/bin/rio", line 11, in <module>
    sys.exit(main_group())
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/mbtiles/scripts/cli.py", line 187, in mbtiles
    for tile, contents in pool.imap_unordered(process_tile, tiles):
  File "/usr/lib/python2.7/multiprocessing/pool.py", line 668, in next
    raise value
IndexError: tuple index out of range
sgillies commented 7 years ago

@andrewharvey I found a couple blockers for this in Rasterio: https://github.com/mapbox/rasterio/issues/984 https://github.com/mapbox/rasterio/issues/985. I'll update here when those are fixed. Will require a Rasterio upgrade.

qxang commented 7 years ago

@andrewharvey Do you fix the problems? and how?

andrewharvey commented 7 years ago

@andrewharvey Do you fix the problems? and how?

@shanyuk nope. Alternatives are https://github.com/mapbox/mapbox-tile-copy and then download tiles from S3 and use https://github.com/mapbox/mbutil to pack them into an MBTiles (which I think should give you the same result as uploading your GeoTIFF as is to Mapbox), or just upload directly to Mapbox.

qxang commented 7 years ago

Thank you. I will have a try.

qxang commented 7 years ago

@andrewharvey https://github.com/ecometrica/gdal2mbtiles

sgillies commented 7 years ago

Kicking this to a future milestone. 1.4.0 is coming sooner than I can make the rasterio fix.

sgillies commented 5 years ago

New milestone: 1.4.2 cc @jacquestardie

sgillies commented 5 years ago

Resolved and will be available in 1.4.2 (on PyPI later today). New usage is explained in the README and rio mbtiles --help.