curtilage 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +75 -0
- data/README.md +76 -22
- data/SECURITY.md +18 -3
- data/docs/reference.md +221 -27
- data/docs/schema/site-v1.json +362 -0
- data/docs/security.md +69 -0
- data/exe/curtilage +375 -82
- data/lib/curtilage/audit.rb +5 -5
- data/lib/curtilage/auto_data.rb +61 -11
- data/lib/curtilage/batch.rb +116 -0
- data/lib/curtilage/build.rb +117 -63
- data/lib/curtilage/candidates.rb +67 -0
- data/lib/curtilage/catalogue.rb +44 -16
- data/lib/curtilage/confidence.rb +55 -0
- data/lib/curtilage/config.rb +24 -2
- data/lib/curtilage/corrections.rb +57 -0
- data/lib/curtilage/diff.rb +90 -0
- data/lib/curtilage/doctor.rb +92 -0
- data/lib/curtilage/download.rb +42 -16
- data/lib/curtilage/duckdb.rb +170 -6
- data/lib/curtilage/error.rb +3 -0
- data/lib/curtilage/features.rb +54 -5
- data/lib/curtilage/formats.rb +271 -36
- data/lib/curtilage/generator.rb +145 -166
- data/lib/curtilage/generator_details.rb +22 -14
- data/lib/curtilage/generator_lot.rb +56 -32
- data/lib/curtilage/generator_pin.rb +74 -0
- data/lib/curtilage/generator_roads.rb +109 -0
- data/lib/curtilage/generator_steps.rb +54 -0
- data/lib/curtilage/generator_store.rb +18 -4
- data/lib/curtilage/generator_zones.rb +93 -0
- data/lib/curtilage/geometry.rb +48 -52
- data/lib/curtilage/lookup.rb +41 -21
- data/lib/curtilage/overture.rb +137 -17
- data/lib/curtilage/preview.rb +55 -16
- data/lib/curtilage/profiles.rb +62 -0
- data/lib/curtilage/regions.rb +4 -8
- data/lib/curtilage/result.rb +72 -7
- data/lib/curtilage/validation.rb +73 -9
- data/lib/curtilage/version.rb +1 -1
- data/lib/curtilage/zip_range.rb +81 -16
- data/lib/curtilage.rb +155 -17
- data/sql/build_from_shapefiles.sql +1 -1
- metadata +15 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: db47b18684e743daa9ffdfb79231f4f90d0a6fd8bfe8e8ba2047b8f8a0af4387
|
|
4
|
+
data.tar.gz: 3dd4de937acd2deaaedfe07fa913dcea669143feeb833aa996750164b1bc0cb0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 28c1688d82b672fc600775d78f147f6c90833ea3c8bbb483125adbbf04d0cce8de26f840ca04a33dc37e948ae341a2db2de3e8358180d68c83d5e41b8878871d
|
|
7
|
+
data.tar.gz: 778a63b4fb4fc736fdd78d18588dd0dc6da5da51a1fc5a42c9770e4b4b164418f26b574cb33c1a1001423317b8fbaaa594c1f3f7843ae34437cedbb9f723f28e
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,81 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.4.0] - 2026-11-23
|
|
6
|
+
|
|
7
|
+
### Breaking
|
|
8
|
+
|
|
9
|
+
- Command-line exit codes: bad input and usage errors exit 2 (they exited 1, which now only means some sites failed), a missing DuckDB exits 3 and unavailable map data 4. `preview` exits 1 when some sites have no usable premises (it always exited 0), and prints its summary to standard error instead of standard output.
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- Every result records its provenance (`Result#provenance`, the GeoJSON `provenance` property): gem version, data source and release (the Overture release, or each region's Geofabrik extract dates and ML footprints), every option after defaults, and a SHA256 of the map data used. CSV gains `gem_version`, `data_source`, `data_release` and `features_sha256` columns at the end; KML descriptions name the version and release. Outputs hold no timestamps, so the same inputs give the same output byte for byte.
|
|
14
|
+
- NDJSON in and out: `--format ndjson` writes one GeoJSON Feature per site per line, following a versioned JSON Schema (`docs/schema/site-v1.json`, shipped in the gem); `--in` reads NDJSON pins, and `--in -` reads them from standard input (`--in-format` picks another format).
|
|
15
|
+
- Documented exit codes for `generate`, `preview` and `build`: 0 ok, 1 some sites failed, 2 bad input or usage, 3 DuckDB missing, 4 map data unavailable, 70 unexpected error. `--quiet` and `--log-format json` for what goes to standard error. A missing DuckDB raises `Curtilage::DependencyError`.
|
|
16
|
+
- Every result has a confidence from 0 to 1 (`Result#confidence`) with the factors behind it (`Result#confidence_factors`): rule-based, each unmet factor (fallback used, pin off the building, no mapped parking, no road frontage, homes next door, ...) takes a documented weight off 1. It's in GeoJSON, NDJSON, CSV and KML; `curtilage generate --min-confidence N` leaves out results below N, and the preview can sort by it.
|
|
17
|
+
- Every result's explanation also comes as structured steps (`Result#steps`, `steps` in GeoJSON and NDJSON): step name, the option that set its distance, the map-data ids involved, the distance used, and the premises area before and after. The explanation gains one line where the lot is added, with the areas.
|
|
18
|
+
- Optional zones for arrival detection, nested with the premises: an approach zone (`approach_m:`, `--approach`, the premises grown by 150 m by default) and an estimated pickup zone (`pickup_m:`, `--pickup`, mapped parking within 25 m of the building, inside the premises). In every output format and the preview.
|
|
19
|
+
- Driveway entrances name the street they open onto (`details[:entrances]`, `Result#entrances`: point, street name and class, driveway id), shown in KML and on the preview. With a pickup zone, an estimated staging point (`Result#staging_point`) where a driver might wait.
|
|
20
|
+
- Pin quality on every result (`Result#pin_quality`: on a building, on a road, near a building or far, with the distance to the nearest building), and optional snapping (`snap_m:`, `--snap`): a pin off any building moves onto the nearest one, flagged `pin_moved`, so a geocoded pin on the street no longer pulls the premises toward the road.
|
|
21
|
+
- `curtilage places` and `Curtilage.places`: pins from Overture Maps places by category, brand or place id, in a region or box, as CSV, NDJSON or GeoJSON that `generate` reads. Each place names its sources and licences.
|
|
22
|
+
- `candidates: N` (`--candidates N`): for ambiguous sites, up to N other premises (another building near the pin, the whole shopping centre on a shared lot, the building rectangle when confidence is low), each a full result with its own confidence and flags, most confident first.
|
|
23
|
+
- Your own named profiles from a JSON or YAML file (`Curtilage::Profiles.load`, `--profiles FILE --preset NAME`): sets of generation options, optionally starting from a built-in preset, checked at load.
|
|
24
|
+
- Corrections: `corrections:` (`--corrections FILE`, matched by id; the gem's own output, edited, works) uses your polygons instead of generating, validated and marked manual (`method_name: :manual`, data source `manual`). `Formats.read_results` reads result files back.
|
|
25
|
+
- `curtilage diff OLD NEW` (`Curtilage::Diff`): compares two runs site by site (IoU, area change, ok, flags gained and lost, confidence) and marks sites that changed beyond a threshold for review, exiting 1 when any need it.
|
|
26
|
+
- Big batches from the command line: `curtilage generate` works in chunks of 500 sites, shows progress with an ETA on a terminal (`--progress` to force it), streams NDJSON and CSV so memory stays flat, and `--resume` carries on an interrupted run from where it stopped. Without `--cache-dir`, a region a run builds is shared by every chunk.
|
|
27
|
+
- The public benchmark has hand-drawn references for its ten sites (traced on public-domain USGS imagery) and a committed baseline (`benchmark/baseline.json`).
|
|
28
|
+
- A `precision:` option sets the decimal places of output coordinates (default 7, as before).
|
|
29
|
+
- `curtilage doctor` checks everything the gem needs outside Ruby with a fix for each problem (DuckDB version, with a warning outside the tested 1.4 and 2.0; extensions; the cache folder), and takes `--network` (are the map-data hosts reachable) and `--json`; it exits 1 when something's missing.
|
|
30
|
+
- A `validation:` option raises or lowers the validation limits for generated polygons (e.g. `{ max_area_error_m2: 300_000 }` for a big-box store's lot, which could only ever get the fallback before). The limits are documented in the reference.
|
|
31
|
+
- CSV output has an `attribution` column, and KML credits every source in the document's description.
|
|
32
|
+
- A "Data licence" section in the README and the reference: what the ODbL asks of results (attribution, derivative databases, produced works), with links.
|
|
33
|
+
- A "Privacy" section in the README: what each data source and mode reveals, and to which host.
|
|
34
|
+
- A public benchmark in the repository (not the gem): `rake benchmark` scores results against hand-drawn references, overall and per category, on a pinned Overture release, and `rake benchmark:compare` diffs two runs. It ships as a skeleton with placeholder sites.
|
|
35
|
+
|
|
36
|
+
### Changed
|
|
37
|
+
|
|
38
|
+
- Lookups in local built files are about three times faster (7 ms to 2 ms a pin): one scan joined to the pins' boxes instead of a scan per pin. Files in a bucket keep a scan per pin, so only the parts near each pin are read. New builds use smaller row groups (5,000 rows), which speeds up those reads; existing builds work as before.
|
|
39
|
+
- Reading map features is faster (8 ms to 6.6 ms a site): checking polygons for self-intersection sweeps edges in order instead of comparing every pair, with the same answers.
|
|
40
|
+
- Generation is faster with identical results: road trims no longer sample road segments too far from the building to matter. About five times on ordinary buildings (34 ms to 7 ms a site on 500 made-up pins), about 1.4 times on busy commercial sites (median 92 ms to 65 ms on a held-out set).
|
|
41
|
+
- Results no longer depend on the order map data arrives in (DuckDB promises no row order, so a re-run could give a different polygon on about a fifth of sites). Neighbouring buildings are now cut nearest first, and the input is sorted into one order before the rules run. Some polygons change: on a private held-out set, mean IoU against hand-drawn premises went from 0.469 to 0.466 (random input orders used to give 0.464-0.466).
|
|
42
|
+
|
|
43
|
+
### Security
|
|
44
|
+
|
|
45
|
+
- Downloads refuse any host but Geofabrik, Overture's catalogue and Microsoft's footprint host.
|
|
46
|
+
- One pin check for every entry point: coordinates must be finite plain decimals in range. Hexadecimal (`0x1A`) and underscores (`1_0`) used to be read as numbers from pin files and `--pin`, out-of-range values from files reached the results, and `Curtilage.generate` didn't check its pin. A bad `--pin` now gives a message instead of a stack trace.
|
|
47
|
+
- Pin files are refused up front if they aren't valid UTF-8 or contain NUL bytes, and capped as they're read (field length, columns, rows, GeoJSON features), so an oversized file fails early with a clear message.
|
|
48
|
+
- Generation options are range-checked (no negative or kilometre-scale distances, whole-number vertex counts), and an Overture `release:` must look like a release name (it goes into a URL path).
|
|
49
|
+
- DuckDB queries have a timeout (600 s for lookups and Overture reads, `CURTILAGE_DUCKDB_TIMEOUT` or `lookup: { timeout: }`; 3600 s for builds), after which DuckDB and anything it started are stopped. Output is read as it arrives and DuckDB is stopped once it passes the cap, instead of reading 200 MB before checking. Lookups and Overture reads cap DuckDB at 1 GB of memory (`lookup: { memory_limit: }`). Error messages no longer quote the failed query, which could include the box around a pin. `doctor` shows the path of the DuckDB binary it runs.
|
|
50
|
+
- The preview page carries a Content-Security-Policy that allows only its own inline style and script, by hash, and no loads, so a missed escape couldn't run script; Unicode direction controls are dropped from the names it shows.
|
|
51
|
+
- CSV output guards more ways a spreadsheet runs a cell as a formula: a leading `|` or `%`, full-width forms, and any of them after leading whitespace, in every column.
|
|
52
|
+
- `--out` files are written atomically, and a symbolic link at the target is refused before any work starts.
|
|
53
|
+
- Fuzz tests for the CSV and GeoJSON readers, map-data parsing, geometry on degenerate input, validation, and generation near the poles and the antimeridian (`FUZZ_ITERATIONS` for longer runs). They found no crash; sites on the antimeridian get no polygon (now a known limitation).
|
|
54
|
+
- Zip extraction caps what the layers may inflate to (20 GB in all, 200 times per member), and a whole zip downloaded when a server can't serve ranges gets the same name and size checks before `unzip`, which now drops folder paths.
|
|
55
|
+
- Builds record the size and SHA256 of every file they download in the region's metadata, and warn when a rebuild finds Geofabrik's file for the same date has changed.
|
|
56
|
+
- The cache folder is created readable only by you, and one that another user owns or everyone can write to is refused. Builds record their Parquet file's size and SHA256; a cached file that's missing or the wrong size is rebuilt (caches built by earlier versions rebuild once), and `curtilage doctor --verify DIR` checks every file's hash.
|
|
57
|
+
- Interrupting a run (Ctrl-C) stops DuckDB too; it has its own process group, so before this the caller waited for the query to finish. A failed or interrupted download leaves no `.part` file, and `curtilage build` without `--work` uses a private temporary folder instead of a fixed name in `/tmp`.
|
|
58
|
+
- Offline mode (`CURTILAGE_OFFLINE=1`): extensions are loaded but never installed, and downloads, Overture reads and bucket reads are refused. `doctor` prints the extension versions it loads, and builds record the DuckDB and `spatial` versions. A test checks that no SQL the gem builds relaxes extension signature checks. `curtilage build` reports errors as a message instead of a stack trace.
|
|
59
|
+
- `generate_many` checks every pin before fetching any data (a bad pin used to fail the batch after builds had run), takes at most 100,000 pins per call (`max_pins:`), refuses unknown `data:` options, and checks `parallel_builds` (1 to 8), `max_age_days` and `auto_build_min_pins`.
|
|
60
|
+
- In a batch, a site whose generation raises gets a result flagged `error` (with the error in its explanation) instead of aborting every other site; generation options are checked once, before any data is fetched.
|
|
61
|
+
- The Docker image pins its base image by digest, checks the DuckDB download against a pinned SHA256, leaves curl and unzip out of the image that runs, and works offline and with a read-only root filesystem. CI actions are pinned to commit SHAs; CodeQL and `bundler-audit` run in CI, and CI builds the image and runs it with no network.
|
|
62
|
+
- Downloads honour `HTTPS_PROXY` and `NO_PROXY` without `curl` too (Ruby's client read `http_proxy` instead).
|
|
63
|
+
- `unzip` is no longer needed: a zip downloaded whole (when a server can't serve byte ranges) is read by the gem itself, with the same name, size and CRC checks as range downloads.
|
|
64
|
+
- Text placed into DuckDB SQL (paths, bucket URLs, folders) may not contain line breaks or NUL bytes, `memory_limit` must look like `"400MB"`, and `threads` must be 1 to 64. Tests push crafted values through every path into SQL.
|
|
65
|
+
|
|
66
|
+
### Fixed
|
|
67
|
+
|
|
68
|
+
- Results from catalogues and Geofabrik builds carry the build's attribution, so builds with Microsoft footprints credit Microsoft (they credited only OpenStreetMap). Overture results that can use non-OSM buildings credit each source used.
|
|
69
|
+
- Microsoft's Global ML Building Footprints are under CDLA Permissive 2.0, not ODbL as the docs and build metadata said.
|
|
70
|
+
|
|
71
|
+
- Text is read as UTF-8 whatever the system locale. Under `LANG=C` (common in containers and cron jobs), a map feature with a non-ASCII name (such as "Café") made lookups raise an encoding error, and so did a data catalogue whose attribution contained `©`.
|
|
72
|
+
- Works with DuckDB 2.0 (what Homebrew installs) as well as 1.4: it renamed the extension folder setting and deprecated `s3_region` (both warned inside the JSON output), dropped the `->` lambda syntax and reads stored geometry as bytes (1.4 reads it as a geometry; a cast suits both). Run from an AI coding tool, DuckDB 2.0's "agent mode" is turned off for the gem's own calls, since it changes the output.
|
|
73
|
+
- No warning on Ruby 4.0, which removed the CGI library (only `cgi/escape` is loaded now). CI tests Ruby 4.0 too.
|
|
74
|
+
- Small downloads (region and file indexes) stop as soon as they pass their size cap, instead of after the whole response has arrived.
|
|
75
|
+
- Errors are `Curtilage::Error` (or `ArgumentError` for bad input) as documented: an unreadable catalogue file, a bad Geofabrik index or zip data that won't inflate used to surface as `JSON::ParserError`, `KeyError` or `Zlib::DataError`, and a pin containing `nil` as `TypeError`.
|
|
76
|
+
- The cached Geofabrik index and each region's `.json` are written atomically, and a cached index that can't be read is fetched again. A copy cut short (a killed process, a full disk) used to break every run until it aged out after a month.
|
|
77
|
+
- When one of several parallel builds fails, the others finish (and start no new region) before the error is raised; the temporary folder used to be deleted under builds still running. Download threads do the same, and failed threads no longer print to stderr.
|
|
78
|
+
- `Build.run` refuses a `date:` that isn't `YYMMDD` (it goes into a file name and URL).
|
|
79
|
+
|
|
5
80
|
## [0.3.0] - 2026-11-22
|
|
6
81
|
|
|
7
82
|
### Breaking
|
data/README.md
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
# curtilage
|
|
2
2
|
|
|
3
|
+
[](https://badge.fury.io/rb/curtilage)
|
|
4
|
+
|
|
3
5
|
*Curtilage: the land immediately around a building, such as its yard, drive and lot.*
|
|
4
6
|
|
|
5
7
|
Generates a site's **premises polygon** (the building plus its customer-facing lot) and a **store zone** (the building's own outline) from free map data, so nobody has to draw them by hand.
|
|
6
8
|
|
|
7
|
-
**Status:** 0.
|
|
9
|
+
**Status:** 0.4, rule-based; the API may change before 1.0. On the [public benchmark](benchmark/README.md) (ten public sites in Delaware, with references drawn to the whole customer-facing lot), all ten get a valid polygon and the median overlap (IoU) is 0.30: the premises mostly fall short of the whole lot, which the next round of rule changes targets. Anyone can rerun it (`rake benchmark`). On private sets of real sites that can't be published:
|
|
10
|
+
|
|
11
|
+
- On 164 sites the rules had never seen, 159 (97%) got a polygon that passed the gem's own validation (pin inside, closed, no self-intersection, plausible size). Nearly all five misses were buildings missing from OpenStreetMap. Passing validation means usable, not necessarily right.
|
|
12
|
+
- Against hand-drawn premises for those sites, the median overlap (IoU) was 0.47. Hand-drawn polygons often hug the building more tightly than the whole lot this gem aims for, so IoU undersells generous but correct results.
|
|
13
|
+
- The 20 sites used to tune the rules were also reviewed by eye on aerial imagery, which is a subjective check. An earlier version gave similar validity on 51 sites in the US, Brazil and Hungary (47 of 51).
|
|
8
14
|
|
|
9
15
|
## Quick start
|
|
10
16
|
|
|
11
|
-
1. Install the gem (`gem install curtilage`, or `gem "curtilage"` in your Gemfile) and the [DuckDB CLI](https://duckdb.org/docs/installation/) 1.4. Check with `curtilage doctor`; DuckDB's extensions install themselves.
|
|
17
|
+
1. Install the gem (`gem install curtilage`, or `gem "curtilage"` in your Gemfile; Ruby 3.2 or newer) and the [DuckDB CLI](https://duckdb.org/docs/installation/), 1.4 LTS or 2.0 (`brew install duckdb` gives 2.0). Check with `curtilage doctor`; DuckDB's extensions install themselves.
|
|
12
18
|
2. Ask for premises:
|
|
13
19
|
|
|
14
20
|
```ruby
|
|
@@ -26,7 +32,7 @@ Or from the shell:
|
|
|
26
32
|
|
|
27
33
|
```sh
|
|
28
34
|
curtilage generate --pin -80.0,35.0 # one pin: GeoJSON to the screen
|
|
29
|
-
curtilage generate --in sites.csv --out premises.csv # a file of pins in; CSV, GeoJSON or KML out
|
|
35
|
+
curtilage generate --in sites.csv --out premises.csv # a file of pins in; CSV, GeoJSON, NDJSON or KML out
|
|
30
36
|
curtilage preview --in sites.csv # a page with a map of each site, to check by eye
|
|
31
37
|
```
|
|
32
38
|
|
|
@@ -40,6 +46,16 @@ store-2,-80.1,35.2
|
|
|
40
46
|
|
|
41
47
|
That's all the setup: map data is fetched as needed. No Ruby? Use [Docker](#docker). Everything else (every option, flag and command) is in the [reference](docs/reference.md).
|
|
42
48
|
|
|
49
|
+
## Data licence
|
|
50
|
+
|
|
51
|
+
The code is MIT-licensed; the polygons are not. Every result is derived from [OpenStreetMap](https://www.openstreetmap.org/copyright) data, which is available under the [Open Database License (ODbL) 1.0](https://opendatacommons.org/licenses/odbl/1-0/):
|
|
52
|
+
|
|
53
|
+
- **Credit OpenStreetMap wherever results are shown or shared**, and make clear the data is under the ODbL ([OSMF attribution guidelines](https://osmfoundation.org/wiki/Licence/Attribution_Guidelines)). Every output carries what to credit: `attribution` in GeoJSON properties and in CSV, the KML description, the preview page.
|
|
54
|
+
- **Storing or publishing many results** can make a *derivative database*. If you use one publicly, the ODbL asks you to offer it under the ODbL too (section 4.4).
|
|
55
|
+
- **A map image or similar *produced work*** made from results needs a notice that it contains data from OpenStreetMap under the ODbL (section 4.3); the image itself doesn't have to be ODbL.
|
|
56
|
+
- Overture data is also credited to the Overture Maps Foundation, and Overture's non-OSM buildings to their source, when a result could use them. Microsoft's footprints are under [CDLA Permissive 2.0](https://cdla.dev/permissive-2-0/).
|
|
57
|
+
- The OSMF [community guidelines](https://osmfoundation.org/wiki/Licence/Community_Guidelines) cover the common cases (produced works, what counts as substantial, collective databases, geocoding). This section is a summary, not legal advice.
|
|
58
|
+
|
|
43
59
|
## How it works
|
|
44
60
|
|
|
45
61
|
1. **Data.** Buildings, parking lots, roads and railways from OpenStreetMap, picked automatically (`source: :auto`, the default):
|
|
@@ -74,6 +90,9 @@ end
|
|
|
74
90
|
- Styles: `preset: :whole_lot` (default), `:tight` (building plus a small margin) or `:centre`. `store_zone: false` skips the store zone. Every rule's distance is an option ([reference](docs/reference.md#generation-options)).
|
|
75
91
|
- Built ahead of time, for instant lookups: `curtilage build tennessee`, then `generate_many(pins, catalogue: Curtilage::Catalogue.from_dir("."))`. Files can also live in a bucket (`s3://`, `gs://`, `https://`).
|
|
76
92
|
- Just the building at a pin: `Curtilage.building_at(pin)`.
|
|
93
|
+
- No pin list? `curtilage places --region virginia --category pharmacy` (or `--brand`) lists matching places from Overture Maps as pins to generate from (`Curtilage.places` in Ruby). Each row names its sources and licences.
|
|
94
|
+
- Big sites (a big-box store's lot can pass 100,000 m2, where validation stops by default): raise the limits, e.g. `validation: { max_area_m2: 200_000, max_area_error_m2: 300_000 }` ([reference](docs/reference.md#validation-limits)).
|
|
95
|
+
- Fix the few bad sites once: `--corrections fixed.geojson` (your edited output, matched by id) uses your polygons instead of generating them, marked manual. After a data refresh, `curtilage diff last.ndjson new.ndjson` lists only the sites whose premises changed enough to look at again.
|
|
77
96
|
- Check a polygon someone already drew: `Curtilage::Audit.check(pin, ring, features)` returns `:ok`, `:review` (with reasons) or `:invalid`.
|
|
78
97
|
|
|
79
98
|
### What each result holds
|
|
@@ -83,18 +102,24 @@ end
|
|
|
83
102
|
| `ok?` | It passed validation. Never save one that isn't. |
|
|
84
103
|
| `ring` / `store_ring` | The premises and the store zone, `[[lng, lat], ...]` closed. |
|
|
85
104
|
| `flags` | Reasons a person should look first ([below](#flags)). |
|
|
105
|
+
| `pin_quality` | Where the pin was given: `on_building`, `on_road`, `near_building` or `far`, and how far from the nearest building. With `snap_m: 30`, a pin off any building is moved onto the nearest one (flag `pin_moved`). |
|
|
106
|
+
| `confidence` | 0 to 1, from documented rules (fallback used, pin off the building, no mapped parking, ...), to decide which sites to review first ([reference](docs/reference.md#confidence)). |
|
|
86
107
|
| `explanation` | Each step, in plain words. |
|
|
87
108
|
| `details` | The building (id, name, type, area, outline), mapped parking inside the premises and an estimate of spaces, street frontage, and where driveways meet the street. Rough, like the map data. |
|
|
109
|
+
| `candidates` | With `candidates: 3`, other premises an ambiguous site could have (another building near the pin, the whole shopping centre, a tighter shape), each with its own confidence and flags. |
|
|
110
|
+
| `approach_ring`, `pickup_ring` | Optional zones for arrival detection (`approach_m: 150`, `pickup_m: 25`): the premises grown for "customer is near", and the parking right by the store (estimated). Nested with the premises ([reference](docs/reference.md#zones)). |
|
|
88
111
|
| `buffered(15)` | The premises grown 15 m (rounded corners), e.g. for a geofence with a margin; negative shrinks. |
|
|
89
112
|
| `to_geojson`, `to_wkt` | Ready to draw or store. GeoJSON carries everything above and the attribution to show. |
|
|
113
|
+
| `attribution` | What to credit wherever the result is shown ([Data licence](#data-licence)). |
|
|
90
114
|
|
|
91
115
|
### Files
|
|
92
116
|
|
|
93
|
-
`curtilage generate --in FILE --out FILE` reads pins from a CSV (as above)
|
|
117
|
+
`curtilage generate --in FILE --out FILE` reads pins from a CSV (as above), a GeoJSON file of points or NDJSON (one site per line; `--in -` reads standard input), and writes:
|
|
94
118
|
|
|
95
|
-
- **CSV** (`.csv`): one row per pin with its id, `ok`, flags, the details
|
|
119
|
+
- **CSV** (`.csv`): one row per pin with its id, `ok`, flags, the details, the polygons as WKT and the attribution. Opens in any spreadsheet.
|
|
96
120
|
- **GeoJSON** (`.geojson`): one FeatureCollection, the premises and store zone of each pin, with the id in each feature's properties.
|
|
97
|
-
- **
|
|
121
|
+
- **NDJSON** (`.ndjson`, or `--format ndjson`): one GeoJSON Feature per site per line, with a [versioned schema](docs/schema/site-v1.json). For scripts in any language, and for GDAL, QGIS or DuckDB.
|
|
122
|
+
- **KML** (`.kml`): for Google Earth, with the attribution in its description.
|
|
98
123
|
|
|
99
124
|
From Ruby, `Curtilage::Formats` does the same ([reference](docs/reference.md#files-curtilageformats)).
|
|
100
125
|
|
|
@@ -109,9 +134,9 @@ From Ruby, `Curtilage::Formats` does the same ([reference](docs/reference.md#fil
|
|
|
109
134
|
|
|
110
135
|
Under each map: the flags (hover for what they mean), the building and premises areas, parking and an estimate of spaces, street frontage, the number of entrances, and "How it was made", the step-by-step explanation. Invalid results say why.
|
|
111
136
|
|
|
112
|
-
At the top, a count of sites that are ok, flagged or unusable, and controls to show only some (sites that need a look, invalid ones, or those with a given flag) and to sort them (input order, needs a look first, id, or premises size).
|
|
137
|
+
At the top, a count of sites that are ok, flagged or unusable, and controls to show only some (sites that need a look, invalid ones, or those with a given flag) and to sort them (input order, needs a look first, lowest confidence first, id, or premises size).
|
|
113
138
|
|
|
114
|
-

|
|
139
|
+

|
|
115
140
|
|
|
116
141
|
*Randomly chosen locations, not real sites. Map data © OpenStreetMap contributors.*
|
|
117
142
|
|
|
@@ -136,17 +161,20 @@ The current folder is mounted at `/work`, so file names are relative to it. The
|
|
|
136
161
|
| `large_building` | Building over 5,000 m2: may be shared by several tenants |
|
|
137
162
|
| `small_building` | Building under 50 m2: may be a kiosk or canopy rather than the store |
|
|
138
163
|
| `building_not_under_pin` | No building under the pin; the nearest one within 30 m was used |
|
|
164
|
+
| `pin_moved` | The pin wasn't on a building and was moved onto the nearest one (`snap_m:`): check it's the right one |
|
|
139
165
|
| `store_may_be_unit` | Store zone is a building over 1,500 m2: the store may be one unit of it |
|
|
140
166
|
| `shopping_centre` | `scope: :centre` mapped the whole centre |
|
|
141
167
|
| `fallback` | The main method failed validation; the building rectangle was used |
|
|
142
168
|
| `partial_data` | Part of the area around the pin is in a region that isn't built |
|
|
143
169
|
| `ml_footprint` | Built on a machine-learned footprint, not an OSM building |
|
|
144
170
|
| `no_data` | No map data covers the pin |
|
|
171
|
+
| `error` | Generating this site raised an error (see its explanation); the rest of the batch went on |
|
|
145
172
|
|
|
146
173
|
### Speed
|
|
147
174
|
|
|
148
|
-
- Generate: about
|
|
149
|
-
-
|
|
175
|
+
- Generate: about 10 ms per site for an ordinary building, about 65 ms (median) for the busier commercial sites tested; a few hundred ms in dense blocks.
|
|
176
|
+
- Big batches: 10,000 made-up pins in one state took under 2.5 minutes from a prebuilt file on a laptop (about 70 sites a second), with Ruby under 650 MB however long the batch. `curtilage generate` works in chunks of 500, shows progress on a terminal, streams NDJSON and CSV, and `--resume` carries on an interrupted run.
|
|
177
|
+
- Prebuilt files: about 2 ms a pin in batches (one DuckDB call serves 500 pins); about 85 ms for a single lookup, mostly starting DuckDB.
|
|
150
178
|
- Overture (the default for scattered pins): about 5-10 s per area; pins within a few km of each other share it. A test batch of 51 sites in 17 regions across three continents took 4 minutes from a cold start; the 164 (143 pins read from Geofabrik builds, 21 from Overture) took under 6.
|
|
151
179
|
- Geofabrik builds (the default once 10+ pins share a region): 1-5 minutes per US state the first time (Texas, the largest tested, about 4.5 minutes and under 650 MB of memory), then as above. Downloads use `curl` when it's installed, and `data: { parallel_builds: 2 }` builds two regions at once on machines with the memory.
|
|
152
180
|
|
|
@@ -159,15 +187,35 @@ Rules on open map data go a long way, but some sites need a person. These are th
|
|
|
159
187
|
- **Sites spread over several buildings** (compounds, campuses). The premises cover the building at the pin only, so they come out too small.
|
|
160
188
|
- **Dense rowhouse blocks.** Cuts toward many close neighbours can leave a thin sliver.
|
|
161
189
|
- **`near_houses` is noisy in dense urban areas,** where almost every site borders homes. It's more meaningful in suburbs.
|
|
162
|
-
- **The polygon is always convex
|
|
190
|
+
- **The polygon is always convex.** Entrance notches are approximated, and an L-shaped site (a building plus a lot to one side) gets a diagonal edge that can cross a neighbour's parking or clip its buildings.
|
|
191
|
+
- **Lots reaching more than 60 m from the building** (deep lots, big parking fields) are cut short (`parking_max_extent_m`), and entrances beyond the claimed lot aren't taken in unless a mapped driveway leads to them.
|
|
192
|
+
- **Shopping centres.** A shared lot is split by nearest building, which is crude; internal streets mapped as service roads don't bound the lot; and a building at an angle to its car park gets an oversized rectangle that can spill into neighbouring lots. Ring roads tagged `unclassified` can cut a store off from its own car park. Check results flagged `store_may_be_unit` or on shared lots, or try `scope: :centre` or `candidates: 3`.
|
|
193
|
+
- **Sites within about 100 m of the antimeridian** (180° longitude: parts of Fiji, Chukotka, the Aleutians) get no polygon: premises can't cross that line, so validation refuses them.
|
|
163
194
|
|
|
164
195
|
## Building footprints: OSM, or OSM plus machine-learned
|
|
165
196
|
|
|
166
|
-
By default all buildings come from OpenStreetMap. Where OSM is missing buildings, you can opt in to [Microsoft's Global ML Building Footprints](https://github.com/microsoft/GlobalMLBuildingFootprints) (
|
|
197
|
+
By default all buildings come from OpenStreetMap. Where OSM is missing buildings, you can opt in to [Microsoft's Global ML Building Footprints](https://github.com/microsoft/GlobalMLBuildingFootprints) (CDLA Permissive 2.0): build with `--ml-footprints microsoft` (or `ml_footprints: "microsoft"`), then generate with `buildings: :osm_filled` or `:ml`. With `source: :overture`, Overture's non-OSM buildings play the same role. Results built on one carry the `ml_footprint` flag, and their attribution credits the footprints' source.
|
|
167
198
|
|
|
168
|
-
##
|
|
199
|
+
## Privacy
|
|
169
200
|
|
|
170
|
-
|
|
201
|
+
Pins never leave the machine as coordinates: they aren't put in any URL or request, and appear only in your own outputs and local error messages. What hosts can learn depends on the data source:
|
|
202
|
+
|
|
203
|
+
| When | Host | What it learns |
|
|
204
|
+
|---|---|---|
|
|
205
|
+
| Geofabrik build (`source: :geofabrik`, or `:auto` where 10+ pins share a region or it's cached) | `download.geofabrik.de` | Which region(s) you build, from the region index and the region's file. Not where in the region. |
|
|
206
|
+
| Overture read (`source: :overture`, or `:auto` for scattered pins) | `stac.overturemaps.org` | Which Overture release you use. Nothing about the pins. |
|
|
207
|
+
| `curtilage places` / `Curtilage.places` | Overture's storage, and Geofabrik for `--region` | The box or region you search, and Geofabrik's region index is downloaded. No pins are involved. |
|
|
208
|
+
| | Overture's storage (Amazon S3, `overturemaps-us-west-2`) | Which files and parts of files are read: roughly where each pin is, to within a few km. |
|
|
209
|
+
| Your own built files (`catalogue:`, `parquet:`) on disk | none | Nothing. |
|
|
210
|
+
| ... in your bucket (`s3://`, `gs://`, `https://`) | your bucket's host | The parts of files read: roughly where each pin is. |
|
|
211
|
+
| Microsoft footprints in a build (opt-in) | Microsoft's footprint host | Which tiles cover the region you build. |
|
|
212
|
+
| First run, or `curtilage doctor` | DuckDB's extension repository | That you install the `spatial` and `httpfs` extensions, and your DuckDB version and platform. |
|
|
213
|
+
|
|
214
|
+
- **For a sensitive list of locations, use `source: :geofabrik`** (or `CURTILAGE_SOURCE=geofabrik`): hosts then learn only which regions you build. `:auto` reads scattered pins from Overture.
|
|
215
|
+
- The gem's own downloads go only to Geofabrik, Overture's catalogue and Microsoft's footprint host, and anything else is refused. DuckDB reads Overture's storage, your bucket and its extension repository itself.
|
|
216
|
+
- If a DuckDB query fails, its error message can quote part of the query, including the coordinates of the box around a pin. That stays on your machine unless your app forwards errors to an outside service.
|
|
217
|
+
- To guarantee nothing leaves the machine, set `CURTILAGE_OFFLINE=1` and use prebuilt files or a cache: downloads, extension installs and Overture or bucket reads are then refused.
|
|
218
|
+
- The preview page loads nothing from the internet. Building the Docker image fetches DuckDB from its GitHub releases and its extensions from DuckDB's repository.
|
|
171
219
|
|
|
172
220
|
## Layout
|
|
173
221
|
|
|
@@ -179,7 +227,7 @@ The gem only talks to public map-data hosts, and only when it needs data: Geofab
|
|
|
179
227
|
| `lib/curtilage/generator_store.rb` | The store zone |
|
|
180
228
|
| `lib/curtilage/generator_details.rb` | Facts about the site: parking, frontage, entrances |
|
|
181
229
|
| `lib/curtilage/result.rb` | What generation returns: GeoJSON, WKT, buffering |
|
|
182
|
-
| `lib/curtilage/formats.rb` | Pins in from CSV or
|
|
230
|
+
| `lib/curtilage/formats.rb` | Pins in from CSV, GeoJSON or NDJSON; results out as GeoJSON, NDJSON, CSV or KML |
|
|
183
231
|
| `lib/curtilage/preview.rb` | The HTML review page |
|
|
184
232
|
| `lib/curtilage/features.rb` | Parses nearby map features (untrusted) and projects them to metres |
|
|
185
233
|
| `lib/curtilage/geometry.rb` | Plain-Ruby planar geometry |
|
|
@@ -202,21 +250,27 @@ The gem only talks to public map-data hosts, and only when it needs data: Geofab
|
|
|
202
250
|
| `docs/reference.md` | Every option, setting, flag and command |
|
|
203
251
|
| `sql/build_from_shapefiles.sql` | DuckDB query: shapefiles to a features Parquet file |
|
|
204
252
|
| `test/` | Tests, using made-up coordinates only |
|
|
253
|
+
| `benchmark/` | The public benchmark: sites, hand-drawn references, the runner ([how to run it](benchmark/README.md)) |
|
|
205
254
|
|
|
206
255
|
## Development
|
|
207
256
|
|
|
208
257
|
```sh
|
|
209
258
|
bin/setup
|
|
210
259
|
bundle exec rake # tests and RuboCop
|
|
260
|
+
bundle exec rake benchmark # the public benchmark (see benchmark/README.md)
|
|
211
261
|
```
|
|
212
262
|
|
|
213
|
-
|
|
263
|
+
No Ruby gem dependencies. Getting data needs the [DuckDB](https://duckdb.org/) CLI (1.4 LTS or 2.0 are tested; `curtilage doctor` checks it and says how to install it); its `spatial` and `httpfs` extensions install themselves on first use. Point `CURTILAGE_DUCKDB` and `CURTILAGE_EXTENSIONS` at them if they aren't in the default places (`curtilage doctor` checks). Nothing else is needed: `curl` is used when it's installed, as a faster download path.
|
|
264
|
+
|
|
265
|
+
## Versioning
|
|
266
|
+
|
|
267
|
+
- The public API is what [docs/reference.md](docs/reference.md) documents: the Ruby methods and their options, result fields, flags, errors, and the command line with its exit status. Anything not listed there is internal and may change at any time.
|
|
268
|
+
- Until 1.0, a minor release (0.x) may change the public API. Every such change is listed under **Breaking** in [CHANGELOG.md](CHANGELOG.md), with how to update. Patch releases don't change it.
|
|
269
|
+
- Rule improvements can change the polygons a release produces; the changelog says when they do.
|
|
214
270
|
|
|
215
|
-
##
|
|
271
|
+
## This repository
|
|
216
272
|
|
|
217
|
-
-
|
|
218
|
-
- With `source: :overture`: also © Overture Maps Foundation. With ML footprints: also Microsoft Global ML Building Footprints (ODbL).
|
|
273
|
+
- The code is MIT-licensed (see `LICENSE.txt`); results keep the map data's licence ([Data licence](#data-licence)).
|
|
219
274
|
- Downloaded files and built Parquet files are OSM-derived data. They're never committed to this repository (see `.gitignore`).
|
|
220
|
-
- This repository must never contain real site locations,
|
|
221
|
-
-
|
|
222
|
-
- Security issues: see `SECURITY.md` (report privately through GitHub).
|
|
275
|
+
- This repository must never contain real site locations, private data or credentials. Tests and examples use made-up coordinates.
|
|
276
|
+
- Security issues: see `SECURITY.md` (report privately through GitHub); the threat model is in [docs/security.md](docs/security.md).
|
data/SECURITY.md
CHANGED
|
@@ -4,12 +4,27 @@
|
|
|
4
4
|
|
|
5
5
|
Please report security issues privately through GitHub: on this repository, open the **Security** tab and choose **Report a vulnerability**. Don't open a public issue for them.
|
|
6
6
|
|
|
7
|
-
Include what you found, how to reproduce it
|
|
7
|
+
Include what you found, how to reproduce it (with made-up or public locations, never private site data), and the version you used.
|
|
8
|
+
|
|
9
|
+
You should get an acknowledgement within 7 days. Confirmed issues are fixed in a new release, usually within 30 days, and disclosed in a GitHub security advisory and the changelog once the fix is out; you'll be credited unless you'd rather not be.
|
|
8
10
|
|
|
9
11
|
## Supported versions
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
curtilage is pre-1.0: fixes go into the latest release only. Upgrade to get them.
|
|
14
|
+
|
|
15
|
+
## Threat model
|
|
16
|
+
|
|
17
|
+
[docs/security.md](docs/security.md) says what the gem trusts and doesn't, who might attack it, and the defences.
|
|
12
18
|
|
|
13
19
|
## Scope
|
|
14
20
|
|
|
15
|
-
|
|
21
|
+
In scope:
|
|
22
|
+
|
|
23
|
+
- The gem's code and the `curtilage` command, including how it runs external programs (the DuckDB CLI, and `curl` when installed) and builds the SQL it gives DuckDB.
|
|
24
|
+
- Downloads of map data (Geofabrik, Overture's catalogue, opt-in Microsoft footprints): host allow-list, size caps, archive handling, the cache folder.
|
|
25
|
+
- Parsing untrusted input: pin files and map data.
|
|
26
|
+
- Outputs: the HTML preview, CSV, KML, GeoJSON and files written with `--out`.
|
|
27
|
+
- The repository's Docker image and CI workflows.
|
|
28
|
+
- `curtilage serve`, once it exists.
|
|
29
|
+
|
|
30
|
+
Out of scope: vulnerabilities in DuckDB or its extensions themselves (report them to [DuckDB](https://github.com/duckdb/duckdb/security)); the accuracy of OpenStreetMap or Overture data; and anything that needs control of your configuration (`CURTILAGE_DUCKDB`, `setup_sql:`), which is trusted by design.
|