π API#
Python Client#
- localtileserver.get_or_create_tile_client(source: Path | str | TileClient | DatasetReaderBase, port: int | str = 'default', debug: bool = False)#
- A helper to safely get a TileClient from a path on disk. - Note - TODO: There should eventually be a check to see if a TileClient instance exists for the given filename. For now, it is not really a big deal because the default is for all TileClientβs to share a single server. 
- class localtileserver.client.TilerInterface(source: Path | str | DatasetReaderBase)#
- Base TileClient methods and configuration. - This class interfaces directly with rasterio and rio-tiler. - Parameters:
- source (pathlib.Path, str, Reader, DatasetReaderBase) β The source dataset to use for the tile client. 
 - property band_names#
 - bounds(projection: str = 'EPSG:4326', return_polygon: bool = False, return_wkt: bool = False)#
 - center(projection: str = 'EPSG:4326', return_point: bool = False, return_wkt: bool = False)#
- Get center in the form of (y <lat>, x <lon>). - 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. 
 
 
 - property dataset#
 - property default_zoom#
 - property filename#
 - property info#
 - property max_zoom#
 - property metadata#
 - property min_zoom#
 - point(lon: float, lat: float, **kwargs)#
 - property reader#
 - thumbnail(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, output_path: Path | None = None, encoding: str = 'PNG', max_size: int = 512)#
- Generate a thumbnail preview of the dataset. - Parameters:
- indexes (int) β The band of the source raster to use (default if None is to show RGB if available). Band indexing starts at 1. This can also be a list of integers to set which 3 bands to use for RGB. 
- colormap (str) β The name of the matplotlib colormap to use when plotting a single band. Default is greyscale. 
- vmin (float) β The minimum value to use when colormapping a single band. 
- vmax (float) β The maximized value to use when colormapping a single band. 
- nodata (float) β The value from the band to use to interpret as not valid data. 
 
 
 - tile(z: int, x: int, y: int, 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, output_path: Path | None = None, encoding: str = 'PNG')#
- Generate a tile from the source raster. - Parameters:
- z (int) β The zoom level of the tile. 
- x (int) β The x coordinate of the tile. 
- y (int) β The y coordinate of the tile. 
- indexes (int) β The band of the source raster to use (default if None is to show RGB if available). Band indexing starts at 1. This can also be a list of integers to set which 3 bands to use for RGB. 
- colormap (str) β The name of the matplotlib colormap to use when plotting a single band. Default is greyscale. 
- vmin (float) β The minimum value to use when colormapping a single band. 
- vmax (float) β The maximized value to use when colormapping a single band. 
- nodata (float) β The value from the band to use to interpret as not valid data. 
 
 
 
- class localtileserver.TileClient(source: Path | str | 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)#
- Tile client interface for generateing and serving tiles. - Parameters:
- source (pathlib.Path, str, Reader, DatasetReaderBase) β The source dataset to use for the tile client. 
- port (int) β The port on your host machine to use for the tile server. This defaults to getting an available port. 
- debug (bool) β Run the tile server in debug mode. 
- client_port (int) β The port on your client browser to use for fetching tiles. This is useful when running in Docker and performing port forwarding. 
- client_host (str) β The host on which your client browser can access the server. 
 
 
Jupyter Widget Helpers#
- localtileserver.get_leaflet_tile_layer(source: Path | str | TileClient | DatasetReaderBase, port: int | str = 'default', debug: bool = False, indexes: List[int] | None = None, colormap: str | Colormap | List[str] | None = None, vmin: float | List[float] | None = None, vmax: float | List[float] | None = None, nodata: int | float | None = None, attribution: str | None = None, **kwargs)#
- Generate an ipyleaflet TileLayer for the given TileClient. - Parameters:
- source (Union[pathlib.Path, str, TileClient, rasterio.io.DatasetReaderBase]) β The source of the tile layer. This can be a path on disk or an already open - TileClient
- port (int) β The port on your host machine to use for the tile server (if creating a tileserver. This is ignored if a file path is given). This defaults to getting an available port. 
- debug (bool) β Run the tile server in debug mode (if creating a tileserver. This is ignored if a file path is given). 
- indexes (int) β The band of the source raster to use (default if None is to show RGB if available). Band indexing starts at 1. This can also be a list of integers to set which 3 bands to use for RGB. 
- colormap (str) β The name of the matplotlib colormap to use when plotting a single band. Default is greyscale. 
- vmin (float) β The minimum value to use when colormapping a single band. 
- vmax (float) β The maximized value to use when colormapping a single band. 
- nodata (float) β The value from the band to use to interpret as not valid data. 
- attribution (str) β Attribution for the source raster. This defaults to a message about it being a local file. 
- **kwargs β All additional keyword arguments are passed to - ipyleaflet.TileLayer.
 
- Return type:
- ipyleaflet.TileLayer 
 
- localtileserver.get_folium_tile_layer(source: Path | str | TileClient | DatasetReaderBase, port: int | str = 'default', debug: bool = False, 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, attr: str | None = None, **kwargs)#
- Generate a folium TileLayer for the given TileClient. - Parameters:
- source (Union[pathlib.Path, str, TileClient, rasterio.io.DatasetReaderBase]) β The source of the tile layer. This can be a path on disk or an already open - TileClient
- port (int) β The port on your host machine to use for the tile server (if creating a tileserver. This is ignored if a file path is given). This defaults to getting an available port. 
- debug (bool) β Run the tile server in debug mode (if creating a tileserver. This is ignored if a file path is given). 
- indexes (int) β The band of the source raster to use (default if None is to show RGB if available). Band indexing starts at 1. This can also be a list of integers to set which 3 bands to use for RGB. 
- colormap (str) β The name of the matplotlib colormap to use when plotting a single band. Default is greyscale. 
- vmin (float) β The minimum value to use when colormapping a single band. 
- vmax (float) β The maximized value to use when colormapping a single band. 
- nodata (float) β The value from the band to use to interpret as not valid data. 
- attr (str) β Folium requires the custom tile source have an attribution. This defaults to a message about it being a local file. 
- **kwargs β All additional keyword arguments are passed to - folium.TileLayer.
 
- Return type:
- folium.TileLayer 
 
Other Helpers#
- localtileserver.helpers.save_new_raster(src, data, out_path: str | None = None)#
- Save new raster from a numpy array using the metadata of another raster. - Note - Requires - rasterio- Parameters:
- src (str, DatasetReader, TilerInterface) β The source rasterio data whose spatial reference will be copied 
- data (np.ndarray) β The bands of data to save to the new raster 
- out_path (Optional[str]) β The path for which to write the new raster. If - None, this will use a temporary file
 
 
- localtileserver.make_vsi(url: str, **options)#
- localtileserver.validate.validate_cog(path: str | Reader | TilerInterface, strict: bool = True, quiet: bool = False) bool#
- localtileserver.helpers.polygon_to_geojson(polygon) str#
- Dump shapely.Polygon to GeoJSON.