{ "cells": [ { "metadata": {}, "cell_type": "markdown", "source": [ "# Building-to-Service Travel Time Matrix with Intermodal Graph\n", "This notebook demonstrates how to compute a time-based adjacency matrix between two GeoDataFrames\n", "(e.g., buildings and services) using a multimodal transport graph.\n", "\n", "The method utilizes the `IduEdu` library to:\n", "- Construct a multimodal graph (e.g., walk + public transport)\n", "- Calculate travel time-based adjacency matrix from one GeoDataFrame to another\n", "\n", "This matrix can be used in `ObjectNat` for further service provision analysis." ], "id": "9ca78071b77f245e" }, { "metadata": { "ExecuteTime": { "end_time": "2026-07-10T10:05:29.962538Z", "start_time": "2026-07-10T10:05:29.959041Z" } }, "cell_type": "code", "source": [ "# %%\n", "# Install required packages (uncomment if needed)\n", "# !pip install iduedu pyarrow" ], "id": "a3fd404cc3b83edd", "outputs": [], "execution_count": 1 }, { "metadata": { "ExecuteTime": { "end_time": "2026-07-10T10:05:38.142935Z", "start_time": "2026-07-10T10:05:30.282064Z" } }, "cell_type": "code", "source": [ "# Import necessary libraries\n", "from iduedu import get_intermodal_graph, od_matrix\n", "import geopandas as gpd\n", "import pandas as pd\n", "from shapely.ops import unary_union\n" ], "id": "9a3e15f423bedc31", "outputs": [], "execution_count": 2 }, { "metadata": {}, "cell_type": "markdown", "source": [ "## 1. Load Input Geospatial Data\n", "Load the GeoDataFrames of buildings (origins) and services (destinations).\n" ], "id": "68af599b21a7895d" }, { "metadata": { "ExecuteTime": { "end_time": "2026-07-10T10:05:38.217274Z", "start_time": "2026-07-10T10:05:38.158957Z" } }, "cell_type": "code", "source": [ "# Read building and service datasets\n", "buildings = gpd.read_parquet('examples_data/buildings.parquet')\n", "services = gpd.read_parquet('examples_data/services.parquet')" ], "id": "ecaca9093632eb44", "outputs": [], "execution_count": 3 }, { "metadata": {}, "cell_type": "markdown", "source": [ "## 2. Create Coverage Polygon for Graph Download\n", "Compute a polygon that encompasses both datasets to define the spatial extent for graph download.\n", "This is done by computing a convex hull over all geometries and buffering it slightly.\n" ], "id": "5146507282cd8082" }, { "metadata": { "ExecuteTime": { "end_time": "2026-07-10T10:05:39.037844Z", "start_time": "2026-07-10T10:05:38.219279Z" } }, "cell_type": "code", "source": [ "polygon = unary_union(\n", " buildings.to_crs(4326).geometry.to_list() + services.to_crs(4326).geometry.to_list()\n", ").convex_hull.buffer(0.001)" ], "id": "74e684470ea483a1", "outputs": [], "execution_count": 4 }, { "metadata": {}, "cell_type": "markdown", "source": [ "## 3. Download and Clip Intermodal Graph\n", "Download the intermodal (multi-modal) network graph using the defined polygon.\n", "This includes walking paths and public transport networks." ], "id": "b6b58fffdd714d38" }, { "metadata": { "ExecuteTime": { "end_time": "2026-07-10T10:05:42.788008Z", "start_time": "2026-07-10T10:05:39.050329Z" } }, "cell_type": "code", "source": [ "# Load multimodal graph clipped to polygon\n", "G_intermodal = get_intermodal_graph(territory=polygon, clip_by_territory=True)" ], "id": "1e643d3fdc052876", "outputs": [ { "data": { "text/plain": [ "Parsing ground PT routes: 0%| | 0/57 [00:00