Current Behavior
Currently, BigMap only supports rectangular bounding boxes for data downloads, even when using county boundaries. When a user specifies a county, the system:
- Loads the county polygon geometry
- Extracts the rectangular bounding box using
gdf.total_bounds
- Downloads data for the entire rectangle
- The actual polygon boundary is discarded
This means users get data for areas outside their region of interest (e.g., downloading a rectangular bbox for an irregularly-shaped county includes areas outside the county).
Proposed Enhancement
Add support for custom polygon boundaries that:
- Accept polygon input from multiple sources:
- GeoJSON files
- Shapefiles
- GeoDataFrame objects
- WKT strings
- Use the polygon's bounding box for the initial download
- Automatically clip/mask the downloaded data to the actual polygon boundary after download
- Preserve the polygon geometry in the Zarr store metadata for visualization
Use Cases
- Analyzing forest metrics for specific counties without including surrounding areas
- Custom study areas that follow watershed boundaries, ecological regions, or administrative boundaries
- Research projects requiring precise spatial boundaries for statistical analysis
- Reducing storage and processing requirements by excluding irrelevant data
API Design Proposal
from bigmap import BigMapAPI
from pathlib import Path
api = BigMapAPI()
# Option 1: From file
files = api.download_species(
polygon="/path/to/boundary.geojson",
species_codes=["0202"],
clip_to_polygon=True # Default: True
)
# Option 2: From GeoDataFrame
import geopandas as gpd
polygon_gdf = gpd.read_file("boundary.shp")
files = api.download_species(
polygon=polygon_gdf,
species_codes=["0202"]
)
# Option 3: Enhanced county/state (use actual boundary, not bbox)
files = api.download_species(
state="Oregon",
county="Lane",
use_boundary_clip=True # Use actual county shape, not just bbox
)
Implementation Considerations
- Download: Still use rectangular bbox for REST API calls (server limitation)
- Post-processing: Apply polygon mask after download using
rasterio.mask.mask() or similar
- Zarr storage: Store clipped arrays with polygon boundary in metadata
- Performance: Add option to skip clipping for performance-critical workflows
- Validation: Ensure polygon CRS matches or can be transformed to match data CRS
- Visualization: Use stored polygon boundary for map overlays
Related Code
bigmap/utils/location_config.py:197-229 - County config setup
bigmap/utils/location_config.py:254-279 - Bounding box extraction
bigmap/api.py:133-231 - Download species method
bigmap/external/fia_client.py - REST client (bbox-based downloads)
References
Current Behavior
Currently, BigMap only supports rectangular bounding boxes for data downloads, even when using county boundaries. When a user specifies a county, the system:
gdf.total_boundsThis means users get data for areas outside their region of interest (e.g., downloading a rectangular bbox for an irregularly-shaped county includes areas outside the county).
Proposed Enhancement
Add support for custom polygon boundaries that:
Use Cases
API Design Proposal
Implementation Considerations
rasterio.mask.mask()or similarRelated Code
bigmap/utils/location_config.py:197-229- County config setupbigmap/utils/location_config.py:254-279- Bounding box extractionbigmap/api.py:133-231- Download species methodbigmap/external/fia_client.py- REST client (bbox-based downloads)References
rasterio.mask.mask()- https://rasterio.readthedocs.io/en/stable/api/rasterio.mask.html