contextily icon indicating copy to clipboard operation
contextily copied to clipboard

Interface with `rio-tiler`

Open darribas opened this issue 5 years ago • 3 comments

It'd be really cool if we could build a bridge to rio-tiler. This would allow to use data on COGs directly as contextual basemaps.

If I read it correctly, they support direct tiling from a file on the web:

from rio_tiler.io import cogeo

tile, mask = cogeo.tile(
  'http://oin-hotosm.s3.amazonaws.com/5a95f32c2553e6000ce5ad2e/0/10edab38-1bdd-4c06-b83d-6e10ac532b7d.tif',
  691559,
  956905,
  21,
  tilesize=256
)
print(tile.shape)
> (3, 256, 256)

print(mask.shape)
> (256, 256)

So it'd be up to contextily to wire this in with our machinery to pull tiles from an extent:

    # download and merge tiles
    tiles = []
    arrays = []
    for t in mt.tiles(w, s, e, n, [zoom]):
        x, y, z = t.x, t.y, t.z
        tile_url = _construct_tile_url(provider, x, y, z)
        image = _fetch_tile(tile_url, wait, max_retries)
        tiles.append(t)
        arrays.append(image)

I don't think this would be too onerous. Would it be worth the effort/interest in having this "exist"? Looping @jorisvandenbossche, @martinfleis and @vincentsarago on this as their view will surely be better informed than mine. Do you think this is worth the time implementing?

darribas avatar Jun 10 '20 16:06 darribas

It sounds interesting. How do you envisage to work with different bands? Get a single band only? Or provide a method of generating RGB (where applicable, i.e. Landsat)?

Supporting a single band does not seem to be overly complicated, but it can get complex quite quickly with multiple bands to deal with.

martinfleis avatar Jun 10 '20 20:06 martinfleis

Yes, that's a good point. One solution could be start only by taking either "true-color" files or 1-band only. One of the use cases I was thinking might be interesting is if population datasets (e.g. WorldPop, GHSL, etc.) begin adopting the COG standard, it might be useful to be able to use them directly as a XYZ-type of basemap?

More generally, do people see this could be of value in some use cases?

darribas avatar Jun 11 '20 16:06 darribas

Having worked for a few months on the rio-tiler ecosystem and tools to create a basemap on the fly, I'd say it's a bit more complex than you're suggesting.

In your first comment you mention the example used in the rio-tiler README, but that only works because you know that mercator tile overlaps with that image. That's not something you can say arbitrarily because a satellite will take images of small areas at a time.

MosaicJSON is an extension to combine lots of source files in a seamless map, but then you need to pregenerate that json file that describes where to join each source file.

I haven't used contextily before, but I'm guessing you want basemaps that "just work", and I don't think you'll easily get that using rio-tiler et al.

P.S. I also wrote an intro COG blog post about this

kylebarron avatar Jun 11 '20 17:06 kylebarron