In [ ]:
Copied!
# %pip install geoai-py
# %pip install geoai-py
Import Libraries¶
These modules allow downloading NAIP imagery and extracting building data statistics.
In [ ]:
Copied!
import leafmap
from geoai.download import (
download_naip,
download_overture_buildings,
extract_building_stats,
)
import leafmap
from geoai.download import (
download_naip,
download_overture_buildings,
extract_building_stats,
)
Define Bounding Box¶
Define the geographic extent (longitude and latitude) for data downloads.
In [ ]:
Copied!
m = leafmap.Map(center=[47.6526, -117.5923], zoom=16)
m.add_basemap("Google Satellite")
m
m = leafmap.Map(center=[47.6526, -117.5923], zoom=16)
m.add_basemap("Google Satellite")
m
Use the drawing tools to draw a rectangle on the map. If no rectangle is drawn, the default ROI will be used.
In [ ]:
Copied!
bbox = m.user_roi_bounds()
if bbox is None:
bbox = (-117.6029, 47.65, -117.5936, 47.6563)
bbox = m.user_roi_bounds()
if bbox is None:
bbox = (-117.6029, 47.65, -117.5936, 47.6563)
Download NAIP Imagery¶
Fetch NAIP aerial imagery for the specified bounding box. The max_items
parameter limits the number of downloaded files.
In [ ]:
Copied!
# Download NAIP imagery for the specified region
downloaded_files = download_naip(
bbox=bbox,
output_dir="naip_data",
max_items=1,
# year=2020,
)
print(f"Downloaded {len(downloaded_files)} files.")
# Download NAIP imagery for the specified region
downloaded_files = download_naip(
bbox=bbox,
output_dir="naip_data",
max_items=1,
# year=2020,
)
print(f"Downloaded {len(downloaded_files)} files.")
Download Building Data¶
Retrieve building footprint data in GeoJSON format within the bounding box. The verbose
flag provides detailed output.
In [ ]:
Copied!
# Download buildings
data_file = download_overture_buildings(
bbox=bbox,
output="buildings.geojson",
)
# Download buildings
data_file = download_overture_buildings(
bbox=bbox,
output="buildings.geojson",
)
Extract Building Statistics¶
If the building data file is successfully downloaded, extract and display relevant statistics such as area, count, and footprint details.
In [ ]:
Copied!
stats = extract_building_stats(data_file)
print(stats)
stats = extract_building_stats(data_file)
print(stats)
Visualize Datasets¶
In [ ]:
Copied!
m = leafmap.Map()
m.add_raster("naip_data/m_4711720_sw_11_060_20230701_20230911.tif", layer_name="NAIP")
m.add_geojson("buildings.geojson", layer_name="Buildings")
m
m = leafmap.Map()
m.add_raster("naip_data/m_4711720_sw_11_060_20230701_20230911.tif", layer_name="NAIP")
m.add_geojson("buildings.geojson", layer_name="Buildings")
m