Skip to content

Commit

Permalink
add notebook example with rio-glui tiles serving (#112)
Browse files Browse the repository at this point in the history
* add notebook example with rio-glui tile serving

* bring your own raster example
  • Loading branch information
vincentsarago authored and ryanbaumann committed Aug 8, 2018
1 parent e38f35e commit 437078d
Show file tree
Hide file tree
Showing 2 changed files with 617 additions and 3 deletions.
40 changes: 37 additions & 3 deletions docs/viz.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ from mapboxgl.utils import *
token = os.getenv('MAPBOX_ACCESS_TOKEN')

# Create Choropleth with GeoJSON Source
viz = ChoroplethViz('us-states.geojson',
viz = ChoroplethViz('us-states.geojson',
color_property='density',
color_stops=create_color_stops([0, 50, 100, 500, 1500], colors='YlOrRd'),
color_function_type='interpolate',
Expand Down Expand Up @@ -480,6 +480,41 @@ viz.show()
[Complete example](https://github.com/mapbox/mapboxgl-jupyter/blob/master/examples/rastertile-viz-types-example.ipynb)


#### Bring your own raster
Using [`rio-glui`](https://github.com/mapbox/rio-glui) python module, you can create a local tiles server to explore your own file.

Note: Your raster file has to be a cloud optimized geotiff (see [cogeo.org](http://www.cogeo.org) or [rio-cogeo](https://github.com/mapbox/rio-cogeo)).

```python

from rio_glui.server import TileServer
from rio_glui.raster import RasterTiles
from mapboxgl.viz import RasterTilesViz

file = 'myfile.tif'

# Create raster tile object
# More info: https://github.com/mapbox/rio-glui/blob/master/rio_glui/raster.py#L16-L44
raster = RasterTiles(file, indexes=(2,1,3))

# Create local tile server
# More info: https://github.com/mapbox/rio-glui/blob/master/rio_glui/server.py#L21-L56
ts = TileServer(raster)

# Start tile server
ts.start()

# Initialize RasterTiles Viz by passing our local tile server url `ts.get_tiles_url`
viz = RasterTilesViz(ts.get_tiles_url(),
tiles_bounds=ts.get_bounds(),
center=ts.get_center(),
height='1000px',
zoom=13)
viz.show()
```



## class LinestringViz

The `LinestringViz` object handles the creation of a vector or GeoJSON-based Linestring visualization and inherits from the `MapViz` class.
Expand Down Expand Up @@ -526,7 +561,7 @@ token = os.getenv('MAPBOX_ACCESS_TOKEN')
# JSON join-data object
data = [{"elevation": x, "weight": random.randint(0,100)} for x in range(0, 21000, 10)]

viz = LinestringViz(data,
viz = LinestringViz(data,
vector_url='mapbox://mapbox.mapbox-terrain-v2',
vector_layer_name='contour',
vector_join_property='ele',
Expand All @@ -547,4 +582,3 @@ viz.show()


[Complete example](https://github.com/mapbox/mapboxgl-jupyter/blob/master/examples/notebooks/linestring-viz.ipynb)

Loading

0 comments on commit 437078d

Please sign in to comment.