# RestMap OSM derived-database format, schema 2

Both SQLite files are ordinary read-only databases with `PRAGMA user_version=2`.
Their matching JSON manifests identify the OSM snapshot, exact output SHA-256, filters, tool versions and attribution.
The separate databases contain only OSM-derived records and a US Census-derived coverage mask in the manifests.

## Junctions

`junctions.id` is the positive OSM node ID.
`lat_e7` and `lon_e7` are integer latitude/longitude in units of 1e-7 degrees.
`ref`, `name` and the JSON `tags` retain the conservative exit label and source evidence.
`junction_rtree` is an approximate spatial acceleration index; the integer coordinates are authoritative.

`ways.id` is the positive OSM way ID.
`direction` is `forward`, `reverse` or `bidirectional` in the way's original vertex order.
Unknown or conditional legal directions are not promoted to a known direction.
`tags` is a JSON object of retained source strings, including destination tags.
`point_count` gives the number of vertices.
`memberships` joins `junction` and `way`, with a zero-based `node_index` into the way.

`ways.geometry` contains two consecutive streams of `point_count` signed delta varints: first latitude E7, then longitude E7.
Each stream resets its previous value to zero, so the first decoded value is absolute.
Each varint uses seven payload bits per byte, least-significant group first, with bit 7 indicating continuation.
An unsigned varint `u` decodes to a signed delta as `(u >> 1) ^ -(u & 1)`.
Add that delta to the previous value to recover the next integer.
Exactly two streams must consume the geometry blob, with no trailing bytes.

`ways.node_ids` uses the same signed delta-varint encoding for one stream of `point_count` OSM node IDs.
The node ID and E7 coordinate at each membership index must match the junction.
The database retains full source geometry without simplification.

## Restroom records

`places.id` is an internal row key, not an OSM identity.
The stable identity is `(osm_type, osm_id)`, where 0 means node, 1 means way and 2 means relation.
Coordinates use the same latitude/longitude E7 representation.
Area coordinates are representative bounding-box centres, and open-way points are vertex averages; these are not verified entrances.
`category` records the mapped venue category, and `tags` is the retained source-string JSON object.
`place_rtree` is a spatial acceleration index.

`evidence=mapped_toilet` means `amenity=toilets`.
`evidence=explicit_toilets_tag` means a retained `toilets` value other than `no`, `none` or `0`; malformed and unknown values remain source evidence rather than availability claims.
`evidence=rest_area_or_services` means a rest-area/service-area record without either earlier evidence class.
Access restrictions, unknown hours and negative toilet tags remain intact.
A mapped rest area alone does not establish an open public restroom.
Separate OSM element identities remain separate even when their coordinates coincide.

## Coverage and metadata

`dataset_metadata` binds the schema, dataset ID/kind, role, source checksum, replication sequence, filters and coverage checksum to the manifest.
The PBF envelope is not a country polygon or a claim of complete real-world mapping.
The manifest's `coveragePolygons` contain polygon/ring/point arrays in **longitude E7, latitude E7** order, with holes retained.
`reviewedCoverage` supplies source-reviewed envelopes, including US bay waters omitted by the land outlines.
`coverageMaskSHA256` hashes canonical compact, sorted-key JSON containing those two named arrays.
Readers require a wholly covered query and otherwise continue to their gap-filling sources.
These contracts do not certify road signs, current restroom access or physical driving behavior.
