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

Update get_3dep functions #908

Merged
merged 1 commit into from
Oct 2, 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
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