Module ltn::save::perma

source · []
Expand description

The Proposal struct references IntersectionIDs and RoadIDs, which won’t survive OSM updates. Similar to the MapEdits <-> PermanentMapEdits strategy, transform those IDs before saving.

Unlike PermanentMapEdits, we don’t define a PermanentProposal struct, because to do so for everything it includes would be a nightmare. In particular, Partitioning includes Blocks, which nest RoadIDs deep inside. Instead, play a “runtime reflection” trick:

  1. Serialize the Proposal with RoadIDs to JSON
  2. Dynamically walk the JSON
  3. When the path of a value matches the hardcoded list of patterns in is_road_id and is_intersection_id, transform to a permanent ID
  4. Save the proposal as JSON with that ID instead
  5. Do the inverse to later load

In practice, this attempt to keep proposals compatible with future basemap updates might be futile. We’re embedding loads of details about the partitioning, but not checking that they remain valid after loading. Even splitting one road in two anywhere in the map would likely break things kind of silently. Absolute worst case, we also record an abst_version field so we could manually load the proposal in the correct version, and do something to manually recover an old proposal.

Also, the JSON blobs are massive because of the partitioning, so compress everything.

Functions