Skip to main content

Visualize Cloud Optimized GeoTIFF in browser

Project description

rio-viz

A Rasterio plugin to visualize Cloud Optimized GeoTIFF in browser.

Test Coverage Package version Downloads

Install

You can install rio-viz using pip

$ pip install rio-viz

with 3d feature

# 3d visualization features is optional
$ pip install -U pip
$ pip install rio-viz["mvt"]

Build from source

$ git clone https://github.com/developmentseed/rio-viz.git
$ cd rio-viz
$ pip install -e .

CLI

$ rio viz --help
Usage: rio viz [OPTIONS] SRC_PATH

  Rasterio Viz cli.

Options:
  --nodata NUMBER|nan  Set nodata masking values for input dataset.
  --minzoom INTEGER    Overwrite minzoom
  --maxzoom INTEGER    Overwrite maxzoom
  --port INTEGER       Webserver port (default: 8080)
  --host TEXT          Webserver host url (default: 127.0.0.1)
  --no-check           Ignore COG validation
  --reader TEXT        rio-tiler Reader (BaseReader). Default is `rio_tiler.io.COGReader`
  --layers TEXT        limit to specific layers (only used for MultiBand and MultiBase Readers). (e.g --layers b1 --layers b2).
  --server-only        Launch API without opening the rio-viz web-page.
  --config NAME=VALUE  GDAL configuration options.
  --help               Show this message and exit.

Multi Reader support

rio-viz support multiple/custom reader as long they are subclass of rio_tiler.io.base.BaseReader.

# Multi Files as Bands
$ rio viz "cog_band{2,3,4}.tif" --reader rio_viz.io.MultiFilesBandsReader

# Simple Mosaic
$ rio viz "tests/fixtures/mosaic_cog{1,2}.tif" --reader rio_viz.io.MosaicReader

# MultiBandReader
# Landsat 8 - rio-tiler-pds
# We use `--layers` to limit the number of bands
$ rio viz LC08_L1TP_013031_20130930_20170308_01_T1 \
  --reader rio_tiler_pds.landsat.aws.landsat8.L8Reader \
  --layers B1,B2 \
  --config GDAL_DISABLE_READDIR_ON_OPEN=FALSE \
  --config CPL_VSIL_CURL_ALLOWED_EXTENSIONS=".TIF,.ovr"

# MultiBaseReader
# We use `--layers` to limit the number of assets
rio viz https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a-cogs/items/S2A_34SGA_20200318_0_L2A \
  --reader rio_tiler.io.STACReader \
  --layers B04,B03,B02

RestAPI

When launching rio-viz, the application will create a FastAPI application to access and read the data you want. By default the CLI will open a web-page for you to explore your file but you can use --server-only option to ignore this.

$ rio viz my.tif --server-only

# In another console
$ curl http://127.0.0.1:8080/info | jq
{
  "bounds": [6.608576517072109, 51.270642883468895, 11.649386808679436, 53.89267160832534],
  "band_metadata": [...],
  "band_descriptions": [...],
  "dtype": "uint8",
  "nodata_type": "Mask",
  "colorinterp": [
    "red",
    "green",
    "blue"
  ]
}

You can see the full API documentation over http://127.0.0.1:8080/docs

API documentation

In Notebook environment

Thanks to the awesome server-thread we can use rio-viz application in Notebook environment.

import time

import httpx
from folium import Map, TileLayer

from rio_viz.app import Client

# Create rio-viz Client (using server-thread to launch backgroud task)
client = Client("https://data.geo.admin.ch/ch.swisstopo.swissalti3d/swissalti3d_2019_2573-1085/swissalti3d_2019_2573-1085_0.5_2056_5728.tif")

# Gives some time for the server to setup
time.sleep(1)

r = httpx.get(
    f"{client.endpoint}/tilejson.json",
    params = {
        "rescale": "1600,2000",  # from the info endpoint
        "colormap_name": "terrain",
    }
).json()

bounds = r["bounds"]
m = Map(
    location=((bounds[1] + bounds[3]) / 2,(bounds[0] + bounds[2]) / 2),
    zoom_start=r["minzoom"]
)

aod_layer = TileLayer(
    tiles=r["tiles"][0],
    opacity=1,
    attr="Yo!!"
)
aod_layer.add_to(m)
m

3D (Experimental)

rio-viz supports Mapbox VectorTiles encoding from a raster array. This feature was added to visualize sparse data stored as raster but will also work for dense array. This is highly experimental and might be slow to render in certain browser and/or for big rasters.

Docker

Ready to use docker image can be found on Github registry.

docker run \
  --volume "$PWD":/data \
  --platform linux/amd64 \
  --rm -it -p 8080:8080 ghcr.io/developmentseed/rio-viz:latest \
  rio viz --host 0.0.0.0 /data/your-file.tif

Notes:

  • --platform linux/amd64 is only needed if you are using latest MacOS M1 machines
  • --volume "$PWD":/data is needed to mount your local directory to the docker image
  • rio-viz's option --host 0.0.0.0 is required to access the web server

Contribution & Development

See CONTRIBUTING.md

Authors

Created by Development Seed

Changes

See CHANGES.md.

License

See LICENSE.txt

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rio_viz-0.12.2.tar.gz (38.7 kB view details)

Uploaded Source

Built Distribution

rio_viz-0.12.2-py3-none-any.whl (44.2 kB view details)

Uploaded Python 3

File details

Details for the file rio_viz-0.12.2.tar.gz.

File metadata

  • Download URL: rio_viz-0.12.2.tar.gz
  • Upload date:
  • Size: 38.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.0

File hashes

Hashes for rio_viz-0.12.2.tar.gz
Algorithm Hash digest
SHA256 b4355f3661fc7df105a83b32713f0f97f1122dc258d393cd3713eb21a6f9c983
MD5 b1e903b0abd77c5a52bf83cc9d09ea9a
BLAKE2b-256 a1f27a17a29dff3fa4adc9fa97653d59219aa774e1933533bf0a06d89569e969

See more details on using hashes here.

File details

Details for the file rio_viz-0.12.2-py3-none-any.whl.

File metadata

  • Download URL: rio_viz-0.12.2-py3-none-any.whl
  • Upload date:
  • Size: 44.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.0

File hashes

Hashes for rio_viz-0.12.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b68bbdce68a7806f6e8e083c2d4874e2160ee16f3e77e25983119f0376a749ab
MD5 c8cf3f770c8ae77ab38fc76dde1e71f7
BLAKE2b-256 6af12d0da9f9707a57ac0bbf7bc23e84054501fa1c3612e00ff12581ae9f1b4d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page