Skip to content

Migrate all dependencies to geozero#113

Merged
robfitzgerald merged 7 commits intomainfrom
copilot/migrate-to-geozero
Mar 13, 2026
Merged

Migrate all dependencies to geozero#113
robfitzgerald merged 7 commits intomainfrom
copilot/migrate-to-geozero

Conversation

Copy link
Contributor

Copilot AI commented Mar 12, 2026

Migrates bambam from individual geospatial crates (wkt, wkb, geojson) to geozero, a unified geospatial format library. This simplifies versioning and APIs for geospatial data formats across the codebase.

Changes Made

Cargo.toml Updates

  • Workspace: Removed wkt, wkb, geojson; added geozero with features with-geo, with-wkb, with-wkt, with-geojson
  • bambam-osm: Added geozero = { workspace = true } (was missing)
  • All other crates (bambam, bambam-core, bambam-gtfs, bambam-omf): removed wkt/wkb/geojson dependencies

Source File Migrations

Old API New API
wkt::ToWkt.to_wkt().to_string() geozero::ToWkt.to_wkt() returning Result<String>
Geometry::try_from_wkt_str(s) WktReader(s).to_geo()
wkt::Wkt<f32>::parse() + .try_into() WktReader(s).to_geo() + map coords to f32
wkb::writer::write_geometry(...) geom.to_wkb(CoordDimensions::xy())
geojson::GeoJson::parse() + geo_types::Geometry::try_from() GeoJsonString(s).to_geo()
geojson::Geometry::from() wrapped in geojson::Feature geom.to_json() wrapped in serde_json::json! Feature

Key technical note: geozero::ToWkt only implements GeozeroGeometry for Geometry<f64>. Geometries stored as f32 (used in several OSM and OMF paths) are converted with geo::Convert before calling to_wkt().

GeoJSON roundtrip: The GeoJSON deserializer now handles Feature-wrapped JSON by extracting the geometry field before passing to GeoJsonString, since geozero's parser requires a plain geometry JSON string.

Unit Tests Added

New tests covering geozero usage without large mock data:

  • isochrone_output_format: WKT, WKB, and GeoJSON serialize/deserialize roundtrips; empty geometry; invalid input error cases
  • extent_format: WKT polygon and multipolygon parsing; invalid WKT error case
  • grid_ops: create_grid_row with polygon geometry; invalid template error case
  • us_states_lookup: embedded GeoJSON state file load; GeoJsonString geometry parse

Code Quality

  • Ran cargo fmt across the rust/ directory
  • Ran cargo clippy --fix across the rust/ directory
  • All unit tests pass (cargo test --lib)

📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Co-authored-by: robfitzgerald <7003022+robfitzgerald@users.noreply.github.com>
@robfitzgerald
Copy link
Collaborator

@copilot please try again now that the copilot rate limit has been addressed. i have added two additional criteria to the list, run cargo fmt and cargo clippy --fix, for acceptance. thank you!

…ests, run fmt and clippy

Co-authored-by: robfitzgerald <7003022+robfitzgerald@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 12, 2026

@copilot please try again now that the copilot rate limit has been addressed. i have added two additional criteria to the list, run cargo fmt and cargo clippy --fix, for acceptan...

Completed the migration in commit a5210de. Here's what was done:

Remaining source files migrated:

  • bambam-omf: omf_graph.rs (ToWkt), geometry_wkb_codec.rs (wkb::writer → geozero ToWkb), omf_app.rs (wkt::Wkt parsing)
  • bambam-gtfs: operation.rs (ToWkt + TryFromWkt), bundle_ops.rs (ToWkt)
  • bambam-osm: osm_way_ops.rs (wkt::Wkt parse + ToWkt), osm_way_data_serializable.rs, osm_graph_vectorized.rs, compass_writer.rs, clustering_rtree.rs (ToWkt), osm_source.rs (TryFromWkt)

Key technical notes:

  • geozero::ToWkt only works on Geometry<f64>, so f32 geometries are converted with geo::Convert first
  • GeoJSON Feature deserialization now extracts the geometry field before passing to GeoJsonString (avoids geozero failing on "id": null)
  • geozero::wkb::Wkb(bytes).to_geo() replaces wkb::reader::read_wkb

Unit tests added for: isochrone_output_format (WKT/WKB/GeoJSON roundtrip), extent_format (WKT parse), grid_ops (create_grid_row), us_states_lookup (embedded GeoJSON load + GeoJsonString parse)

Also ran: cargo fmt and cargo clippy --fix as requested.

Copilot AI changed the title [WIP] Migrate all dependencies to geozero Migrate all dependencies to geozero Mar 12, 2026
Copilot AI requested a review from robfitzgerald March 12, 2026 17:08
@robfitzgerald robfitzgerald marked this pull request as ready for review March 12, 2026 19:06
Copy link
Collaborator

@yamilbknsu yamilbknsu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes make sense and they compile. Thank you!

@robfitzgerald robfitzgerald merged commit 132d00f into main Mar 13, 2026
1 check passed
@robfitzgerald robfitzgerald deleted the copilot/migrate-to-geozero branch March 13, 2026 22:34
@robfitzgerald robfitzgerald mentioned this pull request Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants