TerraFetch is a Python library for fetching and analyzing geospatial data from various public APIs.
You can install the latest version of terrafetch directly from the GitHub repository using pip.
pip install git+https://github.com/naxa-developers/terra-fetch.gitkathmandu_polygon = {
"type": "Polygon",
"coordinates": [
[
[85.30, 27.70], # Southwest corner
[85.32, 27.70], # Southeast corner
[85.32, 27.72], # Northeast corner
[85.30, 27.72], # Northwest corner
[85.30, 27.70] # Closing the loop
]
]
}import json
from terrafetch import Topography
try:
print("-> Analyzing Topography...")
topo_analyzer = Topography(kathmandu_polygon)
# To download the clipped raster, add: download_path="output/elevation.tif"
topo_summary = topo_analyzer.get_summary()
print(json.dumps(topo_summary, indent=2))
except Exception as e:
print(f"ERROR: Topography analysis failed: {e}")- terrafetch.Topography: Calculates area and elevation range (NASADEM).
- terrafetch.BuildingFootprints: Counts building footprints (Microsoft Building Footprints).
- terrafetch.LandUseCover: Analyzes land use percentages (ESA WorldCover).
- terrafetch.Demographics: Estimates population from WorldPop data.
- terrafetch.CriticalInfrastructure: Counts amenities and roads from OpenStreetMap.
- terrafetch.NasaClimate: Provides climate summaries (temperature, precipitation) from NASA NEX-GDDP-CMIP6.
- terrafetch.DisasterEvents: Fetches historical disaster events (USGS, GDACS, EONET).
- terrafetch.JrcFlood: Provides flood depth information for various return periods.
import asyncio
from terrafetch.hazard import JrcFloodConnector
from terrafetch.models import Point
async def run_hazard_analysis():
try:
print("-> Analyzing Flood Hazard...")
jrc_connector = JrcFloodConnector(return_period=100)
point = Point(lat=27.7172, lon=85.3240) # Kathmandu
flood_depth = await jrc_connector.get_value_at_point_async(point)
print(f"Flood depth at {point}: {flood_depth:.2f} meters")
except Exception as e:
print(f"ERROR: Flood hazard analysis failed: {e}")
if __name__ == "__main__":
asyncio.run(run_hazard_analysis())