Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deckgl compute_view bug #693

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 91 additions & 2 deletions docs/notebooks/90_pixel_inspector.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
"outputs": [],
"source": [
"import leafmap\n",
"import rasterio"
"import rasterio\n",
"import rioxarray\n",
"import xarray as xr"
]
},
{
Expand Down Expand Up @@ -146,7 +148,9 @@
"id": "12",
"metadata": {},
"source": [
"## In-memory raster"
"## In-memory raster\n",
"\n",
"### NumPy array"
]
},
{
Expand Down Expand Up @@ -181,6 +185,91 @@
"cell_type": "markdown",
"id": "15",
"metadata": {},
"source": [
"### Xarray DataArray"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "16",
"metadata": {},
"outputs": [],
"source": [
"url = \"https://open.gishub.org/data/raster/srtm90.tif\"\n",
"dem = leafmap.download_file(url, \"srtm90.tif\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "17",
"metadata": {},
"outputs": [],
"source": [
"ds = rioxarray.open_rasterio(dem)\n",
"ds"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "18",
"metadata": {},
"outputs": [],
"source": [
"array = ds.sel(band=1)\n",
"masked_array = xr.where(array < 2000, 0, 1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "19",
"metadata": {},
"outputs": [],
"source": [
"m = leafmap.Map()\n",
"m.add_raster(dem, colormap=\"terrain\", layer_name=\"DEM\")\n",
"m.add_raster(masked_array, colormap=\"coolwarm\", layer_name=\"Classified DEM\")\n",
"m"
]
},
{
"cell_type": "markdown",
"id": "20",
"metadata": {},
"source": [
"## Split map"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "21",
"metadata": {},
"outputs": [],
"source": [
"m = leafmap.Map(center=[37.6, -119], zoom=9)\n",
"m.split_map(\n",
" dem,\n",
" masked_array,\n",
" left_args={\n",
" \"layer_name\": \"DEM\",\n",
" \"colormap\": \"terrain\",\n",
" },\n",
" right_args={\n",
" \"layer_name\": \"Classified DEM\",\n",
" \"colormap\": \"coolwarm\",\n",
" },\n",
")\n",
"m"
]
},
{
"cell_type": "markdown",
"id": "22",
"metadata": {},
"source": [
"![](https://i.imgur.com/2AduU8G.gif)"
]
Expand Down
93 changes: 91 additions & 2 deletions examples/notebooks/90_pixel_inspector.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
"outputs": [],
"source": [
"import leafmap\n",
"import rasterio"
"import rasterio\n",
"import rioxarray\n",
"import xarray as xr"
]
},
{
Expand Down Expand Up @@ -146,7 +148,9 @@
"id": "12",
"metadata": {},
"source": [
"## In-memory raster"
"## In-memory raster\n",
"\n",
"### NumPy array"
]
},
{
Expand Down Expand Up @@ -181,6 +185,91 @@
"cell_type": "markdown",
"id": "15",
"metadata": {},
"source": [
"### Xarray DataArray"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "16",
"metadata": {},
"outputs": [],
"source": [
"url = \"https://open.gishub.org/data/raster/srtm90.tif\"\n",
"dem = leafmap.download_file(url, \"srtm90.tif\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "17",
"metadata": {},
"outputs": [],
"source": [
"ds = rioxarray.open_rasterio(dem)\n",
"ds"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "18",
"metadata": {},
"outputs": [],
"source": [
"array = ds.sel(band=1)\n",
"masked_array = xr.where(array < 2000, 0, 1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "19",
"metadata": {},
"outputs": [],
"source": [
"m = leafmap.Map()\n",
"m.add_raster(dem, colormap=\"terrain\", layer_name=\"DEM\")\n",
"m.add_raster(masked_array, colormap=\"coolwarm\", layer_name=\"Classified DEM\")\n",
"m"
]
},
{
"cell_type": "markdown",
"id": "20",
"metadata": {},
"source": [
"## Split map"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "21",
"metadata": {},
"outputs": [],
"source": [
"m = leafmap.Map(center=[37.6, -119], zoom=9)\n",
"m.split_map(\n",
" dem,\n",
" masked_array,\n",
" left_args={\n",
" \"layer_name\": \"DEM\",\n",
" \"colormap\": \"terrain\",\n",
" },\n",
" right_args={\n",
" \"layer_name\": \"Classified DEM\",\n",
" \"colormap\": \"coolwarm\",\n",
" },\n",
")\n",
"m"
]
},
{
"cell_type": "markdown",
"id": "22",
"metadata": {},
"source": [
"![](https://i.imgur.com/2AduU8G.gif)"
]
Expand Down
3 changes: 2 additions & 1 deletion leafmap/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -12810,7 +12810,8 @@ def gedi_download_files(
password = os.environ.get("EARTHDATA_PASSWORD", None)

if username is None or password is None:
raise ValueError("Username and password must be provided.")
print("Username and password must be provided.")
return

if outdir is None:
outdir = os.getcwd()
Expand Down
9 changes: 6 additions & 3 deletions leafmap/deckgl.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,13 @@ def add_gdf(
self.layers = self.layers + [layer]

if zoom_to_layer:
from lonboard._viewport import compute_view

try:
self._initial_view_state = compute_view([self.layers[-1].table])
bounds = gdf.total_bounds.tolist()
self._initial_view_state = {
"latitude": (bounds[1] + bounds[3]) / 2,
"longitude": (bounds[0] + bounds[2]) / 2,
"zoom": 10,
}
except Exception as e:
print(e)

Expand Down
Loading