geolith 0.2.2

Shared library of the geolith builders: source readers, conflation, admin areas, tile encoding and the PMTiles and MBTiles writers
Documentation
# Notice

This project contains code ported from Valhalla
(https://github.com/valhalla/valhalla) at commit
`2085e78a517a0680a39d3b89efb7eff1f5cf9201` (release 3.9.1). The ported parts
are its graph tile format (the `routing` module of `geolith-glx`), its graph builder
(`packages/routing-builder/src/build`) and the tag rules of its `lua/graph.lua`
(`packages/routing-builder/src/tags`).

Valhalla is distributed under the following license, reproduced verbatim from
https://raw.githubusercontent.com/valhalla/valhalla/2085e78a517a0680a39d3b89efb7eff1f5cf9201/COPYING:

```text
The MIT License (MIT)

Copyright (c) 2018 Valhalla contributors
Copyright (c) 2015-2017 Mapillary AB, Mapzen

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
```

## Default speed tables (routing, optional input)

`--routing-default-speeds` reads a table in the OpenStreetMapSpeeds format
(https://github.com/OpenStreetMapSpeeds/schema). No table is shipped in this
repository: the tests use a made-up table. A routing `.glx` built with the
OpenStreetMapSpeeds `default_speeds.json` (commit
`c9c6872d5ec656f5d290944b44eb1a103ed539fa`) carries speeds from it; credit
"Default speeds from OpenStreetMapSpeeds (MIT), derived from Mapillary
traces" and keep its license, reproduced verbatim from
https://raw.githubusercontent.com/OpenStreetMapSpeeds/schema/c9c6872d5ec656f5d290944b44eb1a103ed539fa/LICENSE:

```text
MIT License

Copyright (c) 2021 OpenStreetMapSpeeds

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```

## Time zone areas (routing, optional input)

`--routing-timezones` reads the time zone boundaries of
timezone-boundary-builder (https://github.com/evansiroky/timezone-boundary-builder),
release `2026f`, file `timezones-with-oceans-1970.shapefile.zip`
(https://github.com/evansiroky/timezone-boundary-builder/releases/download/2026f/timezones-with-oceans-1970.shapefile.zip,
sha256 `1e9829c867229c1cbc9ebd20a3d77211e63e54e20376583b056f642802dcc3d3`),
the same file the reference's `valhalla_build_timezones` at 2085e78a5
downloads. The data is licensed under the Open Data Commons Open Database
License (ODbL, https://opendatacommons.org/licenses/odbl/); it is derived
from OpenStreetMap data, © OpenStreetMap contributors. The file is not
committed; builds read it from `.data/inputs/timezones/`. The test fixture
`packages/routing-builder/tests/fixtures/routing/timezones/` is made up
(`packages/routing-builder/tests/routing-timezones-fixture.ts`).

The time zone index table (`src/routing/timezone_table.rs` of `geolith-glx`) is
Valhalla's `tz_name_to_id` (`src/baldr/datetime.cc` at 2085e78a5, MIT, see
above) with each name resolved in the IANA tz database release 2026f
(public domain), generated by `packages/routing-builder/tests/routing-timezones-table.ts`.

The timed restriction check in `src/costing/time.rs` of `geolith-routing` (routing repo) ports Valhalla's
`is_conditional_active` (`src/baldr/datetime.cc` at 2085e78a5, MIT, see above).

## India boundary (tiles, geocoding, routing)

The builders draw and resolve India on its legal boundary, the Survey of
India map. Both input files come from one source: DataMeet's
`Country/india-composite.geojson` (https://github.com/datameet/maps, commit
`5ed214bf77788f99066e3542cccd4a52cb042896`, sha256
`5e44c39b18aa8fe57267d8018fa4ad4a10eaa3aa4cb7cb7382a1813ef8eb8c53`).

- Geocoding and routing builds read the polygon file as it is, with
  `--india-outline`; a lines file is refused there.
- Tile builds read `--india-boundary`: the same coordinates, every ring of
  the polygons written as a line in one `MultiLineString`
  (sha256 `4e08a3f93028c09e8e1cdf6817b26074497c5bd8a10db7dea8ef73fe895870da`).
  `tools/india-boundary/derive.py` downloads the DataMeet file at that commit,
  checks both hashes, and writes the file, so a clone can make it. A tile
  build also takes the polygon file itself and derives the same lines in
  memory (`geolith-soi`, the algorithm of `derive.py`).

The repository `datameet/maps` states its data licence in its README
("Data License"): "Unless explicitly stated, all datasets in this repository
is shared under CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)
license. Please mention and link to relevant dataset in the attribution, eg.
India boundaries (https://github.com/datameet/maps/blob/master/Country/india-composite.geojson)
by DataMeet India community (http://datameet.org/) (CC BY 4.0)". The
`LICENSE` file of that repository (MIT, 2020 DataMeet India community) covers
its code. The data licence is CC BY 4.0, which needs the attribution. Every
output built with the file carries it: "India boundary: DataMeet India
community (CC BY 4.0)" in the `attribution` of a `PMTiles` archive and in the
`META` part of a `.glx` file. The files are not committed.

## i_overlay and geo (forked)

`vendor/i_overlay` is i_overlay 4.5.2 by Nail Sharipov
(https://github.com/iShape-Rust/iOverlay, tag `4.5.2`, commit
`9448d8da87e11f5b7aedcf994967b18ff640c734`), licensed under MIT OR
Apache-2.0. It is published as the crate `geolith-i-overlay`. Its licence texts
are in `vendor/i_overlay/LICENSE-MIT` and `vendor/i_overlay/LICENSE-APACHE`,
copied unchanged from that commit. Our patch: `src/bind/solver.rs` and
`src/bind/segment.rs` guard the hole binder against the empty-parent sentinel,
so an orphan hole falls back to shape 0 instead of an out-of-bounds panic.

`vendor/geo` is geo 0.33.1 by the GeoRust Developers
(https://github.com/georust/geo, commit
`5ab50b072e34a915a33eaa46c80763d51d61295e`), licensed under MIT OR
Apache-2.0 (`vendor/geo/LICENSE-MIT`, `vendor/geo/LICENSE-APACHE`). It is
published as the crate `geolith-geo`. The source is unchanged; only
`Cargo.toml` differs, so that geo uses `geolith-i-overlay`. We fork geo because
geo 0.33.1 needs i_overlay 4.5.x and a `[patch]` section does not apply to a
crate that is installed from crates.io.

## Planetiler (ported code)

`packages/geolith/src/geometry/line_merge.rs` is ported and modified from
Planetiler's `LoopLineMerger`, and `packages/geolith/src/tile/feature_merge.rs`
from its `FeatureMerge` (`mergeLineStrings`, `mergeNearbyPolygons`).
Planetiler: https://github.com/onthegomap/planetiler, Copyright 2021 Michael
Barry and Planetiler Contributors, licensed under the Apache License,
Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0; the same text is
in `vendor/i_overlay/LICENSE-APACHE`). The port follows
`util/LoopLineMerger.java` as of commit
`cdd783993efc861e8a2b6e02eeb6b1a110356dc7` and `FeatureMerge.java` as of
commit `e4d490773bd8b1e416d4ebf7e56fdfb4acdf97b4`.

## protomaps basemaps (translated rules and data)

The layer processors in `packages/tiles-builder/src/layers/` and the per-tile merge rules in
`packages/tiles-builder/src/tile/protomaps_merge.rs` translate logic and numbers of the
protomaps basemap Java profile (https://github.com/protomaps/basemaps,
`tiles/src/main/java/com/protomaps/basemap/`), for example `Roads`, `Earth`,
`Places` and the `postProcess` methods. `packages/tiles-builder/src/layers/places-wikidata.csv`
is its `tiles/src/main/resources/places.csv` at commit `cf87de9f`, unchanged
(licence copy in `packages/tiles-builder/src/layers/places-wikidata.LICENSE`). The name
attributes (`name`, `script`, `name2`, `script2`, `name3`, `script3`, `name:<lang>`) are written by
`packages/geolith/src/names/`, a port of `names/OsmNames.java`, `names/Script.java` and
`names/ScriptSegmenter.java` as of commit `42ffaaa4a85a41bfcb23e43cc0f5b492a5eca123`. The unit
tests there reuse the expected values of the upstream tests `ScriptTest.java` and
`ScriptSegmenterTest.java`. The attributes are the ones the `get_multiline_name` and
`get_country_name` expressions of `@protomaps/basemaps` 5.7.2 (`src/language.ts`) read. The protomaps
basemaps code is distributed under the following license, reproduced
verbatim from
https://raw.githubusercontent.com/protomaps/basemaps/cf87de9fe05fb18a23126bf9c076ec75201027ec/LICENSE.md:

```text
The BSD 3-Clause License (BSD-3-Clause)

Copyright 2019-2023 Protomaps LLC, Kelso Cartography

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
```

The same `LICENSE.md` states that the protomaps tile schema (its layer and
tag organisation, which geolith's tiles follow) is adapted from the Tilezen
project (https://github.com/tilezen/vector-datasource), MIT License,
Copyright (c) 2015-2018 Mapzen, Copyright (c) 2019 Linux Foundation.

## PMTiles (reference code)

The Hilbert tile-id functions in `packages/geolith/src/output/hilbert.rs`
follow the reference implementations in https://github.com/protomaps/PMTiles,
distributed under the BSD-3-Clause license (Copyright 2021 Protomaps LLC; the
same three conditions and disclaimer as the protomaps basemaps license above).
The PMTiles specification itself is public domain, or CC0 where applicable
(https://github.com/protomaps/PMTiles/blob/main/LICENSE).

## Map data

Builds read OpenStreetMap data, © OpenStreetMap contributors, licensed under
the Open Data Commons Open Database License (ODbL,
https://www.openstreetmap.org/copyright), and Overture Maps data, whose
themes carry their own licences (https://docs.overturemaps.org/attribution/).
Archives built from these sources must carry their attribution.

## India boundary data

India is drawn and resolved on the Survey of India map. The Survey of India
outline that builds read (`--india-outline`) is DataMeet's
`Country/india-composite.geojson`, India boundaries by the
[DataMeet India community](http://datameet.org/), licensed under
[CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
(https://github.com/datameet/maps). Two files in this repository derive from
it, changed by clipping, simplifying and rounding: the envelope in
`packages/soi/src/lib.rs` (grown by half a degree, a coarse test of where a
build is, never drawn) and the Kashmir excerpt
`packages/routing-builder/tests/fixtures/routing/india-guard/soi-kashmir-excerpt.geojson`
(clipped to 72 to 81.5 E, 31 to 37.6 N, simplified to 0.01 degree).

No other test fixture takes its shape from a dataset. `geolith/tests/fixtures/kashmir-soi-boundary.geojson`,
`kashmir-soi-datameet-shape.geojson`, `kashmir-soi-derived-shape.geojson` and `pune-soi-boundary.geojson`
are rectangles written by hand (73 to 80.5 E, 32.5 to 37 N, and 72 to 76 E, 17 to 20.5 N for Pune; the
two `kashmir-soi-*-shape` files are the Kashmir rectangle as a polygon file and as a lines file), not the
Survey of India line. The districts of
`packages/dataset-builder/tests/data/dataset-golden/` are made up ("div-a", "AA fixture"); the files there
are the output of the dataset tests, recorded so the tests can compare bytes.

## GeoParquet 2.0 test fixture

`packages/geolith/tests/fixtures/geoparquet/native-only-geometry.parquet` is
`native-only-geometry.parquet` of the `native_only` folder of
[geoparquet/geoparquet-testing](https://github.com/geoparquet/geoparquet-testing)
(commit `31662c3e877cd8d79dff9f28642754d8ef0ec4bb`), copied unchanged: three
rows, one native Parquet `GEOMETRY` column and no GeoParquet `geo` metadata.
It backs `a_native_geometry_file_without_geo_metadata_reads` in
`packages/geolith/tests/geoparquet_2.rs`. The repository is licensed under the
Apache License 2.0.