@mailwoman/spatial 9.2.0 → 9.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.
- package/{bbox.ts → lib/bbox.ts} +4 -4
- package/{coordinate-bounds.ts → lib/coordinate-bounds.ts} +11 -0
- package/{coordinate-formats.ts → lib/coordinate-formats.ts} +3 -1
- package/lib/distance.ts +204 -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 +4 -4
- package/{geometries → lib/geometries}/point.ts +14 -13
- package/{geometries → lib/geometries}/polygon.ts +82 -158
- 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/{open-location-code.ts → lib/open-location-code.ts} +1 -1
- package/{osgb36.ts → lib/osgb36.ts} +2 -2
- package/{polyline.ts → lib/polyline.ts} +5 -5
- package/{position.ts → lib/position.ts} +2 -2
- 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/out/bbox.d.ts +2 -2
- package/out/bbox.d.ts.map +1 -1
- package/out/bbox.js +3 -3
- package/out/bbox.js.map +1 -1
- package/out/coordinate-bounds.d.ts +9 -0
- package/out/coordinate-bounds.d.ts.map +1 -1
- package/out/coordinate-bounds.js +9 -0
- package/out/coordinate-bounds.js.map +1 -1
- package/out/coordinate-formats.d.ts.map +1 -1
- package/out/coordinate-formats.js +2 -1
- package/out/coordinate-formats.js.map +1 -1
- package/out/distance.d.ts +64 -1
- package/out/distance.d.ts.map +1 -1
- package/out/distance.js +85 -1
- package/out/distance.js.map +1 -1
- 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 +4 -4
- 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 +14 -13
- package/out/geometries/point.d.ts.map +1 -1
- package/out/geometries/point.js +11 -10
- package/out/geometries/point.js.map +1 -1
- package/out/geometries/polygon.d.ts +51 -100
- package/out/geometries/polygon.d.ts.map +1 -1
- package/out/geometries/polygon.js +60 -90
- 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 -15
- package/out/index.d.ts.map +1 -1
- package/out/index.js +15 -15
- 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.map +1 -1
- package/out/open-location-code.js +1 -1
- package/out/open-location-code.js.map +1 -1
- 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 +4 -4
- package/out/polyline.d.ts.map +1 -1
- package/out/polyline.js +5 -5
- package/out/polyline.js.map +1 -1
- package/out/position.d.ts +1 -1
- package/out/position.d.ts.map +1 -1
- package/out/position.js +2 -2
- 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/well-known-text.d.ts.map +1 -0
- package/out/well-known-text.js.map +1 -0
- package/package.json +94 -25
- package/distance.ts +0 -84
- package/geometries/index.ts +0 -12
- package/index.ts +0 -21
- 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/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/{sdk → lib}/well-known-text.ts +0 -0
- /package/out/{sdk/well-known-text.d.ts → well-known-text.d.ts} +0 -0
- /package/out/{sdk/well-known-text.js → well-known-text.js} +0 -0
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*/
|
|
6
|
-
import type {
|
|
7
|
-
import type { LineStringPath } from "
|
|
6
|
+
import type { GeometryLiteral } from "#geometries/collection";
|
|
7
|
+
import type { LineStringPath } from "#geometries/line-string";
|
|
8
|
+
import type { GeoObjectLiteral } from "#objects";
|
|
8
9
|
/**
|
|
9
10
|
* An array of positions forming a closed shape, such as a country or a lake.
|
|
10
11
|
*
|
|
@@ -83,7 +84,7 @@ export type PolygonPath = SolidPolygonPath | NestedPolygonPath;
|
|
|
83
84
|
/**
|
|
84
85
|
* An array of positions forming a closed shape, such as a country or a lake.
|
|
85
86
|
*/
|
|
86
|
-
export interface PolygonLiteral<P extends PolygonPath =
|
|
87
|
+
export interface PolygonLiteral<P extends PolygonPath = PolygonPath> extends GeoObjectLiteral {
|
|
87
88
|
/**
|
|
88
89
|
* Declares the type of GeoJSON object as a `Polygon` geometry.
|
|
89
90
|
*/
|
|
@@ -104,7 +105,7 @@ export declare function isPolygonLiteral<P extends PolygonPath = PolygonPath>(in
|
|
|
104
105
|
/**
|
|
105
106
|
* Predicate for checking if a polygon geometry is a solid, i.e. it has no holes.
|
|
106
107
|
*/
|
|
107
|
-
export declare function isSolidPolygonPath(input: PolygonLiteral): boolean;
|
|
108
|
+
export declare function isSolidPolygonPath(input: PolygonLiteral<PolygonPath>): boolean;
|
|
108
109
|
/**
|
|
109
110
|
* A linear ring as the containment predicates read it: positions of `[lon, lat, …]`.
|
|
110
111
|
*
|
|
@@ -114,6 +115,16 @@ export declare function isSolidPolygonPath(input: PolygonLiteral): boolean;
|
|
|
114
115
|
* call site and buy nothing the predicate uses.
|
|
115
116
|
*/
|
|
116
117
|
export type ContainmentRing = readonly (readonly number[])[];
|
|
118
|
+
/**
|
|
119
|
+
* One polygon's rings: `[exterior, ...holes]` — a `Polygon`'s `coordinates`, read loosely (see
|
|
120
|
+
* {@linkcode ContainmentRing}).
|
|
121
|
+
*/
|
|
122
|
+
export type PolygonRings = readonly ContainmentRing[];
|
|
123
|
+
/**
|
|
124
|
+
* A feature's polygons — `MultiPolygon` coordinates, with a bare `Polygon` lifted into the same shape by
|
|
125
|
+
* {@linkcode arealPolygons}.
|
|
126
|
+
*/
|
|
127
|
+
export type MultiPolygonRings = readonly PolygonRings[];
|
|
117
128
|
/**
|
|
118
129
|
* Ray-cast a point against ONE linear ring — the even-odd crossing count. Shoot a ray along +lon and toggle on every
|
|
119
130
|
* edge crossing.
|
|
@@ -129,7 +140,7 @@ export declare function pointInRing(lon: number, lat: number, ring: ContainmentR
|
|
|
129
140
|
* without depending on ring winding order. GeoJSON nominally specifies orientation, but the gazetteer sources do not
|
|
130
141
|
* reliably honour it, so the orientation-free rule is the one that survives real data.
|
|
131
142
|
*/
|
|
132
|
-
export declare function pointInPolygon(lon: number, lat: number, rings:
|
|
143
|
+
export declare function pointInPolygon(lon: number, lat: number, rings: PolygonRings): boolean;
|
|
133
144
|
/**
|
|
134
145
|
* Inside ANY polygon of a multi-polygon.
|
|
135
146
|
*/
|
|
@@ -137,7 +148,7 @@ export declare function pointInMultiPolygon(lon: number, lat: number, polygons:
|
|
|
137
148
|
/**
|
|
138
149
|
* A collection of polygons, such as a country with islands or a lake with islands.
|
|
139
150
|
*/
|
|
140
|
-
export interface MultiPolygonLiteral<P extends PolygonPath =
|
|
151
|
+
export interface MultiPolygonLiteral<P extends PolygonPath = PolygonPath> extends GeoObjectLiteral {
|
|
141
152
|
type: "MultiPolygon";
|
|
142
153
|
/**
|
|
143
154
|
* One ring array per polygon — `coordinates[polygon][ring][position]`, matching a `Polygon`'s `coordinates` lifted by
|
|
@@ -148,115 +159,55 @@ export interface MultiPolygonLiteral<P extends PolygonPath = SolidPolygonPath> e
|
|
|
148
159
|
coordinates: P[];
|
|
149
160
|
}
|
|
150
161
|
/**
|
|
151
|
-
*
|
|
162
|
+
* A geometry as it arrives from `JSON.parse`, or a typed literal. Nothing has checked the arity of a position and
|
|
163
|
+
* `type` is whatever the source wrote, so a reader narrows on `type` and casts `coordinates` — {@linkcode arealPolygons}
|
|
164
|
+
* is the one place that happens for the areal types.
|
|
152
165
|
*/
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
* This is useful when working with the Overpass API.
|
|
157
|
-
*/
|
|
158
|
-
export declare function polygonToOSMFilter(input: PolygonLiteral): string;
|
|
159
|
-
/**
|
|
160
|
-
* Tags returned by the Overpass API for a node.
|
|
161
|
-
*
|
|
162
|
-
* @category OSM
|
|
163
|
-
*/
|
|
164
|
-
export declare const OSMNodeTag: {
|
|
165
|
-
readonly HouseNumber: "addr:housenumber";
|
|
166
|
-
readonly PostCode: "addr:postcode";
|
|
167
|
-
readonly Street: "addr:street";
|
|
168
|
-
readonly State: "addr:state";
|
|
169
|
-
readonly City: "addr:city";
|
|
170
|
-
readonly Website: "website";
|
|
171
|
-
readonly Email: "email";
|
|
172
|
-
readonly Phone: "phone";
|
|
173
|
-
readonly Shop: "shop";
|
|
174
|
-
readonly Brand: "brand";
|
|
175
|
-
readonly Cuisine: "cuisine";
|
|
176
|
-
readonly Name: "name";
|
|
177
|
-
readonly Healthcare: "healthcare";
|
|
178
|
-
readonly Office: "office";
|
|
179
|
-
readonly Amenity: "amenity";
|
|
166
|
+
export type ParsedGeometry = GeometryLiteral | {
|
|
167
|
+
type: string;
|
|
168
|
+
coordinates?: unknown;
|
|
180
169
|
};
|
|
181
|
-
export type OSMNodeTag = (typeof OSMNodeTag)[keyof typeof OSMNodeTag];
|
|
182
|
-
/**
|
|
183
|
-
* OSM node tags that disqualify a node from being treated as residential — a node carrying one of these is
|
|
184
|
-
* infrastructure or commercial, whatever else it claims.
|
|
185
|
-
*/
|
|
186
|
-
export declare const ForbiddenResidentialOSMNodeTags: ReadonlySet<OSMNodeTag>;
|
|
187
|
-
export type OSMNodeTagRecord = Record<OSMNodeTag, string | undefined>;
|
|
188
|
-
export interface OSMOverpassElement {
|
|
189
|
-
type: "node";
|
|
190
|
-
id: number;
|
|
191
|
-
lat: number;
|
|
192
|
-
lon: number;
|
|
193
|
-
tags: OSMNodeTagRecord;
|
|
194
|
-
}
|
|
195
|
-
export interface OSMOverpassResponseBody {
|
|
196
|
-
version: string;
|
|
197
|
-
generator: string;
|
|
198
|
-
osm3s: {
|
|
199
|
-
timestamp_osm_base: string;
|
|
200
|
-
copyright: string;
|
|
201
|
-
};
|
|
202
|
-
elements: OSMOverpassElement[];
|
|
203
|
-
}
|
|
204
170
|
/**
|
|
205
|
-
*
|
|
206
|
-
|
|
207
|
-
export declare function isResidentialElement(element: OSMOverpassElement): boolean;
|
|
208
|
-
export declare function fetchOSMElementViaOverpassAPI(input: PolygonLiteral): Promise<OSMOverpassElement[]>;
|
|
209
|
-
/**
|
|
210
|
-
* A GeoJSON position — `[lon, lat]`, possibly carrying extra dimensions this module ignores.
|
|
171
|
+
* A geometry's polygons in the `MultiPolygon` coordinate shape, whichever areal type it arrived as — `null` when the
|
|
172
|
+
* geometry is not areal (a Point or a LineString bounds no area).
|
|
211
173
|
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
174
|
+
* The one place a `Polygon` is lifted to `[rings]`; a caller that must refuse a non-areal geometry does so on the
|
|
175
|
+
* `null`, with its own message.
|
|
214
176
|
*/
|
|
215
|
-
export
|
|
177
|
+
export declare function arealPolygons(geometry: ParsedGeometry | null | undefined): MultiPolygonRings | null;
|
|
216
178
|
/**
|
|
217
|
-
*
|
|
179
|
+
* The polygons of a geometry that MUST be areal — {@linkcode arealPolygons} with the refusal every polygon ingest was
|
|
180
|
+
* writing for itself.
|
|
218
181
|
*
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
* a gazetteer, and `PolygonLiteral` where the solid/nested distinction is one you are asserting rather than
|
|
223
|
-
* discovering.
|
|
182
|
+
* @param subject Names the feature in the refusal, e.g. `feature 41209`.
|
|
183
|
+
* @param context Names the calling ingest, so a build log says which layer stopped.
|
|
184
|
+
* @throws {Error} When the geometry is neither a `Polygon` nor a `MultiPolygon`.
|
|
224
185
|
*/
|
|
225
|
-
export
|
|
226
|
-
type: "Polygon";
|
|
227
|
-
coordinates: GeojsonPosition[][];
|
|
228
|
-
}
|
|
186
|
+
export declare function requireArealPolygons(geometry: ParsedGeometry, subject: string, context: string): MultiPolygonRings;
|
|
229
187
|
/**
|
|
230
|
-
*
|
|
231
|
-
*/
|
|
232
|
-
export interface GeojsonMultiPolygon {
|
|
233
|
-
type: "MultiPolygon";
|
|
234
|
-
coordinates: GeojsonPosition[][][];
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* Either areal geometry, or an open fallback for the types containment cannot answer (Point, LineString, …).
|
|
238
|
-
*/
|
|
239
|
-
export type GeojsonGeometry = GeojsonPolygon | GeojsonMultiPolygon | {
|
|
240
|
-
type: string;
|
|
241
|
-
coordinates?: unknown;
|
|
242
|
-
};
|
|
243
|
-
/**
|
|
244
|
-
* Even-odd containment over a polygon's ring list (`[outer, hole1, …]`).
|
|
188
|
+
* Does an areal GeoJSON geometry contain the point?
|
|
245
189
|
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
190
|
+
* The three-valued return is the point of the function. `null` means the geometry is NOT AREAL — a Point or a
|
|
191
|
+
* LineString cannot contain anything — and a caller must read that as "no polygon on record", the same as a missing
|
|
192
|
+
* geometry, never as a rejection. Collapsing it to `false` is how a place with a point-only record gets excluded from a
|
|
193
|
+
* containment pass instead of falling through to the approximate path.
|
|
248
194
|
*
|
|
249
195
|
* `scripts/eval/pip-containment.py` grades the same containment truth against its own ray cast and has to be matched BY
|
|
250
196
|
* HAND if this one changes — it is the one copy no import can reach.
|
|
251
197
|
*/
|
|
252
|
-
export declare function
|
|
198
|
+
export declare function geometryContains(geometry: ParsedGeometry | null | undefined, lon: number, lat: number): boolean | null;
|
|
253
199
|
/**
|
|
254
|
-
*
|
|
200
|
+
* An axis-aligned rectangle as a closed ring, in GeoJSON `[lon, lat]` order and counter-clockwise — the exterior
|
|
201
|
+
* winding.
|
|
255
202
|
*
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
*
|
|
259
|
-
*
|
|
203
|
+
* SHARED BECAUSE THE WINDING IS A CONVENTION AND A SECOND COPY IS A SECOND PLACE FOR IT TO DRIFT. Three layer builders
|
|
204
|
+
* hand-build rectangles for their fixture rungs, and each pairs this with {@link reversedRing} to make a hole. A copy
|
|
205
|
+
* whose hole is wound the same way as its exterior produces a fixture that passes every structural check and tests
|
|
206
|
+
* nothing about hole handling — which is the exact failure the area cross-check exists to catch in production data.
|
|
207
|
+
*/
|
|
208
|
+
export declare function rectangleRing(minLon: number, minLat: number, maxLon: number, maxLat: number): number[][];
|
|
209
|
+
/**
|
|
210
|
+
* The same rectangle wound the other way — a hole, under the GeoJSON convention.
|
|
260
211
|
*/
|
|
261
|
-
export declare function
|
|
212
|
+
export declare function reversedRing(minLon: number, minLat: number, maxLon: number, maxLat: number): number[][];
|
|
262
213
|
//# sourceMappingURL=polygon.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"polygon.d.ts","sourceRoot":"","sources":["../../geometries/polygon.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"polygon.d.ts","sourceRoot":"","sources":["../../lib/geometries/polygon.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAEhD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC9B;;;OAGG;IACH,YAAY,EAAE,cAAc;CAC5B,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC/B;;;OAGG;IACH,YAAY,EAAE,cAAc;IAC5B;;OAEG;IACH,GAAG,aAAa,EAAE,cAAc,EAAE;CAClC,CAAA;AAED;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GAAG,gBAAgB,GAAG,iBAAiB,CAAA;AAE9D;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,CAAE,SAAQ,gBAAgB;IAC5F;;OAEG;IACH,IAAI,EAAE,SAAS,CAAA;IACf;;;;;;OAMG;IACH,WAAW,EAAE,CAAC,CAAA;CACd;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAAC,CAAC,CAAC,CAIhH;AAED;;GAEG;AAGH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,cAAc,CAAC,WAAW,CAAC,GAAG,OAAO,CAE9E;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,eAAe,GAAG,SAA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EAAE,cAAc,GAAG,IAAI,GAAG,SAAS,EAC3C,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,GACT,OAAO,GAAG,IAAI,CAMhB;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,CAQxG;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,CAQvG"}
|
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*/
|
|
6
|
-
import { APIClient, pluckResponseData } from "@mailwoman/core/api";
|
|
7
|
-
import { ResourceError } from "@mailwoman/core/errors";
|
|
8
6
|
/**
|
|
9
7
|
* Predicate for checking if a GeoJSON object is a `Polygon` geometry.
|
|
10
8
|
*/
|
|
@@ -16,6 +14,8 @@ export function isPolygonLiteral(input) {
|
|
|
16
14
|
/**
|
|
17
15
|
* Predicate for checking if a polygon geometry is a solid, i.e. it has no holes.
|
|
18
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.
|
|
19
19
|
export function isSolidPolygonPath(input) {
|
|
20
20
|
return input.coordinates.length === 1;
|
|
21
21
|
}
|
|
@@ -63,92 +63,34 @@ export function pointInMultiPolygon(lon, lat, polygons) {
|
|
|
63
63
|
return polygons.some((rings) => pointInPolygon(lon, lat, rings));
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
|
-
*
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Given a polygon geometry, return an OSM filter string.
|
|
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).
|
|
70
68
|
*
|
|
71
|
-
*
|
|
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.
|
|
72
71
|
*/
|
|
73
|
-
export function
|
|
74
|
-
if (!
|
|
75
|
-
return
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
* Tags returned by the Overpass API for a node.
|
|
82
|
-
*
|
|
83
|
-
* @category OSM
|
|
84
|
-
*/
|
|
85
|
-
export const OSMNodeTag = {
|
|
86
|
-
HouseNumber: "addr:housenumber",
|
|
87
|
-
PostCode: "addr:postcode",
|
|
88
|
-
Street: "addr:street",
|
|
89
|
-
State: "addr:state",
|
|
90
|
-
City: "addr:city",
|
|
91
|
-
Website: "website",
|
|
92
|
-
Email: "email",
|
|
93
|
-
Phone: "phone",
|
|
94
|
-
Shop: "shop",
|
|
95
|
-
Brand: "brand",
|
|
96
|
-
Cuisine: "cuisine",
|
|
97
|
-
Name: "name",
|
|
98
|
-
Healthcare: "healthcare",
|
|
99
|
-
Office: "office",
|
|
100
|
-
Amenity: "amenity",
|
|
101
|
-
};
|
|
102
|
-
/**
|
|
103
|
-
* OSM node tags that disqualify a node from being treated as residential — a node carrying one of these is
|
|
104
|
-
* infrastructure or commercial, whatever else it claims.
|
|
105
|
-
*/
|
|
106
|
-
export const ForbiddenResidentialOSMNodeTags = new Set([
|
|
107
|
-
OSMNodeTag.Shop,
|
|
108
|
-
OSMNodeTag.Brand,
|
|
109
|
-
OSMNodeTag.Cuisine,
|
|
110
|
-
OSMNodeTag.Office,
|
|
111
|
-
OSMNodeTag.Healthcare,
|
|
112
|
-
]);
|
|
113
|
-
/**
|
|
114
|
-
* Given an OSM element, attempts to infer if the result is a residential address.
|
|
115
|
-
*/
|
|
116
|
-
export function isResidentialElement(element) {
|
|
117
|
-
for (const key in element.tags) {
|
|
118
|
-
if (ForbiddenResidentialOSMNodeTags.has(key))
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
121
|
-
if (element.tags[OSMNodeTag.Amenity] === "restaurant")
|
|
122
|
-
return false;
|
|
123
|
-
return true;
|
|
124
|
-
}
|
|
125
|
-
const overpassClient = new APIClient({ displayName: "overpass", retry: true });
|
|
126
|
-
export function fetchOSMElementViaOverpassAPI(input) {
|
|
127
|
-
const filter = polygonToOSMFilter(input);
|
|
128
|
-
const url = new URL("http://overpass-api.de/api/interpreter");
|
|
129
|
-
url.searchParams.set("data", `[out:json];(node['addr:housenumber'](${filter}););out body;>;out skel qt;`);
|
|
130
|
-
// Overpass is a free shared endpoint that answers a throttle with 429 + `Retry-After`. `retry: true` is what
|
|
131
|
-
// reads that header, which is the server stating its own limit rather than this file guessing one. `ResourceError`
|
|
132
|
-
// now arrives from the client instead of being assembled here.
|
|
133
|
-
return overpassClient
|
|
134
|
-
.fetch({ url: url.toString() })
|
|
135
|
-
.then(pluckResponseData)
|
|
136
|
-
.then((body) => body.elements)
|
|
137
|
-
.catch((error) => {
|
|
138
|
-
throw ResourceError.wrap(error, "osm", "overpass-api", "fetch");
|
|
139
|
-
});
|
|
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;
|
|
140
80
|
}
|
|
141
81
|
/**
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
* A named alias for {@linkcode pointInPolygon}: the "rings" spelling is what makes the ring-list argument obvious at a
|
|
145
|
-
* call site that has just pulled `coordinates` off a parsed geometry.
|
|
82
|
+
* The polygons of a geometry that MUST be areal — {@linkcode arealPolygons} with the refusal every polygon ingest was
|
|
83
|
+
* writing for itself.
|
|
146
84
|
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
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`.
|
|
149
88
|
*/
|
|
150
|
-
export function
|
|
151
|
-
|
|
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`);
|
|
152
94
|
}
|
|
153
95
|
/**
|
|
154
96
|
* Does an areal GeoJSON geometry contain the point?
|
|
@@ -157,17 +99,45 @@ export function pointInPolygonRings(lon, lat, rings) {
|
|
|
157
99
|
* LineString cannot contain anything — and a caller must read that as "no polygon on record", the same as a missing
|
|
158
100
|
* geometry, never as a rejection. Collapsing it to `false` is how a place with a point-only record gets excluded from a
|
|
159
101
|
* containment pass instead of falling through to the approximate path.
|
|
102
|
+
*
|
|
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.
|
|
160
105
|
*/
|
|
161
106
|
export function geometryContains(geometry, lon, lat) {
|
|
162
|
-
|
|
107
|
+
const polygons = arealPolygons(geometry);
|
|
108
|
+
if (!polygons)
|
|
163
109
|
return null;
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
110
|
+
return polygons.some((rings) => pointInPolygon(lon, lat, rings));
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
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.
|
|
120
|
+
*/
|
|
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
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* The same rectangle wound the other way — a hole, under the GeoJSON convention.
|
|
132
|
+
*/
|
|
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
|
+
];
|
|
171
141
|
}
|
|
172
142
|
//#endregion
|
|
173
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,CA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AA;IAExC,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAA;IAE1B,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,CAAA;AACjE,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAAC,MAAc,EAAE,MAAc,EAAE,MAAc,EAAE,MAAc;IAC3F,OAAO;QACN,CAAC,MAAM,EAAE,MAAM,CAAC;QAChB,CAAC,MAAM,EAAE,MAAM,CAAC;QAChB,CAAC,MAAM,EAAE,MAAM,CAAC;QAChB,CAAC,MAAM,EAAE,MAAM,CAAC;QAChB,CAAC,MAAM,EAAE,MAAM,CAAC;KAChB,CAAA;AACF,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,MAAc,EAAE,MAAc,EAAE,MAAc,EAAE,MAAc;IAC1F,OAAO;QACN,CAAC,MAAM,EAAE,MAAM,CAAC;QAChB,CAAC,MAAM,EAAE,MAAM,CAAC;QAChB,CAAC,MAAM,EAAE,MAAM,CAAC;QAChB,CAAC,MAAM,EAAE,MAAM,CAAC;QAChB,CAAC,MAAM,EAAE,MAAM,CAAC;KAChB,CAAA;AACF,CAAC;AAED,YAAY"}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister 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,CAAC,SAAS,MAAM,EAAE,CAAC,GAAG,MAAM,CAY/E;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,iBAAiB,GAAG;IAC9D,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;CACnB,CAoBA;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;CACd;AAED;;;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