Skip to content

56 download ned

image image image

Downloading 10-m National Elevation Dataset (NED) with only one line of code

1
# !pip install leafmap
1
# !pip install geopandas rasterio
1
2
3
4
import os
import leafmap
import shutil
import sys
1
2
m = leafmap.Map(center=[40, -100], zoom=4)
m
1
2
3
4
region = m.user_roi_bounds()
if region is None:
    region = [-115.9689, 35.9758, -115.3619, 36.4721]
print(region)
1
leafmap.download_ned(region, return_url=True)
1
2
out_dir = "data"
os.makedirs(out_dir, exist_ok=True)
1
2
if "google.colab" in sys.modules:
    leafmap.download_ned(region, out_dir)
1
2
3
if "google.colab" in sys.modules:
    mosaic = "mosaic.tif"
    leafmap.mosaic(images=out_dir, output=mosaic)
1
2
3
if "google.colab" in sys.modules and (m.user_roi is not None):
    image = "dem.tif"
    leafmap.clip_image(mosaic, mask=m.user_roi, output=image)
1
2
3
out_dir = "/content/drive/MyDrive/Data"
if os.path.exists(out_dir) and os.path.exists(image):
    shutil.copyfile(image, os.path.join(out_dir, image))