Skip to content

Commit

Permalink
Update get_3dep functions (#908)
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs authored Oct 2, 2024
1 parent a9d1f96 commit 5129543
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion leafmap/basemaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,13 @@
# Custom WMS tile services.
WMS_TILES = {
"FWS NWI Wetlands": {
"url": "https://fwspublicservices.wim.usgs.gov/wetlandsmapservice/services/Wetlands/MapServer/WMSServer?",
"url": "https://www.fws.gov/wetlandsmapservice/services/Wetlands/MapServer/WMSServer?",
"layers": "1",
"name": "FWS NWI Wetlands",
"attribution": "FWS",
"format": "image/png",
"transparent": True,
"max_zoom": 30,
},
"FWS NWI Wetlands Raster": {
"url": "https://fwspublicservices.wim.usgs.gov/wetlandsmapservice/services/WetlandsRaster/ImageServer/WMSServer?",
Expand Down
15 changes: 12 additions & 3 deletions leafmap/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -9824,7 +9824,7 @@ def get_nhd_basins(
def get_3dep_dem(
geometry,
resolution=30,
src_crs="EPSG:4326",
src_crs=None,
output=None,
dst_crs="EPSG:5070",
to_cog=False,
Expand Down Expand Up @@ -9852,6 +9852,7 @@ def get_3dep_dem(
except ImportError:
print("py3dep is not installed. Installing py3dep...")
install_package("py3dep")
import py3dep

import geopandas as gpd

Expand All @@ -9860,8 +9861,13 @@ def get_3dep_dem(
return

if isinstance(geometry, gpd.GeoDataFrame):
if src_crs is None:
src_crs = geometry.crs
geometry = geometry.geometry.unary_union

if src_crs is None:
src_crs = "EPSG:4326"

dem = py3dep.get_dem(geometry, resolution=resolution, crs=src_crs)
dem = dem.rio.reproject(dst_crs)

Expand All @@ -9871,7 +9877,10 @@ def get_3dep_dem(
dem.rio.to_raster(output, **kwargs)

if to_cog:
image_to_cog(output, output)
try:
image_to_cog(output, output)
except Exception as e:
print(e)

return dem

Expand Down Expand Up @@ -9951,7 +9960,7 @@ def coords_to_vector(coords, output=None, crs="EPSG:4326", **kwargs):
import geopandas as gpd
from shapely.geometry import Point

if not isinstance(coords, list):
if not isinstance(coords, (list, tuple)):
raise TypeError("coords must be a list of coordinates")

if isinstance(coords[0], int) or isinstance(coords[0], float):
Expand Down

0 comments on commit 5129543

Please sign in to comment.