feat[pmtiles]: support multiple shapes per routes#1365
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the PMTiles builder to support multiple route shapes by allowing routes to have multiple shape_ids with associated trip_ids. The main purpose is to handle cases where a single route can have different shapes for different trips.
- Transforms route-to-shape relationship from single shape_id to multiple shapes with trip associations
- Adds support for trips without shapes by falling back to stop coordinates
- Improves error handling and data validation using safe value getters
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| functions-python/pmtiles_builder/src/main.py | Core refactoring to support multiple route shapes with new RouteCoordinates type and get_route_coordinates method |
| functions-python/pmtiles_builder/src/csv_cache.py | Updates CsvCache to track multiple shapes per route and trips without shapes |
| functions-python/pmtiles_builder/src/gtfs_stops_to_geojson.py | Replaces direct row access with safe value getters for better data validation |
| functions-python/helpers/transform.py | Adds get_safe_int function and improves type hints for existing safe value functions |
| functions-python/helpers/tests/test_transform.py | Adds unit tests for the new get_safe_int function |
| functions-python/pmtiles_builder/src/scripts/pmtiles_builder_verifier.py | New verification script for testing PMTiles builder functionality |
| functions-python/pmtiles_builder/requirements_dev.txt | Adds development dependencies for testing and emulation |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
davidgamez
marked this pull request as ready for review
September 22, 2025 18:32
jcpitre
reviewed
Sep 23, 2025
jcpitre
reviewed
Sep 23, 2025
jcpitre
reviewed
Sep 23, 2025
jcpitre
reviewed
Sep 23, 2025
jcpitre
reviewed
Sep 23, 2025
jcpitre
reviewed
Sep 23, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
This PR adds support for multiple shapes per route. No additional information has been added to the routes.json regarding shapes.
Expected behavior:
All shapes are represented in the pmtiles.
Left image, one shape per route. Right image, multiple shapes per route.

From our AI friend
This pull request introduces improvements to the GTFS CSV caching and GeoJSON conversion logic, focusing on safer data extraction, more robust handling of missing or malformed data, and enhanced support for routes with multiple shapes and trips. The most important changes are grouped below.
Data Extraction and Safety Improvements
get_safe_inthelper for safely extracting integer values, and updatedget_safe_valueandget_safe_floatto use explicit type hints for better type safety. [1] [2] [3] [4]gtfs_stops_to_geojson.pyandmain.pyto consistently useget_safe_valueandget_safe_floatfor extracting values from CSV rows, reducing the risk of exceptions and ensuring missing or malformed data is handled gracefully. [1] [2] [3] [4] [5] [6]Route and Shape Handling Enhancements
CsvCache:get_shape_from_routenow returns all shape IDs and their associated trips for a route, and added tracking of trips without shapes. This enables more accurate representation of GTFS data where multiple shapes or trips may exist per route. [1] [2] [3]main.pyto support multiple shapes and trips per route. Each route feature now includes shape and trip information, and falls back to using stops when shape data is missing. [1] [2] [3]Type Hints and Structure
ShapeTrips,RouteCoordinates) and added type hints throughout the codebase for improved readability and static analysis. [1] [2] [3]Dependency Updates
psutil,gcp_storage_emulator) torequirements_dev.txtfor enhanced testing and local development.Testing tips:
Provide tips, procedures and sample files on how to test the feature.
Testers are invited to follow the tips AND to try anything they deem relevant outside the bounds of the testing tips.
Please make sure these boxes are checked before submitting your pull request - thanks!
./scripts/api-tests.shto make sure you didn't break anything