diff --git a/docs/notebooks/90_pixel_inspector.ipynb b/docs/notebooks/90_pixel_inspector.ipynb index 5f68efbce4..82e65d36e0 100644 --- a/docs/notebooks/90_pixel_inspector.ipynb +++ b/docs/notebooks/90_pixel_inspector.ipynb @@ -34,7 +34,9 @@ "outputs": [], "source": [ "import leafmap\n", - "import rasterio" + "import rasterio\n", + "import rioxarray\n", + "import xarray as xr" ] }, { @@ -146,7 +148,9 @@ "id": "12", "metadata": {}, "source": [ - "## In-memory raster" + "## In-memory raster\n", + "\n", + "### NumPy array" ] }, { @@ -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)" ] diff --git a/examples/notebooks/90_pixel_inspector.ipynb b/examples/notebooks/90_pixel_inspector.ipynb index 5f68efbce4..82e65d36e0 100644 --- a/examples/notebooks/90_pixel_inspector.ipynb +++ b/examples/notebooks/90_pixel_inspector.ipynb @@ -34,7 +34,9 @@ "outputs": [], "source": [ "import leafmap\n", - "import rasterio" + "import rasterio\n", + "import rioxarray\n", + "import xarray as xr" ] }, { @@ -146,7 +148,9 @@ "id": "12", "metadata": {}, "source": [ - "## In-memory raster" + "## In-memory raster\n", + "\n", + "### NumPy array" ] }, { @@ -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)" ] diff --git a/leafmap/common.py b/leafmap/common.py index 8253865b4e..3c26860488 100644 --- a/leafmap/common.py +++ b/leafmap/common.py @@ -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() diff --git a/leafmap/deckgl.py b/leafmap/deckgl.py index 9b85add7d0..80949b9796 100644 --- a/leafmap/deckgl.py +++ b/leafmap/deckgl.py @@ -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)