{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Mapboxgl Python Library for location data visualizaiton\n", "\n", "https://github.com/mapbox/mapboxgl-jupyter\n", "\n", "### Requirements\n", "\n", "These examples require the installation of the following python modules\n", "\n", "```\n", "pip install mapboxgl rio-glui==1.0.0\n", "```" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", "from rio_glui.server import TileServer\n", "from rio_glui.raster import RasterTiles\n", "\n", "from mapboxgl.utils import *\n", "from mapboxgl.viz import *" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "token = os.getenv('MAPBOX_ACCESS_TOKEN')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Create local tile server using `rio-glui`\n", "url = 'https://oin-hotosm.s3.amazonaws.com/5ac626e091b5310010e0d482/0/5ac626e091b5310010e0d483.tif'\n", "\n", "# Create raster tile object \n", "# More info: https://github.com/mapbox/rio-glui/blob/master/rio_glui/raster.py#L16-L44\n", "raster = RasterTiles(url, indexes=(2, 1, 3))\n", "\n", "# Create local tile server\n", "# More info: https://github.com/mapbox/rio-glui/blob/master/rio_glui/server.py#L21-L56\n", "ts = TileServer(raster)\n", "\n", "# Start tile server \n", "ts.start()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": false }, "outputs": [], "source": [ "# Initialize RasterTiles Viz by passing our local tile server url `ts.get_tiles_url` \n", "viz = RasterTilesViz(ts.get_tiles_url(), \n", " tiles_bounds=ts.get_bounds(),\n", " center=ts.get_center(),\n", " access_token=token, \n", " height='1000px', \n", " zoom=13)\n", "viz.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# We need to stop the previous server in order to create a new one\n", "ts.stop()\n", "\n", "raster = RasterTiles(url, indexes=(1,2,3))\n", "ts = TileServer(raster)\n", "ts.start()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "viz = RasterTilesViz(ts.get_tiles_url(), \n", " tiles_bounds=ts.get_bounds(),\n", " center=ts.get_center(),\n", " access_token=token, \n", " height='1000px', \n", " zoom=13)\n", "viz.show()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.1" } }, "nbformat": 4, "nbformat_minor": 2 }