A REST API for the City of Vancouver's public tree dataset, providing fast geospatial queries via PostGIS.
This API exposes Vancouver's cleaned street tree inventory (~180,000 trees) through a clean REST interface. It supports standard filtering, pagination, and three types of spatial queries using PostGIS: bounding box, radius search, and nearest neighbor.
pip install -r requirements.txtSet DATABASE_URL in .env pointing to a PostgreSQL database with PostGIS enabled.
Run the data ingestion script to populate the database:
python ingenstion.pyStart the server:
uvicorn main:app --reloadBase URL: /api/v1
| Endpoint | Description |
|---|---|
GET /health |
Liveness check |
GET /health/db |
Database connectivity check |
GET /trees
Query parameters:
limit(int, default 50, max 100)offset(int, default 0)species- filter by species namegenus- filter by genus namecommon_name- filter by common nameneighborhood- filter by neighbourhoodmin_height/max_height- filter by height range IDplanted_after/planted_before- filter by planting date (YYYY-MM-DD)
Response:
{
"metadata": { "limit": 50, "offset": 0, "total": 181000 },
"data": [
{
"id": 123,
"genus_name": "ACER",
"species_name": "RUBRUM",
"common_name": "RED MAPLE",
"height_range_id": 2,
"geometry": { "type": "Point", "coordinates": [-123.1, 49.2] }
}
]
}GET /trees/{tree_id}
Returns full tree details including civic address, diameter, and planting date.
GET /trees/count
Returns total number of trees in the database.
GET /trees/search
Three mutually exclusive modes:
Bounding Box
?bbox=minLon,minLat,maxLon,maxLat
Radius Search
?coordinates=lat,lon&radius=500
Radius in meters.
Nearest Neighbor
?nearest=lat,lon&count=10
Returns N closest trees (max 100).
All modes support limit parameter (default 50, max 100).
GET /species
Returns list of all distinct species in the dataset.
main.py # FastAPI app entry point
api/
db.py # Database connection
health.py # Health check endpoints
trees.py # Tree CRUD endpoints
search.py # Geospatial search endpoint
species.py # Species list endpoint
ingenstion.py # Data ingestion script
Tree data sourced from Vancouver Open Data Portal.
- FastAPI
- PostgreSQL + PostGIS
- SQLAlchemy
