Giter Site home page Giter Site logo

Comments (4)

vincentsarago avatar vincentsarago commented on May 21, 2024

👋 Hi @kriscarle, thanks for opening this issue.

So to keep everything as simple as possible we could:

  • add an option in array_to_img to apply a palette to a 1 band image (example).
  • add a utils.get_palette function that accept either a rasterio dataset (as in geop) or a color_palette name (local palettes shipped within rio-tiler)

btw, there are some work to do to fully support one band output image (e.g. add mask) : https://github.com/mapbox/rio-tiler/blob/f33930f4da0493c6941e5c3e617364eb9caca86a/rio_tiler/utils.py#L354-L355

from rio-tiler.

kriscarle avatar kriscarle commented on May 21, 2024

Hi @vincentsarago I was able to get it working like this, using rasterio's built in support for writing colormaps and MemoryFile. The PIL palette doesn't support RGBA values, plus I think this example can easily be adapted to support multiple bands.

import rasterio
from rio_tiler import aws
from rasterio.io import MemoryFile

def tile(event, context):
    args = event['pathParameters']
    x = int(args['x'])
    y = int(args['y'])
    z = int(args['z'])

    bucket = 'my-bucket'
    key = 'data.vrt'
    tile = aws.tile(bucket, key, x, y, z, 1, 256)
    with rasterio.open('s3://{}/{}'.format(bucket, key)) as src:
      colormap = src.colormap(1)
      meta = src.meta
      meta['driver'] = 'PNG'
      meta['height'] = 256
      meta['width'] = 256
  
      with MemoryFile() as memfile:
        with memfile.open(**meta) as dataset:
          dataset.write(tile, indexes=1)
          dataset.write_colormap(1, colormap)
        memfile.seek(0)
        return memfile.read()

from rio-tiler.

vincentsarago avatar vincentsarago commented on May 21, 2024

@kriscarle I'm not sure to follow 100%
I made this notebook to try to explain my though.

Basically your example does not imply any change in rio_tiler but it's more on the lambda handler side. What I think will be good is to add this in the documentation.

plus I think this example can easily be adapted to support multiple bands.

I'm not sure to understand the concept of applying color palette to multiple bands. I'll be interested to see any use case for that.

from rio-tiler.

kriscarle avatar kriscarle commented on May 21, 2024

@vincentsarago

Yes, I ended up not needing to change rio-tiler, so it could just work as an example. Though it could still be a nice feature to automatically apply the color map from a VRT band if it is provided in the VRT.

I'm not entirely sure what I meant by multiple bands either. I think I meant that you can create tiles for multiple bands and then combine them in some way. Maybe for calculating NVDI on the fly?

from rio-tiler.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.