Skip to content

Commit

Permalink
Add new open method
Browse files Browse the repository at this point in the history
  • Loading branch information
banesullivan committed Jul 20, 2024
1 parent 40df065 commit 6bb746c
Show file tree
Hide file tree
Showing 19 changed files with 112 additions and 61 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ The following is a minimal example to visualize a local raster file with
`ipyleaflet`:

```py
from localtileserver import get_leaflet_tile_layer, TileClient
import localtileserver as lts
from ipyleaflet import Map

# First, create a tile server from local raster file
client = TileClient('path/to/geo.tif')
client = lts.open('path/to/geo.tif')

# Create ipyleaflet tile layer from that server
t = get_leaflet_tile_layer(client)
t = lts.get_leaflet_tile_layer(client)

m = Map(center=client.center(), zoom=client.default_zoom)
m.add(t)
Expand Down Expand Up @@ -95,6 +95,6 @@ If you would like to report any bugs or make feature requests, please open an is
If filing a bug report, please share a scooby `Report`:

```py
import localtileserver
print(localtileserver.Report())
import localtileserver as lts
print(lts.Report())
```
2 changes: 2 additions & 0 deletions doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build

export LOCALTILESERVER_BUILDING_DOCS = true

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
Expand Down
2 changes: 2 additions & 0 deletions doc/source/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
Python Client
-------------

.. autofunction:: localtileserver.open

.. autofunction:: localtileserver.get_or_create_tile_client


Expand Down
7 changes: 4 additions & 3 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@

.. jupyter-execute::

from localtileserver import TileClient, get_leaflet_tile_layer, examples
import localtileserver as lts
from localtileserver import examples
from ipyleaflet import Map

# Create a TileClient from a raster file
# client = TileClient('path/to/geo.tif')
# client = lts.open('path/to/geo.tif')
client = examples.get_san_francisco() # use example data

# Create ipyleaflet TileLayer from that server
t = get_leaflet_tile_layer(client)
t = lts.get_leaflet_tile_layer(client)
# Create ipyleaflet map, add tile layer, and display
m = Map(center=client.center(), zoom=client.default_zoom)
m.add(t)
Expand Down
2 changes: 1 addition & 1 deletion doc/source/user-guide/bokeh.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from bokeh.plotting import figure, output_file, show
from bokeh.io import output_notebook
from bokeh.models import WMTSTileSource
from localtileserver import TileClient, examples
from localtileserver import examples

output_notebook()

Expand Down
10 changes: 5 additions & 5 deletions doc/source/user-guide/compare.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@

.. jupyter-execute::

from localtileserver import TileClient, get_leaflet_tile_layer
import localtileserver as lts
from ipyleaflet import Map, ScaleControl, FullScreenControl, SplitMapControl

# Create tile servers from two raster files
l_client = TileClient('https://www.dropbox.com/s/ffdmncjaj82hf6f/L5039035_03520060512_B30.TIF?dl=0')
r_client = TileClient('https://www.dropbox.com/s/ysxscp059rtrw0d/L5039035_03520060512_B70.TIF?dl=0')
l_client = lts.open('https://www.dropbox.com/s/ffdmncjaj82hf6f/L5039035_03520060512_B30.TIF?dl=0')
r_client = lts.open('https://www.dropbox.com/s/ysxscp059rtrw0d/L5039035_03520060512_B70.TIF?dl=0')

# Shared display parameters
display = dict(vmin=50, vmax=150, colormap='coolwarm')

# Create 2 tile layers from different raster
l = get_leaflet_tile_layer(l_client, **display)
r = get_leaflet_tile_layer(r_client, **display)
l = lts.get_leaflet_tile_layer(l_client, **display)
r = lts.get_leaflet_tile_layer(r_client, **display)
# Make the ipyleaflet map
m = Map(center=l_client.center(), zoom=l_client.default_zoom)
Expand Down
16 changes: 9 additions & 7 deletions doc/source/user-guide/example-data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ Digital Elevation Models (DEMs) of a local region.

.. code:: python
from localtileserver import get_leaflet_tile_layer, examples
import localtileserver as lts
from localtileserver import examples
from ipyleaflet import Map
# Load example tile layer from publicly available DEM source
client = examples.get_elevation()
# Create ipyleaflet tile layer from that server
t = get_leaflet_tile_layer(client,
indexes=1, vmin=-500, vmax=5000,
colormap='plasma',
opacity=0.75)
t = lts.get_leaflet_tile_layer(client,
indexes=1, vmin=-500, vmax=5000,
colormap='plasma',
opacity=0.75)
m = Map(zoom=2)
m.add(t)
Expand All @@ -32,14 +33,15 @@ Here is another example with the Virtual Earth satellite imagery

.. code:: python
from localtileserver import get_leaflet_tile_layer, examples
import localtileserver as lts
from localtileserver import examples
from ipyleaflet import Map
# Load example tile layer from publicly available imagery
client = examples.get_virtual_earth()
# Create ipyleaflet tile layer from that server
t = get_leaflet_tile_layer(client, opacity=1)
t = lts.get_leaflet_tile_layer(client, opacity=1)
m = Map(center=(39.751343612695145, -105.22181306125279), zoom=18)
m.add(t)
Expand Down
8 changes: 4 additions & 4 deletions doc/source/user-guide/hillshade.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ make the data appear more 3-Dimensional.

.. code:: python
from localtileserver import TileClient, get_leaflet_tile_layer
import localtileserver as lts
from localtileserver import examples, helpers
from ipyleaflet import Map, SplitMapControl
import rasterio
# Example DEM dataset
client = examples.get_co_elevation()
tdem = get_leaflet_tile_layer(client, colormap='gist_earth', nodata=0)
tdem = lts.get_leaflet_tile_layer(client, colormap='gist_earth', nodata=0)
m = client.get_leaflet_map()
m.add(tdem)
Expand Down Expand Up @@ -58,7 +58,7 @@ function (adopted from EarthPy).
.. code:: python
# Make an ipyleaflet tile layer of the hillshade
hst = get_leaflet_tile_layer(hs, nodata=0)
hst = lts.get_leaflet_tile_layer(hs, nodata=0)
m = client.get_leaflet_map()
control = SplitMapControl(left_layer=tdem, right_layer=hst)
Expand All @@ -75,7 +75,7 @@ effect:
m = client.get_leaflet_map()
m.add(tdem)
m.add(get_leaflet_tile_layer(hs, opacity=0.5, nodata=0))
m.add(lts.get_leaflet_tile_layer(hs, opacity=0.5, nodata=0))
m
Expand Down
4 changes: 2 additions & 2 deletions doc/source/user-guide/in-memory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
.. jupyter-execute::

import rasterio
import localtileserver as lts
from ipyleaflet import Map
from localtileserver import TileClient, get_leaflet_tile_layer

# Open a rasterio dataset
dataset = rasterio.open('https://open.gishub.org/data/raster/srtm90.tif')
Expand Down Expand Up @@ -34,5 +34,5 @@

.. jupyter-execute::

client = TileClient(raster_dataset)
client = lts.TileClient(raster_dataset)
client.thumbnail(colormap="terrain")
27 changes: 15 additions & 12 deletions doc/source/user-guide/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ Here is the "one-liner" to visualize a large geospatial image with

.. jupyter-execute::

from localtileserver import TileClient, examples
import localtileserver as lts
from localtileserver import examples

# client = TileClient('path/to/geo.tif')
# client = lts.open('path/to/geo.tif')
client = examples.get_san_francisco() # use example data
client

Expand Down Expand Up @@ -67,17 +68,18 @@ a Jupyter notebook. Here is an example:

.. jupyter-execute::

from localtileserver import get_leaflet_tile_layer, TileClient, examples
import localtileserver as lts
from localtileserver import examples
from ipyleaflet import Map

# First, create a tile server from local raster file
# client = TileClient('path/to/geo.tif')
# client = lts.open('path/to/geo.tif')
client = examples.get_elevation() # use example data

# Create ipyleaflet tile layer from that server
t = get_leaflet_tile_layer(client,
indexes=1, vmin=-5000, vmax=5000,
opacity=0.65)
t = lts.get_leaflet_tile_layer(client,
indexes=1, vmin=-5000, vmax=5000,
opacity=0.65)

# Create ipyleaflet map, add tile layer, and display
m = Map(zoom=3)
Expand All @@ -97,15 +99,16 @@ code as the ``ipyleaflet`` example, just note that :class:`folium.Map` is import

.. jupyter-execute::

from localtileserver import get_folium_tile_layer, TileClient, examples
import localtileserver as lts
from localtileserver import examples
from folium import Map

# First, create a tile server from local raster file
# client = TileClient('path/to/geo.tif')
# client = lts.open('path/to/geo.tif')
client = examples.get_oam2() # use example data

# Create folium tile layer from that server
t = get_folium_tile_layer(client)
t = lts.get_folium_tile_layer(client)

m = Map(location=client.center(), zoom_start=16)
m.add_child(t)
Expand All @@ -131,5 +134,5 @@ If filing a bug report, please share a scooby ``Report``:

.. code:: python
import localtileserver
print(localtileserver.Report())
import localtileserver as lts
print(lts.Report())
5 changes: 3 additions & 2 deletions doc/source/user-guide/ipyleaflet_deep_zoom.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ For more information, please see https://github.com/jupyter-widgets/ipyleaflet/i

.. jupyter-execute::

from localtileserver import get_leaflet_tile_layer, examples
import localtileserver as lts
from localtileserver import examples
from ipyleaflet import Map, TileLayer

# Load high res raster
Expand All @@ -20,7 +21,7 @@ For more information, please see https://github.com/jupyter-widgets/ipyleaflet/i
max_zoom = 30

# Create zoomable tile layer from high res raster
layer = get_leaflet_tile_layer(client,
layer = lts.get_leaflet_tile_layer(client,
# extra kwargs to pass to the TileLayer
max_zoom=max_zoom,
max_native_zoom=max_zoom,
Expand Down
6 changes: 3 additions & 3 deletions doc/source/user-guide/rasterio.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ This will only work when opening a raster in read-mode.
.. code-block:: python
import rasterio
import localtileserver as lts
from ipyleaflet import Map
from localtileserver import TileClient, get_leaflet_tile_layer
src = rasterio.open('path/to/geo.tif')
client = TileClient(src)
client = lts.TileClient(src)
t = get_leaflet_tile_layer(client)
t = lts.get_leaflet_tile_layer(client)
m = Map(center=client.center(), zoom=client.default_zoom)
m.add(t)
Expand Down
9 changes: 4 additions & 5 deletions doc/source/user-guide/remote-cog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,21 @@ we can view tiles of the remote file very efficiently in a Jupyter notebook.

.. jupyter-execute::

from localtileserver import get_folium_tile_layer, get_leaflet_tile_layer
from localtileserver import TileClient
import localtileserver as lts
import folium, ipyleaflet

url = 'https://github.com/giswqs/data/raw/main/raster/landsat7.tif'

# First, create a tile server from the URL raster file
client = TileClient(url)
client = lts.open(url)


Here we can create a folium map with the raster overlain:

.. jupyter-execute::

# Create folium tile layer from that server
t = get_folium_tile_layer(client)
t = lts.get_folium_tile_layer(client)

m = folium.Map(location=client.center(), zoom_start=client.default_zoom)
m.add_child(t)
Expand All @@ -40,7 +39,7 @@ Or we can do the same ipyleaflet:
.. jupyter-execute::

# Create ipyleaflet tile layer from that server
l = get_leaflet_tile_layer(client)
l = lts.get_leaflet_tile_layer(client)

m = ipyleaflet.Map(center=client.center(), zoom=client.default_zoom)
m.add(l)
Expand Down
7 changes: 4 additions & 3 deletions doc/source/user-guide/rgb.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ viewing a different set of bands:

.. jupyter-execute::

from localtileserver import get_leaflet_tile_layer, examples
import localtileserver as lts
from localtileserver import examples
from ipyleaflet import Map, ScaleControl, FullScreenControl, SplitMapControl

# First, create TileClient using example file
Expand All @@ -30,8 +31,8 @@ viewing a different set of bands:
.. jupyter-execute::

# Create 2 tile layers from same raster viewing different bands
l = get_leaflet_tile_layer(client, indexes=[7, 5, 4])
r = get_leaflet_tile_layer(client, indexes=[5, 3, 2])
l = lts.get_leaflet_tile_layer(client, indexes=[7, 5, 4])
r = lts.get_leaflet_tile_layer(client, indexes=[5, 3, 2])

# Make the ipyleaflet map
m = Map(center=client.center(), zoom=client.default_zoom)
Expand Down
9 changes: 5 additions & 4 deletions doc/source/user-guide/validate_cog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,23 @@ You can use the script by:

.. jupyter-execute::

from localtileserver import validate_cog
import localtileserver as lts

# Path to raster (URL or local path)
url = 'https://github.com/giswqs/data/raw/main/raster/landsat7.tif'

# If invalid, returns False
validate_cog(url)
lts.validate_cog(url)


This can also be used with an existing :class:`localtileserver.TileClient`:

.. jupyter-execute::

from localtileserver import examples, validate_cog
import localtileserver as lts
from localtileserver import examples

client = examples.get_san_francisco()

# If invalid, returns False
validate_cog(client)
lts.validate_cog(client)
Loading

0 comments on commit 6bb746c

Please sign in to comment.