### run_app(filename, port=0, debug=False, browser=True, cesium_token='', host='127.0.0.1', cors_all=False, run=True) Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/api/utilities.rst Serves tiles from a raster file or a built-in example dataset. Optionally starts a uvicorn server and opens a browser pointing to the viewer. ```APIDOC ## run_app(filename, port: int = 0, debug: bool = False, browser: bool = True, cesium_token: str = '', host: str = '127.0.0.1', cors_all: bool = False, run: bool = True) ### Description Serves tiles from the raster at `filename`. You can also pass the name of one of the example datasets: `elevation`, `blue_marble`, `virtual_earth`, `arcgis` or `bahamas`. ### Parameters - **filename** (*str* or *pathlib.Path*) – Path to a raster file or the name of a built-in example dataset. - **port** (*int*, optional) – Port to bind the server to. `0` (default) picks an available port. - **debug** (*bool*, optional) – Run the server with verbose debug logging. - **browser** (*bool*, optional) – Open a web browser pointing to the viewer on startup. - **cesium_token** (*str*, optional) – Cesium Ion access token for the 3-D globe viewer. - **host** (*str*, optional) – Hostname to bind the server to. Default is `"127.0.0.1"`. - **cors_all** (*bool*, optional) – If `True`, enable permissive CORS headers allowing all origins. - **run** (*bool*, optional) – If `True` (default), start the uvicorn server. If `False`, return the app without running it. ### Returns - **fastapi.FastAPI** – The configured and (optionally running) FastAPI application. ``` -------------------------------- ### Install localtileserver with Jupyter support Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/installation/remote-jupyter.rst Install localtileserver with the jupyter extra to get the jupyter-loopback proxy extension and kernel-side autodetect. ```bash pip install localtileserver[jupyter] ``` -------------------------------- ### Install with pip Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/installation/index.rst Install localtileserver and ipyleaflet from PyPI using pip. ```bash pip install localtileserver ipyleaflet ``` -------------------------------- ### Install with conda Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/installation/index.rst Recommended installation method using conda from the conda-forge channel. Installs localtileserver and ipyleaflet. ```bash conda install -c conda-forge localtileserver ipyleaflet ``` -------------------------------- ### Create a virtual mosaic with get_mosaic_tile and get_mosaic_preview Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/user-guide/mosaic.rst Use the Python handler functions to create a virtual mosaic from a list of raster files. The example shows how to get a thumbnail preview and a specific tile using the default pixel selection method. ```python from localtileserver.tiler.mosaic import get_mosaic_tile, get_mosaic_preview # List of raster files to mosaic files = [ 'path/to/scene_north.tif', 'path/to/scene_south.tif', ] # Get a mosaic thumbnail thumb = get_mosaic_preview(files, max_size=512) # Get a mosaic tile at a specific location tile = get_mosaic_tile(files, z=10, x=512, y=512) ``` -------------------------------- ### Launch web viewer with example dataset Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/user-guide/web-app.rst Launches the web viewer with the 'dem' example dataset. Other available choices include 'blue_marble', 'virtual_earth', 'arcgis', and 'bahamas'. ```bash python -m localtileserver dem ``` -------------------------------- ### Minimal ipyleaflet visualization Source: https://github.com/banesullivan/localtileserver/blob/main/README.md Minimal example to visualize a local raster file with ipyleaflet. Creates a tile server from a local file, gets a leaflet tile layer, and adds it to a map. Requires a local raster file path. ```python import localtileserver as lts from ipyleaflet import Map # First, create a tile server from local raster file client = lts.open("path/to/geo.tif") # Create ipyleaflet tile layer from that server t = lts.get_leaflet_tile_layer(client) m = Map(center=client.center(), zoom=client.default_zoom) m.add(t) m ``` -------------------------------- ### Install localtileserver with conda Source: https://github.com/banesullivan/localtileserver/blob/main/README.md Recommended installation method using conda from the conda-forge channel. Installs the localtileserver package and its dependencies. ```bash conda install -c conda-forge localtileserver ``` -------------------------------- ### REST API examples for stretch parameter Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/user-guide/stretch.rst Shows three GET requests using the stretch parameter: linear for tiles, equalize and sqrt for thumbnails. The stretch parameter overrides any vmin/vmax values. ```bash # Tile with linear stretch GET /api/tiles/{z}/{x}/{y}.png?filename=dem.tif&stretch=linear # Thumbnail with histogram equalization GET /api/thumbnail.png?filename=dem.tif&stretch=equalize # Thumbnail with square root stretch GET /api/thumbnail.png?filename=dem.tif&stretch=sqrt ``` -------------------------------- ### Load Bahamas example raster Source: https://github.com/banesullivan/localtileserver/blob/main/examples/example.ipynb Load the bundled Bahamas RGB raster from localtileserver's example data using the examples.get_bahamas() function. ```python # Load the bundled Bahamas RGB raster from localtileserver's example data bahamas = examples.get_bahamas() ``` -------------------------------- ### REST API bounding box crop examples Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/user-guide/spatial-subsets.rst REST API examples for bounding box crops using the /api/part endpoint. The first GET request crops a rectangular region using a bounding box in left,bottom,right,top order. The second adds the bounds_crs parameter to specify the CRS of the bounding box coordinates. The third downloads the result as a GeoTIFF for GIS analysis. ```bash # Bounding box as left,bottom,right,top GET /api/part.png?filename=geo.tif&bbox=-78.0,25.0,-77.0,26.0 # Specify the CRS of the bounding box coordinates GET /api/part.png?filename=geo.tif&bbox=-78.0,25.0,-77.0,26.0&bounds_crs=EPSG:4326 # Download as GeoTIFF for GIS analysis GET /api/part.tif?filename=geo.tif&bbox=-78.0,25.0,-77.0,26.0&bounds_crs=EPSG:4326 ``` -------------------------------- ### Install optional colormaps dependencies Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/installation/index.rst Installs optional dependencies for additional colormaps, including matplotlib, cmocean, and colorcet. ```bash pip install localtileserver[colormaps] ``` -------------------------------- ### Install optional helpers dependencies Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/installation/index.rst Installs optional dependencies for geometry helpers, including shapely for geometry conversion utilities. ```bash pip install localtileserver[helpers] ``` -------------------------------- ### localtileserver.examples.get_oam2 Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/api/examples.rst Factory function to create a TileClient for the OAM2 example dataset. Serves tiles on a specified port with optional debug mode and client connection settings. ```APIDOC ## Function: localtileserver.examples.get_oam2 ### Description Creates a TileClient for the OAM2 example dataset. Serves tiles on the specified port with optional debug mode and client connection settings. ### Signature ```python get_oam2(port: int | str = 'default', debug: bool = False, client_port: int | None = None, client_host: str | None = None, client_prefix: str | None = None) ``` ### Parameters - **port** (int | str, optional) - The port on which to serve tiles. Default is `'default'`. - **debug** (bool, optional) - Whether to enable debug mode. Default is `False`. - **client_port** (int | None, optional) - The port for the client to connect to. - **client_host** (str | None, optional) - The host for the client to connect to. - **client_prefix** (str | None, optional) - The URL prefix for the client. ### Returns A TileClient instance for the example dataset. ``` -------------------------------- ### Install optional xarray dependencies Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/installation/index.rst Installs optional dependencies for Xarray/DataArray support, including xarray and rioxarray for serving tiles from xarray DataArrays. ```bash pip install localtileserver[xarray] ``` -------------------------------- ### GET /swagger/ Source: https://github.com/banesullivan/localtileserver/blob/main/README.md Provides interactive API documentation. ```APIDOC ## GET /swagger/ ### Description Provides interactive API documentation. ### Method GET ### Endpoint /swagger/ ### Parameters None ### Response #### Success Response (200) - HTML page with interactive API documentation #### Response Example HTML content ``` -------------------------------- ### localtileserver.manager.AppManager.get_or_create_app Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/api/utilities.rst Static method to get or create the shared FastAPI application instance. ```APIDOC ## localtileserver.manager.AppManager.get_or_create_app ### Description Return the shared FastAPI app, creating it if necessary. This is a static method of the singleton manager class. ### Method Static method call ### Signature `static get_or_create_app(cors_all: bool = False)` ### Parameters - **cors_all** (bool, optional) - If `True`, enable permissive CORS headers allowing all origins. ### Returns - **fastapi.FastAPI** - The singleton FastAPI application instance. ``` -------------------------------- ### localtileserver.examples.get_san_francisco Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/api/examples.rst Factory function to create a TileClient for the San Francisco example dataset. Serves tiles on a specified port with optional debug mode and client connection settings. ```APIDOC ## Function: localtileserver.examples.get_san_francisco ### Description Creates a TileClient for the San Francisco example dataset. Serves tiles on the specified port with optional debug mode and client connection settings. ### Signature ```python get_san_francisco(port: int | str = 'default', debug: bool = False, client_port: int | None = None, client_host: str | None = None, client_prefix: str | None = None) ``` ### Parameters - **port** (int | str, optional) - The port on which to serve tiles. Default is `'default'`. - **debug** (bool, optional) - Whether to enable debug mode. Default is `False`. - **client_port** (int | None, optional) - The port for the client to connect to. - **client_host** (str | None, optional) - The host for the client to connect to. - **client_prefix** (str | None, optional) - The URL prefix for the client. ### Returns A TileClient instance for the example dataset. ``` -------------------------------- ### GET /api/mosaic/thumbnail.{fmt} Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/api/rest-api.rst Serves a thumbnail image of a mosaic. ```APIDOC ## GET /api/mosaic/thumbnail.{fmt} ### Description Serve a mosaic thumbnail. ### Method GET ### Endpoint /api/mosaic/thumbnail.{fmt} ### Parameters #### Path Parameters - **fmt** (string) - Required - Thumbnail format (e.g., png, jpg). #### Query Parameters - **files** (string) - Optional - Comma-separated file paths or URLs to mosaic. If omitted the server falls back to app.state.mosaic_assets. - **indexes** (string) - Optional - Comma-separated band indexes to include. - **max_size** (integer) - Optional - Maximum pixel dimension of the thumbnail (default: 512). ### Response #### Success Response (200) Returns the mosaic thumbnail image. ``` -------------------------------- ### localtileserver.examples.get_landsat Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/api/examples.rst Factory function to create a TileClient for the Landsat example dataset. Serves tiles on a specified port with optional debug mode and client connection settings. ```APIDOC ## Function: localtileserver.examples.get_landsat ### Description Creates a TileClient for the Landsat example dataset. Serves tiles on the specified port with optional debug mode and client connection settings. ### Signature ```python get_landsat(port: int | str = 'default', debug: bool = False, client_port: int | None = None, client_host: str | None = None, client_prefix: str | None = None) ``` ### Parameters - **port** (int | str, optional) - The port on which to serve tiles. Default is `'default'`. - **debug** (bool, optional) - Whether to enable debug mode. Default is `False`. - **client_port** (int | None, optional) - The port for the client to connect to. - **client_host** (str | None, optional) - The host for the client to connect to. - **client_prefix** (str | None, optional) - The URL prefix for the client. ### Returns A TileClient instance for the example dataset. ``` -------------------------------- ### Load DEM and display with ipyleaflet Source: https://github.com/banesullivan/localtileserver/blob/main/examples/hillshade.ipynb Loads an example DEM dataset and creates an ipyleaflet map with a tile layer using the 'gist_earth' colormap. ```python # Example DEM dataset client = examples.get_co_elevation() tdem = get_leaflet_tile_layer(client, colormap="gist_earth") m = Map(center=client.center(), zoom=client.default_zoom) m.add_layer(tdem) m ``` -------------------------------- ### localtileserver.examples.get_landsat7 Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/api/examples.rst Factory function to create a TileClient for the Landsat 7 example dataset. Serves tiles on a specified port with optional debug mode and client connection settings. ```APIDOC ## Function: localtileserver.examples.get_landsat7 ### Description Creates a TileClient for the Landsat 7 example dataset. Serves tiles on the specified port with optional debug mode and client connection settings. ### Signature ```python get_landsat7(port: int | str = 'default', debug: bool = False, client_port: int | None = None, client_host: str | None = None, client_prefix: str | None = None) ``` ### Parameters - **port** (int | str, optional) - The port on which to serve tiles. Default is `'default'`. - **debug** (bool, optional) - Whether to enable debug mode. Default is `False`. - **client_port** (int | None, optional) - The port for the client to connect to. - **client_host** (str | None, optional) - The host for the client to connect to. - **client_prefix** (str | None, optional) - The URL prefix for the client. ### Returns A TileClient instance for the example dataset. ``` -------------------------------- ### GET /api/xarray/thumbnail.{fmt} Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/api/rest-api.rst Serves a thumbnail image from a registered DataArray. ```APIDOC ## GET /api/xarray/thumbnail.{fmt} ### Description Serve a thumbnail from a registered DataArray. ### Method GET ### Endpoint /api/xarray/thumbnail.{fmt} ### Parameters #### Path Parameters - **fmt** (string) - Required - Thumbnail format (e.g., png, jpg). #### Query Parameters - **key** (string) - Optional - Registry key identifying the DataArray. If only one DataArray is registered the key may be omitted. - **indexes** (string) - Optional - Comma-separated band indexes to include. - **max_size** (integer) - Optional - Maximum pixel dimension of the thumbnail (default: 512). ### Response #### Success Response (200) Returns the thumbnail image. ``` -------------------------------- ### localtileserver.configure.get_default_client_params Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/api/utilities.rst Function to get default client connection parameters from environment and Jupyter context. ```APIDOC ## localtileserver.configure.get_default_client_params ### Description Get default client connection parameters from environment and Jupyter context. Resolution order for each parameter: explicit argument, environment variable, then autodetection of the bundled Jupyter Server extension (prefix only). ### Method Function call ### Signature `localtileserver.configure.get_default_client_params(host: str | None = None, port: int | None = None, prefix: str | None = None) -> tuple[str | None, int | None, str | None]` ### Parameters - **host** (str or None, optional) - The client host. If `None`, falls back to the `LOCALTILESERVER_CLIENT_HOST` environment variable. - **port** (int or None, optional) - The client port. If `None`, falls back to the `LOCALTILESERVER_CLIENT_PORT` environment variable. - **prefix** (str or None, optional) - The client URL prefix. If `None`, falls back to the `LOCALTILESERVER_CLIENT_PREFIX` environment variable, then to `jupyter_loopback.autodetect_prefix()`. ### Returns - **tuple** (str or None, int or None, str or None) - The resolved `(host, port, prefix)` values. ``` -------------------------------- ### Cesium Split View Setup and Tile Layer Adding (JavaScript) Source: https://github.com/banesullivan/localtileserver/blob/main/localtileserver/web/templates/tileserver/cesiumSplitViewer.html Creates a draggable slider to control Cesium's imagery split position, then fetches metadata for two tiles files (filenameA and filenameB) to add left and right imagery layers with a flyTo animation. Also defines an opacity update function. ```javascript // Set up Cesium split view // https://sandcastle.cesium.com/?src=Imagery%20Layers%20Split.html var cesiumContainer = document.getElementById('cesiumContainer'); var slider = document.createElement('div'); slider.className = 'slider'; slider.id = 'slider'; cesiumContainer.appendChild(slider) viewer.scene.imagerySplitPosition = slider.offsetLeft / slider.parentElement.offsetWidth; var handler = new Cesium.ScreenSpaceEventHandler(slider); var moveActive = false; function move(movement) { if (!moveActive) { return; } var relativeOffset = movement.endPosition.x; var splitPosition = (slider.offsetLeft + relativeOffset) / slider.parentElement.offsetWidth; slider.style.left = 100.0 * splitPosition + "%"; viewer.scene.imagerySplitPosition = splitPosition; } handler.setInputAction(function() { moveActive = true; }, Cesium.ScreenSpaceEventType.LEFT_DOWN); handler.setInputAction(function() { moveActive = true; }, Cesium.ScreenSpaceEventType.PINCH_START); handler.setInputAction(move, Cesium.ScreenSpaceEventType.MOUSE_MOVE); handler.setInputAction(move, Cesium.ScreenSpaceEventType.PINCH_MOVE); handler.setInputAction(function() { moveActive = false; }, Cesium.ScreenSpaceEventType.LEFT_UP); handler.setInputAction(function() { moveActive = false; }, Cesium.ScreenSpaceEventType.PINCH_END); ``` ```javascript // Add tile layers to scene var params = new URLSearchParams(window.location.search); var filenameA = params.get('filenameA'); var filenameB = params.get('filenameB'); var tileProvider; var tileLayerA; var tileLayerB; var layers = viewer.scene.imageryLayers; var tileUrlA = `${host}/api/tiles/{z}/{x}/{y}.png?filename=${filenameA}`; var tileUrlB = `${host}/api/tiles/{z}/{x}/{y}.png?filename=${filenameB}`; fetch(`${host}/api/metadata?filename=${filenameA}`) .then(response => response.json()) .then(data => { var extents = data["bounds"]; var rectangle = Cesium.Rectangle.fromDegrees(extents.xmin, extents.ymin, extents.xmax, extents.ymax) var tileProvider = new Cesium.UrlTemplateImageryProvider({ url: tileUrlA, subdomains: null, rectangle: rectangle, }); tileLayerA = layers.addImageryProvider(tileProvider); tileLayerA.splitDirection = Cesium.ImagerySplitDirection.LEFT; viewer.camera.flyTo({ destination: rectangle, }); }); fetch(`${host}/api/metadata?filename=${filenameB}`) .then(response => response.json()) .then(data => { var extents = data["bounds"]; var rectangle = Cesium.Rectangle.fromDegrees(extents.xmin, extents.ymin, extents.xmax, extents.ymax) var tileProvider = new Cesium.UrlTemplateImageryProvider({ url: tileUrlB, subdomains: null, rectangle: rectangle, }); tileLayerB = layers.addImageryProvider(tileProvider); tileLayerB.splitDirection = Cesium.ImagerySplitDirection.RIGHT; viewer.camera.flyTo({ destination: rectangle, }); }); ``` ```javascript function updateTilesOpacity(e, value) { value = Number(value) / 100.0; tileLayerA.alpha = value; tileLayerB.alpha = value; } ``` -------------------------------- ### Display Bahamas raster with ipyleaflet Source: https://github.com/banesullivan/localtileserver/blob/main/example.ipynb Creates a tile server from the Bahamas example raster, generates an ipyleaflet tile layer, and displays it on a map centered on the data. ```python # First, create a tile server from raster file b_client = examples.get_bahamas() # Create ipyleaflet tile layer from that server t = get_leaflet_tile_layer(b_client) # Create ipyleaflet map, add tile layer, and display m = Map(center=b_client.center(), zoom=b_client.default_zoom) m.add(t) m ``` -------------------------------- ### GET /api/thumbnail.{fmt} Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/api/rest-api.rst Generates a thumbnail image of the raster file. ```APIDOC ## GET /api/thumbnail.{fmt} ### Description Generates a thumbnail image of the raster file. ### Method GET ### Endpoint /api/thumbnail.{fmt} ### Parameters #### Path Parameters - **fmt** (string) - Required - Output format (e.g., `png`, `jpg`). #### Query Parameters - **filename** (string) - Required - Path or URL to the raster file. - **indexes** (string) - Optional - Comma-separated band indexes (e.g., `1,2,3`). - **colormap** (string) - Optional - Colormap name (e.g., `terrain`, `viridis`), or a JSON color definition. - **vmin** (number) - Optional - Minimum value for rescaling (comma-separated for per-band values). - **vmax** (number) - Optional - Maximum value for rescaling (comma-separated for per-band values). - **nodata** (number) - Optional - Override the file’s nodata value. - **expression** (string) - Optional - Band math expression (e.g., `(b4-b1)/(b4+b1)`). Mutually exclusive with `indexes`. - **stretch** (string) - Optional - Stretch mode: `none`, `minmax`, `linear`, `equalize`, `sqrt`, `log`. - **max_size** (integer) - Optional - Maximum pixel dimension of the thumbnail (default: `512`). - **crs** (string) - Optional - Reproject the thumbnail to this CRS before returning. ### Response #### Success Response (200) Returns the thumbnail image in the specified format. ``` -------------------------------- ### localtileserver.get_or_create_tile_client Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/api/python-client.rst Get an existing TileClient or create a new one from a source. If the source is already a TileClient, it is used directly; otherwise a new TileClient is created. ```APIDOC ## localtileserver.get_or_create_tile_client ### Description Get an existing TileClient or create a new one from a source. If the source is already a TileClient, it is used directly; otherwise a new TileClient is created. ### Method Function call ### Signature `localtileserver.get_or_create_tile_client(source: Path | str | TileClient | DatasetReaderBase, port: int | str = 'default', debug: bool = False)` ### Parameters - **source** (Path | str | TileClient | DatasetReaderBase) - Required - The raster source. If already a `TileClient`, it is used directly. Otherwise, a new `TileClient` is created. - **port** (int | str) - Optional - The port on your host machine to use for the tile server. Defaults to `"default"` which selects an available port. - **debug** (bool) - Optional - Run the tile server in debug mode. Defaults to `False`. ### Returns - **source** (TileClient) - The tile client instance. - **_internally_created** (bool) - `True` if a new `TileClient` was created internally, `False` if the provided `source` was already a `TileClient`. ``` -------------------------------- ### get_mosaic_preview(files, max_size=512) Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/user-guide/mosaic.rst Python function to get a mosaic thumbnail preview. ```APIDOC ## get_mosaic_preview(files, max_size=512) ### Description Get a thumbnail preview of the mosaic from the provided raster files. ### Parameters - **files** (list) - Required - List of raster file paths or URLs. - **max_size** (int, optional) - Maximum thumbnail dimension (default: 512). ### Returns - Thumbnail image. ``` -------------------------------- ### Use pixel selection methods (HighestMethod, MeanMethod) Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/user-guide/mosaic.rst Select a pixel selection method from rio-tiler's defaults. The example shows using HighestMethod and MeanMethod; the default is FirstMethod (first valid pixel wins). ```python from rio_tiler.mosaic.methods.defaults import ( FirstMethod, HighestMethod, LowestMethod, MeanMethod, MedianMethod, ) # Use the highest pixel value from overlapping areas tile = get_mosaic_tile(files, z=10, x=512, y=512, pixel_selection=HighestMethod) # Use the mean of overlapping pixels tile = get_mosaic_tile(files, z=10, x=512, y=512, pixel_selection=MeanMethod) ``` -------------------------------- ### GET /api/mosaic/tiles/{z}/{x}/{y}.{fmt} Source: https://github.com/banesullivan/localtileserver/blob/main/README.md Retrieves mosaic tiles from multiple rasters. ```APIDOC ## GET /api/mosaic/tiles/{z}/{x}/{y}.{fmt} ### Description Retrieves mosaic tiles from multiple rasters. ### Method GET ### Endpoint /api/mosaic/tiles/{z}/{x}/{y}.{fmt} ### Parameters #### Path Parameters - **z** (integer) - Required - Zoom level - **x** (integer) - Required - Tile column - **y** (integer) - Required - Tile row - **fmt** (string) - Required - Output format (e.g., png, jpg) #### Query Parameters - **expression** (string) - Optional - Band expression - **stretch** (string) - Optional - Stretch type - **indexes** (string) - Optional - Band indexes - **colormap** (string) - Optional - Colormap name - **vmin** (number) - Optional - Minimum value for contrast - **vmax** (number) - Optional - Maximum value for contrast - **nodata** (number) - Optional - No-data value ### Response #### Success Response (200) - Image data of the requested format #### Response Example Binary image data ``` -------------------------------- ### TileServerMixin.get_leaflet_map Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/api/python-client.rst Gets an ipyleaflet Map centered and zoomed to the dataset bounds. ```APIDOC ## TileServerMixin.get_leaflet_map ### Description Gets an ipyleaflet Map centered and zoomed to the dataset bounds. ### Method Method ### Parameters - **add_bounds** (bool) - Optional - If True, add a WKT boundary layer to the map. Requires shapely. Defaults to False. - **\*\*kwargs** - Optional - Additional keyword arguments passed to ipyleaflet.Map. ### Returns - **ipyleaflet.Map** - A map widget centered on the dataset with the default zoom level. ``` -------------------------------- ### GET /api/part.{fmt} Source: https://github.com/banesullivan/localtileserver/blob/main/README.md Crops a bounding box from the raster and returns it in the specified format. ```APIDOC ## GET /api/part.{fmt} ### Description Crops a bounding box from the raster and returns it in the specified format. ### Method GET ### Endpoint /api/part.{fmt} ### Parameters #### Path Parameters - **fmt** (string) - Required - Output format (e.g., png, jpg) #### Query Parameters - **bbox** (string) - Required - Bounding box coordinates (minx,miny,maxx,maxy) ### Response #### Success Response (200) - Image data of the cropped area #### Response Example Binary image data ``` -------------------------------- ### GET /api/tiles/{z}/{x}/{y}.png Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/user-guide/expressions.rst Retrieves a tile image with an on-the-fly band math expression applied, such as NDVI or NDWI. ```APIDOC ## [GET] /api/tiles/{z}/{x}/{y}.png ### Description Retrieves a tile image with an on-the-fly band math expression applied, such as NDVI or NDWI. ### Method GET ### Endpoint /api/tiles/{z}/{x}/{y}.png ### Parameters #### Path Parameters - **z** (integer) - Required - Zoom level - **x** (integer) - Required - Tile column - **y** (integer) - Required - Tile row #### Query Parameters - **filename** (string) - Required - Path to the raster file - **expression** (string) - Required - Band math expression (e.g., `(b4-b1)/(b4+b1)`) - **vmin** (number) - Optional - Minimum value for color scaling - **vmax** (number) - Optional - Maximum value for color scaling - **colormap** (string) - Optional - Colormap name (e.g., `RdYlGn`) ### Response #### Success Response (200) - PNG image of the tile #### Response Example Binary PNG image data ``` -------------------------------- ### Import dependencies for DEM hillshade Source: https://github.com/banesullivan/localtileserver/blob/main/examples/hillshade.ipynb Imports required modules: ipyleaflet for map controls, rasterio for raster I/O, and localtileserver for example data, tile layers, and helpers. ```python from ipyleaflet import Map, SplitMapControl import rasterio as rio from localtileserver import examples, get_leaflet_tile_layer, helpers ``` -------------------------------- ### TilerInterface.center Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/api/python-client.rst Get the center coordinates of the dataset in the form (y, x) or as a shapely point or WKT string. ```APIDOC ## center(projection: str = 'EPSG:4326', return_point: bool = False, return_wkt: bool = False) ### Description Get center in the form of (y , x ). ### Method center ### Parameters #### Query Parameters - **projection** (str) - The srs or projection as a Proj4 string of the returned coordinates. - **return_point** (bool, optional) - If true, returns a shapely.Point object. - **return_wkt** (bool, optional) - If true, returns a Well Known Text (WKT) string of center coordinates. ### Returns - **tuple of float** - A tuple of `(y, x)` (latitude, longitude) when neither `return_point` nor `return_wkt` is `True`. - **shapely.geometry.Point** - When `return_point` is `True`. - **str** - WKT string when `return_wkt` is `True`. ``` -------------------------------- ### localtileserver.tiler.mosaic.get_mosaic_preview Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/api/handlers.rst Get a mosaic preview from multiple raster assets. This function takes a list of raster file paths or URLs and optional parameters, and returns the rendered preview image bytes. ```APIDOC ## localtileserver.tiler.mosaic.get_mosaic_preview ### Description Get a mosaic preview from multiple raster assets. ### Method Function call ### Endpoint `localtileserver.tiler.mosaic.get_mosaic_preview(assets, img_format='PNG', max_size=512, indexes=None, pixel_selection=None, **kwargs)` ### Parameters - **assets** (list of str) - Required - List of file paths or URLs to raster datasets. - **img_format** (str, optional) - Output image format. Default is `"PNG"`. - **max_size** (int, optional) - Maximum dimension (width or height) of the preview image in pixels. Default is `512`. - **indexes** (list of int or None, optional) - Band indexes to read (1-based). If `None`, all bands are included. - **pixel_selection** (MosaicMethodBase or None, optional) - Mosaic pixel selection method. Defaults to `FirstMethod` (first valid pixel wins). - **\*\*kwargs** (dict, optional) - Additional keyword arguments passed to the underlying preview reader. ### Returns Rendered mosaic preview image bytes with MIME type metadata. ### Return Type [ImageBytes](utilities.md#localtileserver.tiler.utilities.ImageBytes) ``` -------------------------------- ### TilerInterface.bounds Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/api/python-client.rst Get the bounds of the dataset in a specified projection. Optionally return a shapely polygon or WKT string. ```APIDOC ## bounds(projection: str = 'EPSG:4326', return_polygon: bool = False, return_wkt: bool = False) ### Description Get the bounds of the dataset. ### Method bounds ### Parameters #### Query Parameters - **projection** (str, optional) - The spatial reference system as a Proj4 or EPSG string for the returned coordinates. Defaults to `"EPSG:4326"`. - **return_polygon** (bool, optional) - If `True`, return a `shapely.geometry.Polygon` instead of a tuple. Requires `shapely`. - **return_wkt** (bool, optional) - If `True`, return a Well Known Text (WKT) string of the bounding polygon. Requires `shapely`. ### Returns - **tuple of float** - A tuple of `(bottom, top, left, right)` when neither `return_polygon` nor `return_wkt` is `True`. - **shapely.geometry.Polygon** - When `return_polygon` is `True`. - **str** - WKT string when `return_wkt` is `True`. ``` -------------------------------- ### TileServerMixin.__init__ Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/api/python-client.rst Initializes a TileServerMixin instance to serve tiles from a local raster file in a background thread. ```APIDOC ## TileServerMixin.__init__ ### Description Initializes a TileServerMixin instance to serve tiles from a local raster file in a background thread. ### Method Constructor ### Parameters - **port** (int) - Optional - The port on your host machine to use for the tile server. Defaults to getting an available port. - **debug** (bool) - Optional - Run the tile server in debug mode. - **host** (str) - Optional - The host address to bind the tile server to. - **client_port** (int) - Optional - The port on your client browser to use for fetching tiles. Useful when running in Docker and performing port forwarding. - **client_host** (str) - Optional - The host on which your client browser can access the server. - **client_prefix** (str) - Optional - The URL prefix used for proxied access to the tile server. - **cors_all** (bool) - Optional - If True, enable CORS for all origins on the tile server. ``` -------------------------------- ### localtileserver.open Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/api/python-client.rst Open a raster source as a TileClient. Convenience entrypoint modeled after rasterio.open / xarray.open_dataset. Launches a background tile server and returns a client ready for use with visualization helpers. ```APIDOC ## localtileserver.open ### Description Open a raster source as a TileClient. Convenience entrypoint modeled after `rasterio.open` / `xarray.open_dataset`. Launches a background tile server for the given source and returns a client ready for use with `get_leaflet_tile_layer()`, `get_folium_tile_layer()`, and other visualization helpers. ### Method Function call ### Signature `localtileserver.open(source: Path | str | TileClient | STACClient | DatasetReaderBase, port: int | str = 'default', debug: bool = False, host: str = '127.0.0.1', client_port: int | None = None, client_host: str | None = None, client_prefix: str | None = None, cors_all: bool = False) -> TileClient | STACClient` ### Parameters - **source** (Path | str | TileClient | STACClient | DatasetReaderBase) - Required - The raster source. A local path, a URL to a remote COG, a `rasterio.io.DatasetReader`, or an already-running client. - **port** (int | str) - Optional - Port on the host machine for the tile server. Defaults to `"default"`, which picks an available port. - **debug** (bool) - Optional - Run the tile server in debug mode. - **host** (str) - Optional - Host address to bind the tile server to. - **client_port** (int) - Optional - Port the client browser should use when fetching tiles. Useful when running in Docker with port forwarding. - **client_host** (str) - Optional - Host the client browser should use when fetching tiles. - **client_prefix** (str) - Optional - URL prefix for proxied access to the tile server. - **cors_all** (bool) - Optional - If `True`, enable CORS for all origins on the tile server. ### Returns - **TileClient | STACClient** - A running tile client for `source`. ### Example ```pycon >>> import localtileserver as lts >>> client = lts.open("path/to/raster.tif") >>> client.default_zoom ``` ``` -------------------------------- ### localtileserver.examples.get_blue_marble Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/api/examples.rst Factory function that returns a TileClient pre-loaded with the Blue Marble sample dataset. Accepts optional server configuration parameters. ```APIDOC ## get_blue_marble(port: int | str = 'default', debug: bool = False, client_port: int | None = None, client_host: str | None = None, client_prefix: str | None = None) ### Description Returns a TileClient instance pre-loaded with the Blue Marble sample dataset. This is a factory function for quick experimentation. ### Parameters - **port** (int | str) - Optional - The port on which to serve tiles. Default is `"default"`. - **debug** (bool) - Optional - Whether to enable debug mode. Default is `False`. - **client_port** (int | None) - Optional - The port for the client to connect to. - **client_host** (str | None) - Optional - The host for the client to connect to. - **client_prefix** (str | None) - Optional - The URL prefix for the client. ### Returns - **TileClient** - A TileClient instance pre-loaded with the sample data. ``` -------------------------------- ### TileServerMixin.enable_colab Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/api/python-client.rst Configures this client for use on Google Colab. ```APIDOC ## TileServerMixin.enable_colab ### Description Configures this client for use on Google Colab. Sets client_host to "localhost" and client_port to the server port so that tiles are accessible within Colab. ### Method Method ``` -------------------------------- ### Launch tileserver web application Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/user-guide/web-app.rst Launches the local tileserver web application for viewing a raster file. The web viewer allows you to view the raster and extract regions of interest. ```bash python -m localtileserver path/to/raster.tif ``` -------------------------------- ### server (property) Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/api/python-client.rst Returns the background server instance for the tile server. ```APIDOC ## server (property) ### Description Return the background server instance. ### Method N/A (Python property) ### Endpoint N/A (Python property) ### Parameters None ### Returns - **server_thread.ServerThread** - The managed server thread. ### Return Type server_thread.ServerThread ``` -------------------------------- ### GET /api/statistics Source: https://github.com/banesullivan/localtileserver/blob/main/README.md Retrieves per-band statistics for the raster. ```APIDOC ## GET /api/statistics ### Description Retrieves per-band statistics for the raster. ### Method GET ### Endpoint /api/statistics ### Parameters None ### Response #### Success Response (200) - Statistics object containing per-band statistics #### Response Example { "statistics": "per-band statistics" } ``` -------------------------------- ### GET /api/xarray/info Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/api/rest-api.rst Retrieves metadata for a registered DataArray. ```APIDOC ## GET /api/xarray/info ### Description Get DataArray metadata for a registered DataArray. ### Method GET ### Endpoint /api/xarray/info ### Parameters #### Query Parameters - **key** (string) - Optional - Registry key identifying the DataArray. If only one DataArray is registered the key may be omitted. ### Response #### Success Response (200) Returns DataArray metadata. ``` -------------------------------- ### REST API GeoJSON feature mask example Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/user-guide/spatial-subsets.rst REST API example for a GeoJSON feature mask using the /api/feature endpoint. The request is a POST with a JSON body containing a GeoJSON Polygon. The polygon defines the mask to extract data from the raster. ```bash POST /api/feature.png?filename=geo.tif Content-Type: application/json { "type": "Polygon", "coordinates": [[ [-77.5, 25.5], [-77.0, 25.5], [-77.0, 26.0], [-77.5, 26.0], [-77.5, 25.5] ]] } ``` -------------------------------- ### create_app(url_prefix='/', cors_all=False, debug=False, cesium_token='') Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/api/utilities.rst Creates and configures a FastAPI application instance. Allows setting a URL prefix, enabling CORS, debug mode, and providing a Cesium Ion access token. ```APIDOC ## create_app(url_prefix: str = '/', cors_all: bool = False, debug: bool = False, cesium_token: str = '') ### Description Creates and configures a FastAPI application instance. ### Parameters - **url_prefix** (*str*, optional) – URL prefix for the application routes. Default is `"/"`. - **cors_all** (*bool*, optional) – If `True`, enable permissive CORS headers allowing all origins. - **debug** (*bool*, optional) – Run the application in debug mode with verbose logging. - **cesium_token** (*str*, optional) – Cesium Ion access token for the 3-D globe viewer. ### Returns - **fastapi.FastAPI** – The configured FastAPI application instance. ``` -------------------------------- ### GET /api/xarray/statistics Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/api/rest-api.rst Retrieves per-band statistics for a registered DataArray. ```APIDOC ## GET /api/xarray/statistics ### Description Get per-band statistics for a registered DataArray. ### Method GET ### Endpoint /api/xarray/statistics ### Parameters #### Query Parameters - **key** (string) - Optional - Registry key identifying the DataArray. If only one DataArray is registered the key may be omitted. - **indexes** (string) - Optional - Comma-separated band indexes to include. ### Response #### Success Response (200) Returns per-band statistics. ``` -------------------------------- ### localtileserver.tiler.handler.get_preview(tile_source: Reader, indexes: list[int] | None = None, colormap: str | None = None, vmin: float | list[float] | None = None, vmax: float | list[float] | None = None, nodata: int | float | None = None, img_format: str = 'PNG', max_size: int = 512, crs: str | None = None, expression: str | None = None, stretch: str | None = None) Source: https://github.com/banesullivan/localtileserver/blob/main/doc/source/api/handlers.rst Generates a downsampled preview image of the entire raster. Supports band selection, colormap, value scaling, nodata override, output format, maximum size, target CRS, band math expression, and stretch mode. ```APIDOC ## localtileserver.tiler.handler.get_preview ### Description Generates a downsampled preview image of the entire raster. Supports band selection, colormap, value scaling, nodata override, output format, maximum size, target CRS, band math expression, and stretch mode. ### Parameters - **tile_source** (Reader) - Required - An open rio-tiler `Reader` for the raster dataset. - **indexes** (list of int, optional) - Band indexes to render. Auto-detected when not provided. - **colormap** (str, optional) - Name of a colormap to apply when rendering a single band. - **vmin** (float or list of float, optional) - Minimum value(s) for rescaling band data. - **vmax** (float or list of float, optional) - Maximum value(s) for rescaling band data. - **nodata** (int or float, optional) - Override nodata value for the dataset. - **img_format** (str, optional) - Output image format (e.g., `"PNG"`, `"JPEG"`). Defaults to `"PNG"`. - **max_size** (int, optional) - Maximum dimension of the output image in pixels. Defaults to `512`. - **crs** (str, optional) - Target CRS for the preview. When provided, the image is reprojected via `Reader.part`. - **expression** (str, optional) - Band math expression (e.g., `"b1/b2"`). When provided, *indexes* is ignored. - **stretch** (str, optional) - Stretch mode to apply before rendering. One of `"none"`, `"minmax"`, `"linear"`, `"equalize"`, `"sqrt"`, or `"log"`. ### Returns - **ImageBytes** - Encoded image bytes with an associated MIME type. ``` -------------------------------- ### GET /api/metadata Source: https://github.com/banesullivan/localtileserver/blob/main/README.md Retrieves metadata about the raster, such as geospatial information and band details. ```APIDOC ## GET /api/metadata ### Description Retrieves metadata about the raster. ### Method GET ### Endpoint /api/metadata ### Parameters None ### Response #### Success Response (200) - Metadata object containing raster information #### Response Example { "metadata": "raster metadata" } ```