# Land/sea mask A land/sea bitmap, tiled by 1° × 1°, so the app never draws a tidal-stream arrow on land. The app used to treat a lattice point as sea when its terrain height was within ±0.5 m of 0 (`WeatherOverlay.isSeaLevel`). That fails on low-lying land: Felpham and Flansham by Bognor Regis, Romney Marsh, the Fens, the Somerset Levels, Canvey Island and the Dutch coast. Now it uses both checks: **a point is sea only if the mask says water and its height is about 0** (`WeatherOverlay.landCheck`). A point the mask calls land isn't sent to the server at all, for a tidal stream or a height. Outside the mask's region the height check stands alone. The app bundles the pack as `LightWatch/Resources/landmask.lmp`, with this folder's `NOTICE.txt` as `landmask-NOTICE.txt`, and reads it with `LightWatch/Services/LandMask.swift`. The same files are offered at (`website/public/data/landmask/`). The generator and its output live here, in `out/`. `tools/golden/run.sh` fails if the app's or the website's copies differ from `out/`, and its harness checks the Swift reader against this folder (see Verification). | File | What it is | | --- | --- | | `build.py` | Generator. Reads an OSM land-polygons shapefile and writes `out/`. | | `check.py` | Reads the tiles back through the format and checks them: known sea and land points, the app's arrow lattice, and (with `--shp`) an independent comparison with the source, including the accuracy near the coast. | | `landmask.py` | Shared code: the shapefile reader, the rasteriser, the format encoder and decoder, and a reference lookup (`LandMask.is_land`, and `LandMask.lookup` for arrays of points). | | `out/index.lmi` | The index, 66 bytes. | | `out/tiles/*.lmt` | One file per tile that has both land and water (96 files). | | `out/landmask.lmp` | The index and all the tiles in one file, for bundling in the app: 242,534 bytes. | | `out/manifest.json` | Source, licence, build command, counts, and the size, SHA-256 and bits CRC-32 of every file. | | `out/NOTICE.txt` | The ODbL notice. It must travel with the tiles. | The tools need only Python 3 and numpy, with no GIS libraries. ## Source and licence - **Data:** OpenStreetMap land polygons, *full-detail* variant split into pieces of about 1° × 1° (`land-polygons-split-4326`), dated 2026-10-06. Downloaded from . It has 873,437 polygons in EPSG:4326 (WGS 84 latitude and longitude); 23,861 of them, with 2.65 million edges, meet this region. - **Attribution:** "© OpenStreetMap contributors". - **Licence:** Open Database License (ODbL) 1.0 (). See . The first build used the *simplified* variant (`simplified-land-polygons-complete-3857`, Web Mercator, accurate to a few hundred metres). The generator still reads it, and rebuilding from it with `--cells-per-degree 480` gives that build's files byte for byte. This is our reading of the ODbL, not legal advice. **What the mask is.** It is a **Derivative Database** of OpenStreetMap. What users see, arrows placed or held back by the mask, is a **Produced Work**. **When the conditions apply.** They apply as soon as the app shows the public arrows that the mask has filtered, even if the mask itself is never bundled or served. By §4.4(c), publicly using a Produced Work makes the Derivative Database it came from publicly used too. Bundling the mask in the app or serving it from our server also counts. **What we must do then:** - **§4.4, share-alike.** We must offer the mask under the ODbL. - **§4.2, notices.** Where we convey the mask, we must: - convey it only under the ODbL; - include the licence or its URI; - keep the notices with it. `out/NOTICE.txt` is that notice. It names the source, carries the attribution and links the ODbL. - **§4.3, the Produced Work notice.** The arrows need a notice such as "Contains information from OpenStreetMap, © OpenStreetMap contributors, available under the ODbL". They do not have to be ODbL themselves. The mask is never drawn, so the line is on the app's Credits page in Settings (under Map data), with the other data credits. - **§4.6, an offer of the database.** We must actually offer every recipient a machine-readable copy, free over the internet. The copy can be either the mask itself or "the method of making" it. - `build.py` alone wouldn't satisfy this while it lived only in a private repository that recipients can't reach. - **The offer** is the database itself, published with its notice, this README and the scripts at . Without an offer URL, `NOTICE.txt` says `OFFER NOT SET`, and `build.py` and `check.py` both print a reminder. **Release steps for the licence** (before the mask reaches users): 1. Choose a public URL for the mask. Done: `website/public/data/landmask/` publishes it at `https://focusscout.app/data/landmask/`. 2. Rebuild with `--offer-url `. Done: `NOTICE.txt` says where the database is available, and `manifest.json` records the URL. 3. Publish `out/landmask.lmp` and `out/NOTICE.txt` at that URL. Prepared: they go in `website/public/data/landmask/` with `manifest.json`, this README, `build.py`, `landmask.py`, `check.py` and an `index.html` that explains them. **Deploy the website before, or with, the first app build that bundles the mask, TestFlight included, and check the URL answers 200.** The repository README's Before launch list carries this as a release gate. 4. In the Settings credits, add the §4.3 line with links to the published mask and to . Done (Credits, Map data). 5. Check the OSMF Attribution Guidelines (). After any rebuild, copy the new files to both places (the app's `Resources` and the website folder); `tools/golden/run.sh` stops until they match. ## Regenerating ```sh # 1. Download and unzip (928 MB zip; the .shp is 1.3 GB, with its .shx index beside it): # https://osmdata.openstreetmap.de/download/land-polygons-split-4326.zip # 2. Build (2.4 s, 436 MB peak) and check (about 8 s, 1.2 GB): python3 tools/landmask/build.py --shp PATH/land-polygons-split-4326/land_polygons.shp \ --offer-url https://focusscout.app/data/landmask/ python3 tools/landmask/check.py --shp PATH/land-polygons-split-4326/land_polygons.shp ``` The times are with the shapefile in the disk cache, on an Apple-silicon Mac. **The shapefile is streamed, never loaded whole.** `landmask.read_polygons` reads the `.shx` index (8 bytes a record, 7 MB), then the 52-byte head of every record, which holds its bounding box, and then the points of only the records whose box meets the region. - For this region that is 897,298 reads and 90 MB: 45 MB of heads (all 873,437 records) and 44 MB of points (the 23,861 records that meet the region). Reading takes about 1.1 s with the file in the disk cache. - The heads are spread through the whole file. They touch 0.57 GB of it in 4 KB pages (0.77 GB in 16 KB pages), so with a cold cache the OS reads most of the 1.3 GB from disk. That is the OS's cache, not the build's memory. - Without a `.shx` it walks the `.shp` record by record. **Memory follows the region, not the world.** The build's peak is 436 MB (maximum resident set, from `/usr/bin/time -l`). - About 230 MB of it is reached before rasterising starts. Reading the region's records takes the process to about 125 MB, the edge arrays (2.65 million edges) to 145 MB, and the lists of the edges each 1° band needs to about 230 MB. - Each rasteriser pass then adds two things. One is its grid, about 8 bytes a cell: 100 MB for this region's 14-tile band at 960 cells. The other is working copies of the band's edges, up to 570,000 of them in the 51° N band. - `--chunk-tiles` caps only the grid. With `--chunk-tiles 1` the peak falls to 348 MB and the build takes 3.7 s, with byte-identical output. **Reproducibility.** The same input, the same flags and the same zlib build give byte-identical output. Two builds in a row of the current `out/` compared equal byte for byte. - No timestamps are written. The date stored in the output is the source's date, which `build.py` reads from the package's `README.txt` (or pass `--source-date`). - `manifest.json` records the zlib version (1.2.12 here). A different zlib build, such as zlib-ng, can compress the same bits to different bytes. - **The portable identity of the data** is therefore: - `index.lmi`, which is not compressed; - the CRC-32 of the decoded bits in each tile header, which `manifest.json` also lists as `bitsCrc32`. - Tile content doesn't depend on the region box or on `--chunk-tiles`. A build of 47–63° N, 13° W–5° E with `--chunk-tiles 5` gave all 96 of this region's mixed tiles byte for byte. | Flag | Default | Meaning | | --- | --- | --- | | `--shp` | required | Polygon shapefile in EPSG:3857 or EPSG:4326, read from the `.prj`. Any other CRS is refused (see below). `--crs 3857` or `--crs 4326` overrides the `.prj`. | | `--south --north --west --east` | 49, 61, −11, 3 | Region in whole degrees. North and east are exclusive. For a region across the antimeridian, give an east edge past 180: `--west 170 --east 190` covers 170° E to 170° W. | | `--cells-per-degree` | 960 | Cells per degree of latitude. | | `--lon-cells-per-degree` | same as latitude | Cells per degree of longitude. | | `--rule` | `nonzero` | Fill rule. `evenodd` is available for comparison only (see below). | | `--offer-url` | none | Public URL where `landmask.lmp` and `NOTICE.txt` are published, for the ODbL §4.6 offer. It is written into `NOTICE.txt` and `manifest.json`. | | `--out` | `tools/landmask/out` | Output folder. Old `.lmt` files in it are deleted first. | | `--no-pack` | off | Skip `landmask.lmp`. | | `--chunk-tiles` | 24 | Tile columns per pass. A pass's grid takes about rows × chunk × cols × 8 bytes; the band's edges come on top, whatever the chunk. | **The CRS check is strict.** A `.prj` is read as EPSG:3857 only if it names `Mercator_Auxiliary_Sphere`, `Pseudo-Mercator` or EPSG 3857. It is read as EPSG:4326 only if it is a WGS 84 `GEOGCS`. Anything else stops the build. That includes World Mercator (EPSG:3395) and British National Grid (`Transverse_Mercator`), which a looser test would have misread as 3857. **Other regions** need no code changes: pass a different box. For example: - **The Netherlands:** `--south 51 --north 54 --west 3 --east 8`. - **Fiji, across the antimeridian:** `--south -21 --north -12 --west 174 --east 183`. From the full source at 960 cells this gives 26 mixed tiles and a 35,878-byte pack in 1.2 s, and `check.py --shp` passes on it with no cell-centre disagreements. - **Near the poles:** EPSG:3857 ends at ±85.0511°, and the source has no data beyond it. Tiles that reach past that line are written as "not covered" (status 0), not as water. With an EPSG:4326 source, every latitude is used. A whole-world run from the full source at 960 cells (`--south -90 --north 90 --west -180 --east 180`) reads all 873,437 polygons (77.9 million edges) and gives these numbers: - 197 s and 6.6 GB of memory. Each 1° band rasterises only the edges that reach it (`landmask.BandIndex`), so the time grows with the coastline, not with the number of bands times the edges. - 6,885 mixed tiles totalling 13,451,656 bytes, a 16,224-byte index, and a 13.6 MB pack. - The UK and Fiji tiles from the regional builds are byte-identical to the same tiles from the world build. **Bundling.** Bundle the pack rather than the folder. The 6,885 small files of a world build take 31 MB on disk because of the disk's block size, against 13.6 MB as one pack. **Coverage.** All-water and all-land tiles cost 2 bits each in the index, so growing one box is cheap. **Several tilesets.** The app can also hold more than one tileset, for example a bundled UK pack plus packs served later for new regions. - To look up a point, ask each tileset in turn and take the first answer that isn't "not covered". - Tilesets built from the same source at the same resolution agree wherever they overlap. - Tile names are global (`N50W002.lmt`), so `index.lmi` and `tiles/` can also be served as static files. ## How the tiles are made 1. **Polygons.** The generator reads every polygon whose bounding box meets the region, through the `.shx` index (see Regenerating). It uses all of each polygon's edges, including the parts outside the region. - Nothing is clipped, so polygons that cross tile or region edges come out right. - Polygons wholly outside the box cannot change a cell inside it: a closed ring entirely to a point's west adds no net winding along the point's row. - A region across the antimeridian is read as two longitude runs, and each run is rasterised on its own. The source's polygons are split at ±180°, so no ring wraps. 2. **Scanlines at cell centres.** For each row of cell centres (latitude `south + (r + 0.5)/rows`), the generator finds every edge crossing that latitude. - It uses a half-open rule (`ymin <= y < ymax`), so a vertex that falls exactly on a row counts once. - The crossing is computed in the source CRS, because edges are straight lines there, which is how the source defines them. It is then converted to longitude. - Each cell takes the value of the polygon at its **centre**. 3. **Nonzero winding.** Shapefile outer rings are clockwise and holes anticlockwise. An upward crossing adds +1 and a downward one −1, and a cell is land where the winding to its west is non-zero. - Holes therefore come out as water. - **Where polygons overlap, the overlap stays land.** The split source's pieces overlap on purpose: along every whole degree, neighbouring pieces both cover a strip about 110 m wide, reaching 55 m either side of the degree line (±0.0005° of latitude, and ±0.0005°/cos(latitude) of longitude). Inside those strips the winding is 2 on land. Even-odd would turn every such strip into a line of water across the land, so it is for comparison only. - At 960 cells, 89,878 cell centres fall in these strips (`overlapCells` in `manifest.json`), all in the longitude strips: a row of cell centres is 0.00052° from a whole degree of latitude, just outside the latitude strips. At 480 cells none do. 4. **Lakes count as land.** OSM land polygons are bounded only by `natural=coastline`, so inland water is never cut out. - The data bears this out: no ring that meets the region is a hole. - So Lough Neagh and Loch Ness are land. Harbours, sea lochs and estuaries are water as far as the coastline runs up them (see Limitations for the rivers where it stops). - Lakes have no tidal streams, so this is the right answer for the app. ## Resolution The build uses **960 cells per degree in both directions**: - North to south, a cell is 115.8 m everywhere. - East to west it is 115.8 m × cos(latitude): 76 m at 49° N, 66 m at 55° N and 56 m at 61° N. Why the same angular step in both directions: - One constant works worldwide, and the lookup is two multiplications. - Cells are never wider than they are tall, so the north-to-south size bounds the error everywhere. - The extra east-to-west detail at high latitudes costs little. Compressed size grows with the number of coastline crossings per row, not with the row length. **Size and accuracy by resolution**, all built from the full-detail source and measured by `check.py --shp` (200,000 points per sample): | Cells per degree | Cell (N–S × E–W at 55° N) | Pack | Coastal points wrong, truly within 50 / 100 / 200 m of the coast | Wrong points at most (bound) | Islands of 1–5 ha kept | Islands of 5–10 ha kept | | --- | --- | --- | --- | --- | --- | --- | | 480 | 232 × 133 m | 102,159 B | 34.8% / 25.4% / 17.6% | 129 m from the coast (139 m) | 955 of 1,633 (58%) | 393 of 403 | | 720 | 154 × 89 m | 170,212 B | 28.9% / 19.1% / 13.2% | 84 m (92 m) | 1,427 (87%) | all 403 | | **960** | **116 × 66 m** | **242,534 B** | **24.6% / 15.7% / 10.8%** | **65 m (69 m)** | **1,589 (97%)** | **all 403** | | 1920 | 58 × 33 m | 586,629 B | 14.8% / 9.4% / 6.5% | 31 m (35 m) | 1,633 (100%) | all 403 | For comparison, the first build (simplified source, 480 cells) was 97,843 bytes. The full source costs only 4% more at the same resolution. What the columns mean: - **Coastal points.** Points spread evenly along the source coastline by length, each placed up to 300 m off it at right angles, either side. The figure is the share the mask puts on the wrong side among the points truly within 50, 100 or 200 m of the nearest source coastline. - A point's true distance can be less than how far it was placed off its own stretch of coast, because another stretch may be nearer. Grouped by how far the points were placed off instead, the rates are a little higher: 27.4% / 17.7% / 11.8% at 960. `check.py` prints both. - The sample is spread by coast length, so ragged coasts weigh more than they would in a sample spread evenly over the coastal area. - Close to the coast a lot is wrong at any resolution: a cell takes the value at its centre, so a point nearer the coast than half a cell can land on either side. The rate falls roughly in step with the cell size. - **Wrong points at most.** The farthest a wrongly classified coastal point was from the source coastline in this sample. The bound, in brackets, is half a cell's diagonal at 49° N: no point can be wrong farther from the coastline than that. It is how far inland an arrow could stand, or how far out to sea one could be withheld. - **Islands kept.** Whole source islands with at least one cell centre on them, so they are land in the mask. Every island of 10–60 ha (507) is kept at every resolution; larger ones were not counted. Of the 20,579 islands under 1 ha, mostly rocks, 2,732 are kept at 960. - Over the whole region, random points are wrong 0.128% of the time at 480, 0.080% at 720, 0.071% at 960 and 0.035% at 1920. In these samples the wrong ones were at most 111, 81, 50 and 27 m from the coastline. **Why 960.** The owner asked that the app stay small. At 237 KB the pack is about 1.2% of the 20 MB app and well under the 1 MB target, against 96 KB before. For those 141 KB it halves the error band (wrong points at most 69 m from the coastline against 139 m at 480), cuts the wrong points within 100 m of the coast from 25% to 16%, and keeps 97% of islands of 1–5 ha instead of 58%. 720 is a fair compromise at 166 KB. 1920 halves the error again but costs 573 KB, and the app's arrows stand 0.02° apart (1.1–1.5 km east to west, 2.2 km north to south), so 69 m is already small beside them. A decoded tile is 115,200 bytes, so `LandMask.swift`'s cache of 8 tiles holds 0.9 MB. ## Format (version 1) All integers are little-endian. **Tile and cell layout:** - A tile covers latitude [south, south+1) and longitude [west, west+1). - It holds `rows` × `cols` cells. Row 0 is the **southernmost**; column 0 is the westernmost. - Cell (r, c) covers latitude [south + r/rows, south + (r+1)/rows) and longitude [west + c/cols, west + (c+1)/cols). Its value is the source sampled at the cell's centre. - **Bit 1 = land, 0 = water.** - Bits are packed MSB-first. Each row is padded to `stride = ceil(cols/8)` bytes, which is 120 at 960 cells. - **Padding bits are 0.** They are covered by the CRC, and `landmask.py` rejects a tile whose padding isn't 0. Padding only exists when `cols` is not a multiple of 8. ### Tile file `tiles/ddddd.lmt` The file is named from the tile's south-west corner, e.g. `N50W002.lmt` for 50–51° N, 2–1° W. West is always in [−180, 180), also for tiles east of the antimeridian in a region that crosses it. | Offset | Size | Field | | --- | --- | --- | | 0 | 4 | magic `LMT1` | | 4 | 1 | version = 1 | | 5 | 1 | encoding = 1: packed bits, raw DEFLATE. Other values are reserved. | | 6 | 2 | rows (u16): cells per degree of latitude | | 8 | 2 | cols (u16): cells per degree of longitude | | 10 | 2 | south (i16), whole degrees | | 12 | 2 | west (i16), whole degrees, in [−180, 180) | | 14 | 2 | reserved, 0 | | 16 | 4 | CRC-32 (IEEE, as in zlib) of the decoded bitset, padding included | | 20 | … | **raw DEFLATE** (RFC 1951, no zlib header) of `rows × stride` bytes | A row-XOR pre-filter was tried and made the tiles about 2.5% larger, so encoding 1 is plain bits. ### Index `index.lmi` | Offset | Size | Field | | --- | --- | --- | | 0 | 4 | magic `LMI1` | | 4 | 1 | version = 1 | | 5 | 1 | reserved | | 6 | 2 | rows (u16), the same in every tile | | 8 | 2 | cols (u16) | | 10 | 2 | south (i16) of the tile grid | | 12 | 2 | west (i16) of the tile grid, in [−180, 180) | | 14 | 2 | nLat (u16): tiles from south to north | | 16 | 2 | nLon (u16): tiles from west to east, at most 360 | | 18 | 2 | reserved | | 20 | 4 | source date as YYYYMMDD (u32) | | 24 | ceil(nLat·nLon/4) | tile status, 2 bits each | Status layout and codes: - Tile `k = i·nLon + j` has `i` counted from the south and `j` from the west. - **`j` is counted modulo 360:** `j = floorMod(tileWest − west, 360)`. A grid with west 170 and nLon 20 therefore runs across the antimeridian, from 170° E to 170° W. For a grid that doesn't cross it, this is simply `tileWest − west`. - Four tiles share a byte, first tile in the top bits: `status = (byte[k >> 2] >> (6 − 2·(k & 3))) & 3`. - **0** = not covered, **1** = all water, **2** = all land, **3** = mixed (read the tile file). - A tile outside the grid counts as 0. So does a tile inside it that the source has no data for (EPSG:3857 beyond ±85.0511°). ### Pack `landmask.lmp` The pack holds the same bytes as `index.lmi` plus every mixed tile, in one file. | Offset | Size | Field | | --- | --- | --- | | 0 | 4 | magic `LMP1` | | 4 | 4 | n = length of the index (u32) | | 8 | n | the index (`.lmi` bytes) | | 8+n | 4 | count of tiles (u32) | | 12+n | 12·count | entries: south (i16), west (i16), offset from the start of the pack (u32), length (u32) | | … | | the tile files, headers included, in index order (south to north, then west to east from the grid's west edge) | **Most multi-byte fields in the pack are not aligned.** - The index is 66 bytes here, so the tile count sits at byte 74 and entry k at 78 + 12k. - A tile's CRC sits at its own offset + 16, and tiles start wherever the previous one ended. - Read every field with an unaligned load, or assemble it from bytes. ### Lookup Use exactly this arithmetic, in IEEE double precision, so every reader picks the same cell: ``` if lat or lon is not finite, or lat < -90 or lat > 90: not covered if lon < -180 or lon >= 180: wrap lon into [-180, 180) gRow = floor(lat * rows); gCol = floor(lon * cols) // Double, then Int south = floorDiv(gRow, rows); west = floorDiv(gCol, cols) // floor, also for negatives i = south - index.south; j = floorMod(west - index.west, 360) status = 0 if i is not in [0, nLat) or j is not in [0, nLon), else the index status of tile k = i*nLon + j 0 -> not covered: caller decides (fall back to the height check alone, or no arrow) 1 -> water, 2 -> land 3 -> r = gRow - south*rows; c = gCol - west*cols land = (bits[r*stride + (c >> 3)] >> (7 - (c & 7))) & 1 ``` **Points on a cell edge.** The cell is whichever one `floor(Double(lat) * rows)` and `floor(Double(lon) * cols)` give. Don't reason about it geometrically. - At 960 cells per degree, every multiple of 0.025° is a cell edge (at 480, every multiple of 0.05°). - Usually the product is exact and the point falls in the cell to its north-east. - For 134 two-decimal multiples of 0.05° worldwide, the product rounds just below the whole number, and the point falls in the cell to the west or south. In this region those are longitudes −8.30, −8.05, −4.15 and 2.05. No latitude between 49° and 61° is affected. These are the same at 480 and 960, because multiplying by 960 is exactly twice multiplying by 480 in binary floating point. - At 960, the odd multiples of 0.025° (three decimals, such as 1.025) are edges too. In this region the product rounds below for longitudes −8.425, −8.175, −4.025, −2.075 and 1.025, and for no latitude between 49° and 61°. - This is harmless, because every IEEE-754 reader computes the same thing. But don't replace the formula with an "equivalent" one, such as `(lat − south) * rows`, which rounds differently. **The app's arrow lattice.** - Lattice points are at (i + ½) × step (`WeatherOverlay.GridKey`), and the land check snaps them to 0.001° (`landCheckPoint`). - At 0.02° the points are odd multiples of 0.01°. Multiples of 0.1° are never lattice points. - The lattice points that fall exactly on cell edges are odd multiples of 0.05° (x.05, x.15, …), at 480 and at 960 alike: an odd multiple of 0.01° is never an odd multiple of 0.025°. Three of them are among the exceptions above: −8.05, −4.15 and 2.05. **Notes for the Swift side:** - Apple's Compression framework reads raw DEFLATE, which is exactly this payload: `compression_decode_buffer` with `COMPRESSION_ZLIB`, or `NSData.decompressed(using: .zlib)`. In Python it is `zlib.decompress(payload, -15)`. - A Swift reader written from this spec alone agreed with `LandMask.is_land` at 520,013 UK points of the 480-cell build. - It also agreed on Sydney, on Fiji either side of 180°, on Svalbard, and on 481 × 479 and 480 × 320 builds. - `LandMask.swift` takes `rows` and `cols` from the pack (it accepts up to 4,096), so the 960-cell pack needs no code change. - Use `loadUnaligned(fromByteOffset:as:)`, or assemble the bytes, for every pack and tile header field. `load(as:)` traps on a misaligned address. - `Int(floor(x))` traps when x is NaN, infinite or out of `Int`'s range. Do the finite and latitude checks above before converting. - Swift's `/` truncates toward zero, so `floorDiv` and `floorMod` need their own helpers for cells west of Greenwich and south of the equator. - zlib's `crc32` is available through `import zlib` if the reader verifies tiles. - A decoded tile is 115,200 bytes at 960 cells, so a small cache of decoded tiles is enough. `landmask.py`'s `LandMask.is_land` is the reference implementation of this lookup. ## Current output (region 49–61° N, 11° W–3° E, 960 × 960) **Tiles:** 168 in all. 65 are all water and 7 all land, and those are stored only as index flags. The other 96 are mixed. **Tile sizes, mixed tiles only:** | Statistic | Bytes | Tile | | --- | --- | --- | | Minimum | 167 | | | Median | 1,915 | | | Mean | 2,514 | | | 90th percentile | 5,010 | | | Maximum | 11,096 | `N56W006` (Mull, Oban, Loch Linnhe) | | Total | 241,304 | | **File sizes:** | Form | Bytes | | --- | --- | | Index | 66 | | Pack (index plus all tiles) | 242,534 | | Uncompressed, for comparison | 115,200 per tile; 19.4 MB for all 168 | The folder form and the pack each come to about 237 KB. ## Verification (`check.py`) `check.py` exits with status 1 if any assertion fails. The current run passes everything. **Format.** - The index, all 96 tile files and the pack decode. - CRCs match, padding bits are 0, and tile headers agree with the index. - The folder and the pack hold identical bits, and the tile files are exactly the index's mixed tiles. - `NOTICE.txt` carries the attribution and the ODbL. A missing §4.6 offer URL is reported, not failed. **Sea, asserted, all pass.** "Nearest land" is the distance to the nearest mask cell centre of the other kind; "coastline" is the distance to the source coastline. | Place | Point | Nearest land | Source coastline | | --- | --- | --- | --- | | Solent | 50.78, −1.20 | 1,322 m | 1,303 m | | Needles Channel | 50.66, −1.60 | 977 m | 629 m | | Poole Bay | 50.70, −1.85 | 2,054 m | 2,041 m | | Poole Harbour, open water | 50.6975, −2.0025 | 1,182 m | 1,140 m | | Bristol Channel | 51.35, −3.30 | 4.2 km | 4.1 km | | Menai Strait, mid-channel | 53.2145, −4.1940 | 172 m | 154 m | | Strangford Lough entrance | 54.37, −5.55 | 107 m | 60 m | | Dover Strait | 51.0, 1.4 | over 6 km | over 10 km | | Thames, Sea Reach off Canvey | 51.495, 0.60 | 1,459 m | 1,446 m | | Humber, 2 km below the bridge (1.3 km below where the source's Humber ends) | 53.705, −0.42 | 846 m | 805 m | | Dublin Bay | 53.33, −6.12 | 2.9 km | 2.5 km | **Land, asserted, all pass:** Flansham, Yapton, Romney Marsh, Wisbech, Somerset Levels, Canvey Island (51.52, 0.58), London (51.5, −0.12) and Dublin (53.35, −6.26), and seven islands of 7–10 ha that the simplified source had no polygon for: | Island | Point | Nearest water | Source coastline | | --- | --- | --- | --- | | St Michael's Mount | 50.1172, −5.4775 | 141 m | 128 m | | Looe Island | 50.3369, −4.4519 | 118 m | 45 m | | Burgh Island | 50.2797, −3.9007 | 130 m | 75 m | | Bass Rock | 56.0773, −2.6406 | 88 m | 60 m | | Craigleith | 56.0735, −2.7200 | 149 m | 123 m | | Inner Farne | 55.6164, −1.6554 | 141 m | 75 m | | Dalkey Island | 53.2722, −6.0844 | 171 m | 116 m | The nearest water cell is 878 m away at Canvey, 1,014 m at Flansham, 863 m at Yapton and 2.3 km at Dublin; at Romney Marsh, Wisbech, the Somerset Levels and London it is over 6 km away. **The brief's points that the source doesn't support.** These are reported, not asserted. Each is land in the full-detail source as well as in the mask, so no resolution would make it water: | Place | Point | Source coastline | Why | | --- | --- | --- | --- | | Thames at Gravesend | 51.445, 0.37 | over 10 km | OSM's coastline crosses the Thames at 0.50° E, west of Canvey Island (see Limitations). | | Thames at Westminster | 51.50, −0.122 | over 10 km | The same. | | Thames at Tower Bridge | 51.5055, −0.0754 | over 10 km | The same. | | Humber at the bridge | 53.71, −0.45 | 581 m | The coastline crosses the Humber at 0.44° W, 600 m below the bridge. | | Dublin port | 53.345, −6.20 | 664 m | The coastline crosses the Liffey at 6.195° W, 750 m NNE, at the port's seaward end. | | Menai Strait | 53.21, −4.19 | 408 m | On the mainland shore. The strait itself is one continuous channel of water in the mask from Caernarfon to Bangor (with the simplified source it was broken); the mid-channel point above is 570 m NNW. | | Poole Harbour | 50.69, −1.98 | 330 m | Inside Brownsea Island (west end). Open harbour water at 50.6975, −2.0025 is asserted above. | **Reported water:** Chichester Harbour (50.80, −0.90; 482 m from the source coastline), Langstone Harbour (613 m), Portsmouth Harbour (590 m), Southampton Water (1,065 m), Morecambe Bay (5.3 km) and the Wash (9.0 km). Great Mewstone (3.2 ha) is reported, and is land. **The app's lattice.** - The 0.02° lattice is built the way the app builds it: (i + ½) × 0.02, snapped to 0.001°. - It has 420,000 points over the region. The mask calls 299,494 of them water and 120,506 land. - A 3 × 3 cell margin would remove 1,123 of those water points (0.37%). - `check.py` prints these numbers on every run, for any region. **Independent comparison with the source.** This uses a northward-ray point-in-polygon test, a different code path from the generator's westward scanlines. A ring can only wind round a point inside its own bounding box, so each point is tested against those rings alone, which keeps the 2.6 million edges quick. Distances to the coastline leave out the straight cuts between the source's 1° pieces (1,516 edges here), which are not coast. | Sample | Points | Result | | --- | --- | --- | | Cell centres next to the coast | 200,000 of 619,228 | 0 disagreements | | Random cell centres | 200,000 | 0 disagreements | | Random points anywhere | 200,000 | 143 differ (0.071%), about evenly split between water called land and land called water; in this sample at most 50 m from the source coastline, median 13 m | | Coastal points, truly within 25 / 50 / 100 / 200 m of the coast | 198,302, placed up to 300 m off | 34.6% / 24.6% / 15.7% / 10.8% wrong, about evenly split between water called land and land called water (grouped by how far they were placed off: 36.9% / 27.4% / 17.7% / 11.8%); at most 65 m from the coastline, median 10 m | | Islands (whole source rings) | 23,122 of 60 ha or less | kept: under 1 ha 2,732 of 20,579; 1–5 ha 1,589 of 1,633; 5–10 ha 403 of 403; 10–60 ha 507 of 507 | The differences are the expected effect of sampling at cell centres. None can be farther from the coastline than half a cell's diagonal (69 m at 49° N); the samples' largest are 50 and 65 m. **Other regions.** `check.py` runs unchanged on any region's output. - The named places are in Britain and Ireland. Any outside the tileset's box are skipped. - Tiles that are "not covered" are left out of the source comparison. - With the full source, Fiji across the antimeridian passes with no cell-centre disagreements. With the simplified source, Sydney, Fiji, 78–90° N and 90–80° S (with "not covered" polar rows) and a 481 × 479 build with padded rows all passed. **The app's reader** (`LightWatch/Services/LandMask.swift`) is checked by the golden harness (`tools/golden/run.sh`, `weatherMap.landMask.unitChecks`), which runs it on the app's bundled pack: - The pack's SHA-256, the tile counts, and every mixed tile's bits CRC-32 and land fraction match `out/manifest.json`, which `build.py` wrote from the bits it encoded. - It agrees with `check.py`'s asserted sea and land points, read from `check.py` itself. - Points on cell edges fall in the cells this README gives, and points outside the mask, or not finite, are "not covered". - On the app's 0.02° lattice it counts the same water and land points as `check.py` (299,494 and 120,506 of 420,000 with this build). - The tile cache stays bounded, eight callers at once get the same answers as one, and a damaged tile or pack answers "not covered". - A pack that is missing, unreadable or not valid, or a tile that doesn't decode, is reported as a problem (logged, a signpost event, and in the app's "Overlay land mask" signpost), not taken for "outside the region"; a Debug build of the app stops on it. - `LandMask.shared`'s own `Bundle.main` lookup finds the app's pack (`run.sh` puts `Resources/*.lmp` beside the harness binary), and the app target doesn't exclude it. A one-off comparison of the app's `LandMask.swift` (compiled on its own, with only its signpost call removed) with `LandMask.is_land` on this 960-cell pack found no differences at 426,658 points: 400,000 random, multiples of 1/960° and of 0.05°, three-decimal points (the cell-edge cases above) and the brief's points. Its cache stayed at 8 tiles. An earlier one on the 480-cell build, at 200,016 points, found none either. ## Limitations 1. **Rivers stop where OSM's coastline crosses them.** The land polygons are made only from `natural=coastline`. OSM mappers close each river with a line across it somewhere near its mouth and map the water above as a river (`natural=water`), which the land polygons leave as land. So the mask calls these rivers land, and they get no arrows: - the **Thames** above 0.50° E (west of Canvey Island): Gravesend, London and everything upstream; - the **Humber** above 0.44° W, 600 m below the Humber Bridge, so the bridge and everything upstream; - the **Liffey** above 6.195° W, Dublin port included. The simplified source stops at the same places, so this is not a matter of detail. Making these rivers water would need a second source: OSM's river areas (`natural=water` with `water=river`) from an OSM extract, also ODbL, which the land-polygons package doesn't contain. 2. **Islands of under about 1 ha are mostly missing.** The source has them, but a cell centre rarely falls on one: 2,732 of the region's 20,579 islands under 1 ha are land in the mask. 97% of islands of 1–5 ha are, and every island over 5 ha is (see Resolution). The height check is the only guard for the missing ones, and it catches an island only where the terrain model puts the arrow's point above 0.5 m. 3. **Sampling at cell centres adds up to half a cell of error:** 58 m north to south and 28–38 m east to west, up to 69 m along a cell's diagonal. A point a little inside the coastline can take the value of a cell centre on the other side. A channel narrower than a cell (116 m north to south, 66 m east to west at 55° N) can vanish or break, and so can a spit that narrow. 4. **The coastline is OSM's mean high water line.** Drying flats are therefore water: Morecambe Bay, the Wash, Chichester and Langstone mudflats. The height check does not help there, because the flats are about 0 m. 5. **Points close to the shore have little margin, and the app reads a single cell.** A margin would call a point sea only when its cell and the 8 cells around it are all water. The app doesn't use one: it reads the point's own cell (`WeatherOverlay.landCheck` records the decision). - On the 0.02° lattice, 165 points (0.055% of the water points) are water in the mask but land in the source. All are within 57 m of the source coastline, with a median of 12 m. At 480 cells it was 301 points, within 116 m. - A margin would leave 8 of them, on slivers of land narrower than a cell. - But it would remove 1,123 of the 299,494 water points (0.37%). - **Why a single cell.** Narrow tidal channels such as the Menai Strait and the Strangford Narrows are where a tidal-stream arrow matters most, and a margin would blank them. - **What that leaves.** A point on land within half a cell of the coastline (up to 69 m) can be water in the mask. Such a point still gets no arrow where the terrain model puts it above 0.5 m. It gets one only where the terrain model also has it at about 0 m, such as a salt marsh or a shingle bank. - The golden harness's Bognor 0 m variants showed the gap with the simplified source: up to 2 arrows a view stood north of the harness's synthetic shore line, within its accuracy band, where the mask had water, because from Aldwick to Middleton the simplified coast ran 65–470 m north of that line. The full-detail coastline there is within 133 m of the simplified one (median 56 m), so the gap remains; the harness's numbers need recording again with this mask. Neither line has been checked against a survey there. 6. **Coverage.** The lookup answers "not covered" outside the index's box, and, with an EPSG:3857 source, beyond ±85.0511°. The app uses the height check alone there.