@mailwoman/spatial 9.1.0 → 9.3.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.
- package/{bbox.ts → lib/bbox.ts} +54 -3
- package/lib/coordinate-bounds.ts +52 -0
- package/{coordinate-formats.ts → lib/coordinate-formats.ts} +16 -3
- package/lib/distance.ts +165 -0
- package/{feature.ts → lib/feature.ts} +1 -1
- package/{geometries → lib/geometries}/collection.ts +4 -4
- package/lib/geometries/index.ts +13 -0
- package/{geometries → lib/geometries}/line-string.ts +2 -2
- package/{geometries → lib/geometries}/point.ts +9 -9
- package/{geometries → lib/geometries}/polygon.ts +93 -89
- package/lib/geometries/ring-blob.ts +521 -0
- package/{google → lib/google}/index.ts +1 -1
- package/{h3 → lib/h3}/cell.ts +83 -1
- package/lib/h3/coverage.ts +45 -0
- package/{h3 → lib/h3}/index.ts +5 -3
- package/lib/h3/interior-cells.ts +138 -0
- package/lib/h3/polygon-cells.ts +462 -0
- package/lib/index.ts +21 -0
- package/{objects.ts → lib/objects.ts} +1 -1
- package/lib/open-location-code.ts +168 -0
- package/{osgb36.ts → lib/osgb36.ts} +2 -2
- package/{polyline.ts → lib/polyline.ts} +1 -1
- package/lib/position.ts +216 -0
- package/lib/projection-transform.ts +115 -0
- package/{regions → lib/regions}/codes.ts +1 -1
- package/{regions → lib/regions}/index.ts +2 -2
- package/lib/tools/ogr-stream.ts +99 -0
- package/lib/tools/ogr.ts +201 -0
- package/{sdk → lib}/well-known-text.ts +2 -1
- package/out/bbox.d.ts +23 -2
- package/out/bbox.d.ts.map +1 -1
- package/out/bbox.js +33 -2
- package/out/bbox.js.map +1 -1
- package/out/coordinate-bounds.d.ts +41 -0
- package/out/coordinate-bounds.d.ts.map +1 -0
- package/out/coordinate-bounds.js +45 -0
- package/out/coordinate-bounds.js.map +1 -0
- package/out/coordinate-formats.d.ts +8 -0
- package/out/coordinate-formats.d.ts.map +1 -1
- package/out/coordinate-formats.js +14 -3
- package/out/coordinate-formats.js.map +1 -1
- package/out/distance.d.ts +84 -0
- package/out/distance.d.ts.map +1 -0
- package/out/distance.js +132 -0
- package/out/distance.js.map +1 -0
- package/out/feature.d.ts +1 -1
- package/out/feature.d.ts.map +1 -1
- package/out/feature.js.map +1 -1
- package/out/geometries/collection.d.ts +4 -4
- package/out/geometries/collection.d.ts.map +1 -1
- package/out/geometries/collection.js.map +1 -1
- package/out/geometries/index.d.ts +5 -4
- package/out/geometries/index.d.ts.map +1 -1
- package/out/geometries/index.js +5 -4
- package/out/geometries/index.js.map +1 -1
- package/out/geometries/line-string.d.ts +2 -2
- package/out/geometries/line-string.d.ts.map +1 -1
- package/out/geometries/line-string.js.map +1 -1
- package/out/geometries/point.d.ts +9 -9
- package/out/geometries/point.d.ts.map +1 -1
- package/out/geometries/point.js +9 -9
- package/out/geometries/point.js.map +1 -1
- package/out/geometries/polygon.d.ts +60 -56
- package/out/geometries/polygon.d.ts.map +1 -1
- package/out/geometries/polygon.js +66 -63
- package/out/geometries/polygon.js.map +1 -1
- package/out/geometries/ring-blob.d.ts +183 -0
- package/out/geometries/ring-blob.d.ts.map +1 -0
- package/out/geometries/ring-blob.js +376 -0
- package/out/geometries/ring-blob.js.map +1 -0
- package/out/google/index.d.ts +1 -1
- package/out/google/index.d.ts.map +1 -1
- package/out/google/index.js +1 -1
- package/out/google/index.js.map +1 -1
- package/out/google/place-id.d.ts.map +1 -1
- package/out/google/place-id.js.map +1 -1
- package/out/h3/cell.d.ts +32 -0
- package/out/h3/cell.d.ts.map +1 -1
- package/out/h3/cell.js +68 -1
- package/out/h3/cell.js.map +1 -1
- package/out/h3/coverage.d.ts +32 -0
- package/out/h3/coverage.d.ts.map +1 -0
- package/out/h3/coverage.js +27 -0
- package/out/h3/coverage.js.map +1 -0
- package/out/h3/index.d.ts +5 -3
- package/out/h3/index.d.ts.map +1 -1
- package/out/h3/index.js +5 -3
- package/out/h3/index.js.map +1 -1
- package/out/h3/interior-cells.d.ts +54 -0
- package/out/h3/interior-cells.d.ts.map +1 -0
- package/out/h3/interior-cells.js +111 -0
- package/out/h3/interior-cells.js.map +1 -0
- package/out/h3/polygon-cells.d.ts +182 -0
- package/out/h3/polygon-cells.d.ts.map +1 -0
- package/out/h3/polygon-cells.js +339 -0
- package/out/h3/polygon-cells.js.map +1 -0
- package/out/index.d.ts +15 -12
- package/out/index.d.ts.map +1 -1
- package/out/index.js +15 -12
- package/out/index.js.map +1 -1
- package/out/objects.d.ts +1 -1
- package/out/objects.d.ts.map +1 -1
- package/out/objects.js +1 -1
- package/out/objects.js.map +1 -1
- package/out/open-location-code.d.ts +48 -0
- package/out/open-location-code.d.ts.map +1 -0
- package/out/open-location-code.js +137 -0
- package/out/open-location-code.js.map +1 -0
- package/out/osgb36.d.ts +2 -2
- package/out/osgb36.d.ts.map +1 -1
- package/out/osgb36.js +1 -1
- package/out/osgb36.js.map +1 -1
- package/out/polyline.d.ts.map +1 -1
- package/out/polyline.js +1 -1
- package/out/polyline.js.map +1 -1
- package/out/position.d.ts +4 -61
- package/out/position.d.ts.map +1 -1
- package/out/position.js +14 -126
- package/out/position.js.map +1 -1
- package/out/projection-transform.d.ts +67 -0
- package/out/projection-transform.d.ts.map +1 -0
- package/out/projection-transform.js +48 -0
- package/out/projection-transform.js.map +1 -0
- package/out/projection.d.ts.map +1 -1
- package/out/projection.js.map +1 -1
- package/out/regions/codes.d.ts.map +1 -1
- package/out/regions/codes.js.map +1 -1
- package/out/regions/index.d.ts +2 -2
- package/out/regions/index.d.ts.map +1 -1
- package/out/regions/index.js +2 -2
- package/out/regions/index.js.map +1 -1
- package/out/regions/names.d.ts.map +1 -1
- package/out/regions/names.js.map +1 -1
- package/out/tools/ogr-stream.d.ts +34 -0
- package/out/tools/ogr-stream.d.ts.map +1 -0
- package/out/tools/ogr-stream.js +74 -0
- package/out/tools/ogr-stream.js.map +1 -0
- package/out/tools/ogr.d.ts +87 -0
- package/out/tools/ogr.d.ts.map +1 -0
- package/out/tools/ogr.js +84 -0
- package/out/tools/ogr.js.map +1 -0
- package/out/tsconfig.test.tsbuildinfo +1 -1
- package/out/{sdk/well-known-text.d.ts → well-known-text.d.ts} +1 -1
- package/out/well-known-text.d.ts.map +1 -0
- package/out/well-known-text.js.map +1 -0
- package/package.json +143 -14
- package/geometries/index.ts +0 -12
- package/index.ts +0 -18
- package/out/sdk/index.d.ts +0 -7
- package/out/sdk/index.d.ts.map +0 -1
- package/out/sdk/index.js +0 -7
- package/out/sdk/index.js.map +0 -1
- package/out/sdk/well-known-text.d.ts.map +0 -1
- package/out/sdk/well-known-text.js.map +0 -1
- package/out/tsconfig.tsbuildinfo +0 -1
- package/position.ts +0 -345
- package/sdk/index.ts +0 -7
- /package/{google → lib/google}/place-id.ts +0 -0
- /package/{projection.ts → lib/projection.ts} +0 -0
- /package/{regions → lib/regions}/names.ts +0 -0
- /package/out/{sdk/well-known-text.js → well-known-text.js} +0 -0
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*/
|
|
6
|
-
import { ResourceError } from "@mailwoman/core/errors";
|
|
7
6
|
/**
|
|
8
7
|
* Predicate for checking if a GeoJSON object is a `Polygon` geometry.
|
|
9
8
|
*/
|
|
@@ -15,6 +14,8 @@ export function isPolygonLiteral(input) {
|
|
|
15
14
|
/**
|
|
16
15
|
* Predicate for checking if a polygon geometry is a solid, i.e. it has no holes.
|
|
17
16
|
*/
|
|
17
|
+
// The parameter admits BOTH paths because distinguishing them is the function's job: defaulted to
|
|
18
|
+
// `SolidPolygonPath`, it cannot be asked about a polygon with holes without the caller asserting past the signature.
|
|
18
19
|
export function isSolidPolygonPath(input) {
|
|
19
20
|
return input.coordinates.length === 1;
|
|
20
21
|
}
|
|
@@ -62,79 +63,81 @@ export function pointInMultiPolygon(lon, lat, polygons) {
|
|
|
62
63
|
return polygons.some((rings) => pointInPolygon(lon, lat, rings));
|
|
63
64
|
}
|
|
64
65
|
/**
|
|
65
|
-
*
|
|
66
|
+
* A geometry's polygons in the `MultiPolygon` coordinate shape, whichever areal type it arrived as — `null` when the
|
|
67
|
+
* geometry is not areal (a Point or a LineString bounds no area).
|
|
68
|
+
*
|
|
69
|
+
* The one place a `Polygon` is lifted to `[rings]`; a caller that must refuse a non-areal geometry does so on the
|
|
70
|
+
* `null`, with its own message.
|
|
66
71
|
*/
|
|
72
|
+
export function arealPolygons(geometry) {
|
|
73
|
+
if (!geometry)
|
|
74
|
+
return null;
|
|
75
|
+
if (geometry.type === "Polygon")
|
|
76
|
+
return [geometry.coordinates];
|
|
77
|
+
if (geometry.type === "MultiPolygon")
|
|
78
|
+
return geometry.coordinates;
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
67
81
|
/**
|
|
68
|
-
*
|
|
82
|
+
* The polygons of a geometry that MUST be areal — {@linkcode arealPolygons} with the refusal every polygon ingest was
|
|
83
|
+
* writing for itself.
|
|
69
84
|
*
|
|
70
|
-
*
|
|
85
|
+
* @param subject Names the feature in the refusal, e.g. `feature 41209`.
|
|
86
|
+
* @param context Names the calling ingest, so a build log says which layer stopped.
|
|
87
|
+
* @throws {Error} When the geometry is neither a `Polygon` nor a `MultiPolygon`.
|
|
71
88
|
*/
|
|
72
|
-
export function
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return `poly:'${filter}'`;
|
|
89
|
+
export function requireArealPolygons(geometry, subject, context) {
|
|
90
|
+
const polygons = arealPolygons(geometry);
|
|
91
|
+
if (polygons)
|
|
92
|
+
return polygons;
|
|
93
|
+
throw new Error(`${context}: ${subject} is a ${geometry.type}, expected Polygon or MultiPolygon`);
|
|
78
94
|
}
|
|
79
95
|
/**
|
|
80
|
-
*
|
|
96
|
+
* Does an areal GeoJSON geometry contain the point?
|
|
97
|
+
*
|
|
98
|
+
* The three-valued return is the point of the function. `null` means the geometry is NOT AREAL — a Point or a
|
|
99
|
+
* LineString cannot contain anything — and a caller must read that as "no polygon on record", the same as a missing
|
|
100
|
+
* geometry, never as a rejection. Collapsing it to `false` is how a place with a point-only record gets excluded from a
|
|
101
|
+
* containment pass instead of falling through to the approximate path.
|
|
81
102
|
*
|
|
82
|
-
*
|
|
103
|
+
* `scripts/eval/pip-containment.py` grades the same containment truth against its own ray cast and has to be matched BY
|
|
104
|
+
* HAND if this one changes — it is the one copy no import can reach.
|
|
83
105
|
*/
|
|
84
|
-
export
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
Website: "website",
|
|
91
|
-
Email: "email",
|
|
92
|
-
Phone: "phone",
|
|
93
|
-
Shop: "shop",
|
|
94
|
-
Brand: "brand",
|
|
95
|
-
Cuisine: "cuisine",
|
|
96
|
-
Name: "name",
|
|
97
|
-
Healthcare: "healthcare",
|
|
98
|
-
Office: "office",
|
|
99
|
-
Amenity: "amenity",
|
|
100
|
-
};
|
|
106
|
+
export function geometryContains(geometry, lon, lat) {
|
|
107
|
+
const polygons = arealPolygons(geometry);
|
|
108
|
+
if (!polygons)
|
|
109
|
+
return null;
|
|
110
|
+
return polygons.some((rings) => pointInPolygon(lon, lat, rings));
|
|
111
|
+
}
|
|
101
112
|
/**
|
|
102
|
-
*
|
|
103
|
-
*
|
|
113
|
+
* An axis-aligned rectangle as a closed ring, in GeoJSON `[lon, lat]` order and counter-clockwise — the exterior
|
|
114
|
+
* winding.
|
|
115
|
+
*
|
|
116
|
+
* SHARED BECAUSE THE WINDING IS A CONVENTION AND A SECOND COPY IS A SECOND PLACE FOR IT TO DRIFT. Three layer builders
|
|
117
|
+
* hand-build rectangles for their fixture rungs, and each pairs this with {@link reversedRing} to make a hole. A copy
|
|
118
|
+
* whose hole is wound the same way as its exterior produces a fixture that passes every structural check and tests
|
|
119
|
+
* nothing about hole handling — which is the exact failure the area cross-check exists to catch in production data.
|
|
104
120
|
*/
|
|
105
|
-
export
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
]
|
|
121
|
+
export function rectangleRing(minLon, minLat, maxLon, maxLat) {
|
|
122
|
+
return [
|
|
123
|
+
[minLon, minLat],
|
|
124
|
+
[maxLon, minLat],
|
|
125
|
+
[maxLon, maxLat],
|
|
126
|
+
[minLon, maxLat],
|
|
127
|
+
[minLon, minLat],
|
|
128
|
+
];
|
|
129
|
+
}
|
|
112
130
|
/**
|
|
113
|
-
*
|
|
131
|
+
* The same rectangle wound the other way — a hole, under the GeoJSON convention.
|
|
114
132
|
*/
|
|
115
|
-
export function
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
export function fetchOSMElementViaOverpassAPI(input) {
|
|
125
|
-
const filter = polygonToOSMFilter(input);
|
|
126
|
-
const url = new URL("http://overpass-api.de/api/interpreter");
|
|
127
|
-
url.searchParams.set("data", `[out:json];(node['addr:housenumber'](${filter}););out body;>;out skel qt;`);
|
|
128
|
-
return fetch(url)
|
|
129
|
-
.then((response) => {
|
|
130
|
-
if (!response.ok)
|
|
131
|
-
throw ResourceError.from(response.status, response.statusText, "osm", "overpass-api", "fetch");
|
|
132
|
-
return response;
|
|
133
|
-
})
|
|
134
|
-
.then((response) => response.json())
|
|
135
|
-
.then((body) => body.elements)
|
|
136
|
-
.catch((error) => {
|
|
137
|
-
throw ResourceError.wrap(error, "osm", "overpass-api", "fetch");
|
|
138
|
-
});
|
|
133
|
+
export function reversedRing(minLon, minLat, maxLon, maxLat) {
|
|
134
|
+
return [
|
|
135
|
+
[minLon, minLat],
|
|
136
|
+
[minLon, maxLat],
|
|
137
|
+
[maxLon, maxLat],
|
|
138
|
+
[maxLon, minLat],
|
|
139
|
+
[minLon, minLat],
|
|
140
|
+
];
|
|
139
141
|
}
|
|
142
|
+
//#endregion
|
|
140
143
|
//# sourceMappingURL=polygon.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"polygon.js","sourceRoot":"","sources":["../../geometries/polygon.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"polygon.js","sourceRoot":"","sources":["../../lib/geometries/polygon.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAsGH;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAsC,KAAc;IACnF,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,KAAK,CAAA;IAE7D,OAAO,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,IAAI,aAAa,IAAI,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;AACjH,CAAC;AAED;;GAEG;AACH,kGAAkG;AAClG,qHAAqH;AACrH,MAAM,UAAU,kBAAkB,CAAC,KAAkC;IACpE,OAAO,KAAK,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC,CAAA;AACtC,CAAC;AAwBD;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,GAAW,EAAE,GAAW,EAAE,IAAqB;IAC1E,IAAI,MAAM,GAAG,KAAK,CAAA;IAClB,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAA;IAErB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QAC3C,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,CAAE,CAAC,CAAC,CAAE,CAAA;QACvB,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,CAAE,CAAC,CAAC,CAAE,CAAA;QACvB,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,CAAE,CAAC,CAAC,CAAE,CAAA;QACvB,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,CAAE,CAAC,CAAC,CAAE,CAAA;QAEvB,IAA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ister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* The ring blob — how a polygon layer stores one authority feature's UNSIMPLIFIED coordinates, and the
|
|
7
|
+
* point test that reads it without materializing them.
|
|
8
|
+
*
|
|
9
|
+
* THE GEOMETRY IS THE TRUTH TABLE. An H3 index above it answers a cell that lies wholly inside one
|
|
10
|
+
* feature; a cell a boundary crosses falls through to a ray cast against the few features the index
|
|
11
|
+
* already named. A rooftop answer at a boundary — which is where the answer usually matters most — has
|
|
12
|
+
* no other source, so the rings are stored at the resolution the authority published them and never
|
|
13
|
+
* simplified.
|
|
14
|
+
*
|
|
15
|
+
* THE LAYOUT PUTS THE COORDINATES ON AN 8-BYTE BOUNDARY, so the reader takes a `Float64Array` view over
|
|
16
|
+
* them instead of a `DataView.getFloat64` per ordinate. Header is `u32 version`, `u32 ringCount`, then
|
|
17
|
+
* one `(u32 pointCount, u32 polygonIndex)` pair per ring — `8 + 8 × ringCount` bytes, a multiple of
|
|
18
|
+
* eight by construction. Coordinates follow as `[lon, lat]` pairs, ring by ring.
|
|
19
|
+
*
|
|
20
|
+
* `polygonIndex` IS required AND CANNOT BE INFERRED. A source feature is a MultiPolygon, so its
|
|
21
|
+
* rings belong to several polygons and "the first ring is the exterior" is true only per polygon. The
|
|
22
|
+
* point test is orientation-free and nesting-free (even-odd across a polygon's own rings, the rule
|
|
23
|
+
* {@link pointInPolygon} uses), but it still has to know which rings share a polygon: an island sitting
|
|
24
|
+
* inside another polygon's hole is inside the layer and would cancel to "outside" if every ring were
|
|
25
|
+
* pooled into one list.
|
|
26
|
+
*
|
|
27
|
+
* SHARED BY EVERY POLYGON LAYER RATHER THAN COPIED INTO EACH. `@mailwoman/flood` and `@mailwoman/soil`
|
|
28
|
+
* both store an authority's rings this way, and a second copy of the alignment arithmetic or of the
|
|
29
|
+
* signed-area reading would be a second thing to get right — both failure modes are silent, since a
|
|
30
|
+
* mis-read blob answers a containment question wrongly and a hole-blind area reading answers "inside"
|
|
31
|
+
* for every point in a hole.
|
|
32
|
+
*/
|
|
33
|
+
import type { MultiPolygonRings } from "#geometries/polygon";
|
|
34
|
+
/**
|
|
35
|
+
* Format version stamped into every blob. A reader that meets a different number throws rather than reinterpreting
|
|
36
|
+
* bytes it does not know the shape of.
|
|
37
|
+
*/
|
|
38
|
+
export declare const RING_BLOB_VERSION = 1;
|
|
39
|
+
/**
|
|
40
|
+
* One decoded feature: `[exteriorRing, ...holes]` per polygon, each ring a flat `[lon, lat, lon, lat, …]` run.
|
|
41
|
+
*/
|
|
42
|
+
export interface DecodedRings {
|
|
43
|
+
/**
|
|
44
|
+
* `polygons[p][r]` is a flat coordinate run for ring `r` of polygon `p`.
|
|
45
|
+
*/
|
|
46
|
+
polygons: number[][][];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Pack a GeoJSON `MultiPolygon`/`Polygon` coordinate tree into the stored blob.
|
|
50
|
+
*
|
|
51
|
+
* @throws {RangeError} When the geometry carries no ring, or a ring carries fewer than four positions (a linear ring is
|
|
52
|
+
* closed, so three is the minimum distinct-vertex count plus the repeat).
|
|
53
|
+
*/
|
|
54
|
+
export declare function encodeRings(polygons: MultiPolygonRings): Uint8Array;
|
|
55
|
+
/**
|
|
56
|
+
* Is the point inside the stored geometry?
|
|
57
|
+
*
|
|
58
|
+
* Even-odd within each polygon's own ring list, inside-any-polygon across them — the orientation-free rule
|
|
59
|
+
* {@linkcode pointInPolygon} states, applied without allocating the ring arrays. Reading a hole as an exterior ring is
|
|
60
|
+
* what this rule survives: a point inside a hole crosses two rings and comes out even, whichever way either ring
|
|
61
|
+
* winds.
|
|
62
|
+
*/
|
|
63
|
+
export declare function pointInEncodedRings(blob: Uint8Array, lon: number, lat: number): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Unpack the blob back into per-polygon flat coordinate runs — for tests, for a debug render, and for the round-trip
|
|
66
|
+
* check a build's fixtures assert.
|
|
67
|
+
*/
|
|
68
|
+
export declare function decodeRings(blob: Uint8Array): DecodedRings;
|
|
69
|
+
/**
|
|
70
|
+
* Signed spherical area of one linear ring, in square metres. **CLOCKWISE is positive**, counter-clockwise negative.
|
|
71
|
+
*
|
|
72
|
+
* The sign is the whole point: an orientation-respecting sum over a polygon's rings subtracts its holes, while a sum of
|
|
73
|
+
* absolute values adds them. Comparing the two against the source's own area figure is what tells a builder whether it
|
|
74
|
+
* has read the holes at all — the failure mode is silent, because a hole read as an exterior ring produces a perfectly
|
|
75
|
+
* well-formed polygon that simply covers more ground than the authority mapped.
|
|
76
|
+
*
|
|
77
|
+
* WHICH WINDING IS POSITIVE IS A CONTRACT, NOT A DETAIL, because a builder whose source encodes hole roles by
|
|
78
|
+
* ORIENTATION reads roles off this sign. It is the opposite of the standard planar shoelace: this sum runs `(lonᵢ −
|
|
79
|
+
* lonⱼ)` against the shoelace's `(xⱼ − xᵢ)`, so a ring `@mailwoman/spatial`'s own {@link rectangleRing} builds
|
|
80
|
+
* counter-clockwise answers NEGATIVE here. `@mailwoman/zoning` is the caller that depends on it, and
|
|
81
|
+
* `packages/zoning/test/unit/ring-roles.test.ts` pins the sign directly.
|
|
82
|
+
*/
|
|
83
|
+
export declare function ringSignedAreaM2(ring: ReadonlyArray<readonly number[]>): number;
|
|
84
|
+
/**
|
|
85
|
+
* Both readings of one feature's area, in square metres: `nested` respects ring orientation (holes subtract) and
|
|
86
|
+
* `allExterior` does not (holes add).
|
|
87
|
+
*
|
|
88
|
+
* A source whose holes are correctly nested makes `nested` match the authority's own figure and `allExterior` exceed
|
|
89
|
+
* it. The gap between them is the area a hole-blind reader would answer "inside" for.
|
|
90
|
+
*/
|
|
91
|
+
export declare function ringAreaReadings(polygons: MultiPolygonRings): {
|
|
92
|
+
nested: number;
|
|
93
|
+
allExterior: number;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* A rectangle in CRS84 degrees.
|
|
97
|
+
*/
|
|
98
|
+
export interface DegreeExtent {
|
|
99
|
+
minLon: number;
|
|
100
|
+
minLat: number;
|
|
101
|
+
maxLon: number;
|
|
102
|
+
maxLat: number;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Refuse a feature whose reprojected vertices fall outside the publisher's own declared extent.
|
|
106
|
+
*
|
|
107
|
+
* THE CHECK A PROJECTION CHECK CANNOT MAKE. A swapped coordinate order survives an authority-code comparison — both
|
|
108
|
+
* axes are still numbers in a plausible range — and a source read in its own metres as if they were degrees produces
|
|
109
|
+
* perfectly well-formed coordinates in the wrong ocean. Both show up here on the first feature, before a whole layer is
|
|
110
|
+
* written to the wrong side of the planet.
|
|
111
|
+
*
|
|
112
|
+
* SHARED BY EVERY POLYGON INGEST, because it is rectangle arithmetic over the ring types and knows nothing about any
|
|
113
|
+
* product. `marginDegrees` is the caller's, because a declared extent is itself a rounded published value and how
|
|
114
|
+
* tightly a source hugs its own is a fact about that source.
|
|
115
|
+
*
|
|
116
|
+
* @param context Names the calling ingest in the refusal, so a build log says which layer stopped.
|
|
117
|
+
* @throws {RangeError} On the first vertex outside the extent.
|
|
118
|
+
*/
|
|
119
|
+
export declare function assertRingsInsideExtent(polygons: MultiPolygonRings, label: string, extent: DegreeExtent, marginDegrees: number, context?: string): void;
|
|
120
|
+
/**
|
|
121
|
+
* One stored polygon's bounding box and geometry, as every polygon layer's truth table stores them.
|
|
122
|
+
*/
|
|
123
|
+
export interface EncodedArea {
|
|
124
|
+
min_lat: number;
|
|
125
|
+
min_lon: number;
|
|
126
|
+
max_lat: number;
|
|
127
|
+
max_lon: number;
|
|
128
|
+
rings: Uint8Array;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* A point INSIDE one stored polygon, for a verification sampler.
|
|
132
|
+
*
|
|
133
|
+
* The bounding-box centre is tried first; where it is not inside — a crescent, a band hugging a river, a polygon with a
|
|
134
|
+
* hole through its middle — a small deterministic grid over the box is scanned. A polygon no grid point lands inside is
|
|
135
|
+
* refused (`undefined`) rather than approximated, because a sample point that is not actually inside the polygon turns
|
|
136
|
+
* an agreement check into a check on the sampler.
|
|
137
|
+
*
|
|
138
|
+
* SHARED BY EVERY POLYGON LAYER'S VERIFY, because it is bounding-box arithmetic over the ring blob and knows nothing
|
|
139
|
+
* about any product. `gridSteps` is the one thing that differs between them: a layer whose polygons are narrow strips
|
|
140
|
+
* needs a finer grid than one whose polygons are compact, and the value is part of a layer's sampling receipt — two
|
|
141
|
+
* runs of the same layer must draw the same points, so it is a caller's choice rather than a shared default nobody
|
|
142
|
+
* owns.
|
|
143
|
+
*
|
|
144
|
+
* @param gridSteps Grid divisions per axis. Only `steps − 1` interior lines are tested, so 7 gives a 6 × 6 grid.
|
|
145
|
+
*/
|
|
146
|
+
export declare function interiorPointOfEncodedRings(area: EncodedArea, gridSteps?: number): {
|
|
147
|
+
latitude: number;
|
|
148
|
+
longitude: number;
|
|
149
|
+
} | undefined;
|
|
150
|
+
/**
|
|
151
|
+
* Whether a stored polygon's precomputed bounding box contains the point — the ray cast's prefilter, so the blob is
|
|
152
|
+
* only pulled off disk for a polygon that could contain the point.
|
|
153
|
+
*/
|
|
154
|
+
export declare function bboxContains(bounds: Pick<EncodedArea, "min_lat" | "min_lon" | "max_lat" | "max_lon">, longitude: number, latitude: number): boolean;
|
|
155
|
+
/**
|
|
156
|
+
* A reproducible sample of interior points drawn by a deterministic STRIDE over a key list — the shape every polygon
|
|
157
|
+
* layer's verification sampler shares.
|
|
158
|
+
*
|
|
159
|
+
* The keys are chosen before any geometry is read: selecting them alone is an index-only walk over the primary key, and
|
|
160
|
+
* the rows they name are then fetched by key. The draw is deterministic rather than random, so a re-run compares the
|
|
161
|
+
* same points and a disagreement can be looked at rather than re-rolled.
|
|
162
|
+
*
|
|
163
|
+
* @param options.gridSteps The interior-point search depth, per {@link interiorPointOfEncodedRings} — part of a layer's
|
|
164
|
+
* sampling receipt, so it is a caller's choice rather than a shared default nobody owns.
|
|
165
|
+
*/
|
|
166
|
+
export declare function strideSampleInteriorPoints<Area extends EncodedArea, Point>(keys: readonly string[], count: number, options: {
|
|
167
|
+
fetch: (key: string) => Area | undefined;
|
|
168
|
+
gridSteps: number;
|
|
169
|
+
toPoint: (area: Area, interior: {
|
|
170
|
+
latitude: number;
|
|
171
|
+
longitude: number;
|
|
172
|
+
}) => Point;
|
|
173
|
+
}): Point[];
|
|
174
|
+
/**
|
|
175
|
+
* The bounding rectangle of one feature's rings, in degrees — a ray cast's prefilter, precomputed.
|
|
176
|
+
*/
|
|
177
|
+
export declare function ringsBoundingBox(polygons: MultiPolygonRings): {
|
|
178
|
+
minLat: number;
|
|
179
|
+
minLon: number;
|
|
180
|
+
maxLat: number;
|
|
181
|
+
maxLon: number;
|
|
182
|
+
};
|
|
183
|
+
//# sourceMappingURL=ring-blob.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ring-blob.d.ts","sourceRoot":"","sources":["../../lib/geometries/ring-blob.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAE5D;;;GAGG;AACH,eAAO,MAAM,iBAAiB,IAAI,CAAA;AAkBlC;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B;;OAEG;IACH,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,CAAA;CACtB;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,iBAAiB,GAAG,UAAU,CA8CnE;AAuDD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CA2BvF;AAuBD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,UAAU,GAAG,YAAY,CAe1D;AAOD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,aAAa,C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