@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
|
@@ -4,11 +4,9 @@
|
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
import type { GeoObjectLiteral } from "../objects.ts"
|
|
11
|
-
import type { LineStringPath } from "./line-string.ts"
|
|
7
|
+
import type { GeometryLiteral } from "#geometries/collection"
|
|
8
|
+
import type { LineStringPath } from "#geometries/line-string"
|
|
9
|
+
import type { GeoObjectLiteral } from "#objects"
|
|
12
10
|
|
|
13
11
|
/**
|
|
14
12
|
* An array of positions forming a closed shape, such as a country or a lake.
|
|
@@ -91,7 +89,7 @@ export type PolygonPath = SolidPolygonPath | NestedPolygonPath
|
|
|
91
89
|
/**
|
|
92
90
|
* An array of positions forming a closed shape, such as a country or a lake.
|
|
93
91
|
*/
|
|
94
|
-
export interface PolygonLiteral<P extends PolygonPath =
|
|
92
|
+
export interface PolygonLiteral<P extends PolygonPath = PolygonPath> extends GeoObjectLiteral {
|
|
95
93
|
/**
|
|
96
94
|
* Declares the type of GeoJSON object as a `Polygon` geometry.
|
|
97
95
|
*/
|
|
@@ -118,7 +116,9 @@ export function isPolygonLiteral<P extends PolygonPath = PolygonPath>(input: unk
|
|
|
118
116
|
/**
|
|
119
117
|
* Predicate for checking if a polygon geometry is a solid, i.e. it has no holes.
|
|
120
118
|
*/
|
|
121
|
-
|
|
119
|
+
// The parameter admits BOTH paths because distinguishing them is the function's job: defaulted to
|
|
120
|
+
// `SolidPolygonPath`, it cannot be asked about a polygon with holes without the caller asserting past the signature.
|
|
121
|
+
export function isSolidPolygonPath(input: PolygonLiteral<PolygonPath>): boolean {
|
|
122
122
|
return input.coordinates.length === 1
|
|
123
123
|
}
|
|
124
124
|
|
|
@@ -132,6 +132,18 @@ export function isSolidPolygonPath(input: PolygonLiteral): boolean {
|
|
|
132
132
|
*/
|
|
133
133
|
export type ContainmentRing = readonly (readonly number[])[]
|
|
134
134
|
|
|
135
|
+
/**
|
|
136
|
+
* One polygon's rings: `[exterior, ...holes]` — a `Polygon`'s `coordinates`, read loosely (see
|
|
137
|
+
* {@linkcode ContainmentRing}).
|
|
138
|
+
*/
|
|
139
|
+
export type PolygonRings = readonly ContainmentRing[]
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* A feature's polygons — `MultiPolygon` coordinates, with a bare `Polygon` lifted into the same shape by
|
|
143
|
+
* {@linkcode arealPolygons}.
|
|
144
|
+
*/
|
|
145
|
+
export type MultiPolygonRings = readonly PolygonRings[]
|
|
146
|
+
|
|
135
147
|
/**
|
|
136
148
|
* Ray-cast a point against ONE linear ring — the even-odd crossing count. Shoot a ray along +lon and toggle on every
|
|
137
149
|
* edge crossing.
|
|
@@ -164,7 +176,7 @@ export function pointInRing(lon: number, lat: number, ring: ContainmentRing): bo
|
|
|
164
176
|
* without depending on ring winding order. GeoJSON nominally specifies orientation, but the gazetteer sources do not
|
|
165
177
|
* reliably honour it, so the orientation-free rule is the one that survives real data.
|
|
166
178
|
*/
|
|
167
|
-
export function pointInPolygon(lon: number, lat: number, rings:
|
|
179
|
+
export function pointInPolygon(lon: number, lat: number, rings: PolygonRings): boolean {
|
|
168
180
|
let inside = false
|
|
169
181
|
|
|
170
182
|
for (const ring of rings) {
|
|
@@ -190,7 +202,7 @@ export function pointInMultiPolygon(
|
|
|
190
202
|
/**
|
|
191
203
|
* A collection of polygons, such as a country with islands or a lake with islands.
|
|
192
204
|
*/
|
|
193
|
-
export interface MultiPolygonLiteral<P extends PolygonPath =
|
|
205
|
+
export interface MultiPolygonLiteral<P extends PolygonPath = PolygonPath> extends GeoObjectLiteral {
|
|
194
206
|
type: "MultiPolygon"
|
|
195
207
|
|
|
196
208
|
/**
|
|
@@ -202,163 +214,46 @@ export interface MultiPolygonLiteral<P extends PolygonPath = SolidPolygonPath> e
|
|
|
202
214
|
coordinates: P[]
|
|
203
215
|
}
|
|
204
216
|
|
|
205
|
-
|
|
206
|
-
* Predicate for checking if a GeoJSON object is a `MultiPolygon` geometry.
|
|
207
|
-
*/
|
|
217
|
+
//#region Ring-list geometry — the parsed-GeoJSON shape
|
|
208
218
|
|
|
209
219
|
/**
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
220
|
+
* A geometry as it arrives from `JSON.parse`, or a typed literal. Nothing has checked the arity of a position and
|
|
221
|
+
* `type` is whatever the source wrote, so a reader narrows on `type` and casts `coordinates` — {@linkcode arealPolygons}
|
|
222
|
+
* is the one place that happens for the areal types.
|
|
213
223
|
*/
|
|
214
|
-
export
|
|
215
|
-
if (!isPolygonLiteral(input)) return ""
|
|
216
|
-
|
|
217
|
-
const [exteriorRing] = input.coordinates
|
|
218
|
-
|
|
219
|
-
const filter = exteriorRing.map(([lon, lat]) => `${lat} ${lon}`).join(" ")
|
|
220
|
-
|
|
221
|
-
return `poly:'${filter}'`
|
|
222
|
-
}
|
|
224
|
+
export type ParsedGeometry = GeometryLiteral | { type: string; coordinates?: unknown }
|
|
223
225
|
|
|
224
226
|
/**
|
|
225
|
-
*
|
|
227
|
+
* A geometry's polygons in the `MultiPolygon` coordinate shape, whichever areal type it arrived as — `null` when the
|
|
228
|
+
* geometry is not areal (a Point or a LineString bounds no area).
|
|
226
229
|
*
|
|
227
|
-
*
|
|
228
|
-
|
|
229
|
-
export const OSMNodeTag = {
|
|
230
|
-
HouseNumber: "addr:housenumber",
|
|
231
|
-
PostCode: "addr:postcode",
|
|
232
|
-
Street: "addr:street",
|
|
233
|
-
State: "addr:state",
|
|
234
|
-
City: "addr:city",
|
|
235
|
-
Website: "website",
|
|
236
|
-
Email: "email",
|
|
237
|
-
Phone: "phone",
|
|
238
|
-
Shop: "shop",
|
|
239
|
-
Brand: "brand",
|
|
240
|
-
Cuisine: "cuisine",
|
|
241
|
-
Name: "name",
|
|
242
|
-
Healthcare: "healthcare",
|
|
243
|
-
Office: "office",
|
|
244
|
-
Amenity: "amenity",
|
|
245
|
-
} as const
|
|
246
|
-
|
|
247
|
-
export type OSMNodeTag = (typeof OSMNodeTag)[keyof typeof OSMNodeTag]
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* OSM node tags that disqualify a node from being treated as residential — a node carrying one of these is
|
|
251
|
-
* infrastructure or commercial, whatever else it claims.
|
|
230
|
+
* The one place a `Polygon` is lifted to `[rings]`; a caller that must refuse a non-areal geometry does so on the
|
|
231
|
+
* `null`, with its own message.
|
|
252
232
|
*/
|
|
253
|
-
export
|
|
254
|
-
|
|
255
|
-
OSMNodeTag.Brand,
|
|
256
|
-
OSMNodeTag.Cuisine,
|
|
257
|
-
OSMNodeTag.Office,
|
|
258
|
-
OSMNodeTag.Healthcare,
|
|
259
|
-
])
|
|
260
|
-
|
|
261
|
-
export type OSMNodeTagRecord = Record<OSMNodeTag, string | undefined>
|
|
262
|
-
|
|
263
|
-
export interface OSMOverpassElement {
|
|
264
|
-
type: "node"
|
|
265
|
-
id: number
|
|
266
|
-
lat: number
|
|
267
|
-
lon: number
|
|
268
|
-
tags: OSMNodeTagRecord
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
export interface OSMOverpassResponseBody {
|
|
272
|
-
version: string
|
|
273
|
-
generator: string
|
|
274
|
-
osm3s: {
|
|
275
|
-
timestamp_osm_base: string
|
|
276
|
-
copyright: string
|
|
277
|
-
}
|
|
278
|
-
elements: OSMOverpassElement[]
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* Given an OSM element, attempts to infer if the result is a residential address.
|
|
283
|
-
*/
|
|
284
|
-
export function isResidentialElement(element: OSMOverpassElement): boolean {
|
|
285
|
-
for (const key in element.tags) {
|
|
286
|
-
if (ForbiddenResidentialOSMNodeTags.has(key as OSMNodeTag)) return false
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
if (element.tags[OSMNodeTag.Amenity] === "restaurant") return false
|
|
290
|
-
|
|
291
|
-
return true
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
const overpassClient = new APIClient({ displayName: "overpass", retry: true })
|
|
233
|
+
export function arealPolygons(geometry: ParsedGeometry | null | undefined): MultiPolygonRings | null {
|
|
234
|
+
if (!geometry) return null
|
|
295
235
|
|
|
296
|
-
|
|
297
|
-
const filter = polygonToOSMFilter(input)
|
|
236
|
+
if (geometry.type === "Polygon") return [geometry.coordinates as PolygonRings]
|
|
298
237
|
|
|
299
|
-
|
|
300
|
-
url.searchParams.set("data", `[out:json];(node['addr:housenumber'](${filter}););out body;>;out skel qt;`)
|
|
238
|
+
if (geometry.type === "MultiPolygon") return geometry.coordinates as MultiPolygonRings
|
|
301
239
|
|
|
302
|
-
|
|
303
|
-
// reads that header, which is the server stating its own limit rather than this file guessing one. `ResourceError`
|
|
304
|
-
// now arrives from the client instead of being assembled here.
|
|
305
|
-
return overpassClient
|
|
306
|
-
.fetch<OSMOverpassResponseBody>({ url: url.toString() })
|
|
307
|
-
.then(pluckResponseData)
|
|
308
|
-
.then((body) => body.elements)
|
|
309
|
-
.catch((error) => {
|
|
310
|
-
throw ResourceError.wrap(error, "osm", "overpass-api", "fetch")
|
|
311
|
-
})
|
|
240
|
+
return null
|
|
312
241
|
}
|
|
313
242
|
|
|
314
|
-
//#region Ring-list geometry — the parsed-GeoJSON shape
|
|
315
|
-
|
|
316
243
|
/**
|
|
317
|
-
*
|
|
244
|
+
* The polygons of a geometry that MUST be areal — {@linkcode arealPolygons} with the refusal every polygon ingest was
|
|
245
|
+
* writing for itself.
|
|
318
246
|
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
247
|
+
* @param subject Names the feature in the refusal, e.g. `feature 41209`.
|
|
248
|
+
* @param context Names the calling ingest, so a build log says which layer stopped.
|
|
249
|
+
* @throws {Error} When the geometry is neither a `Polygon` nor a `MultiPolygon`.
|
|
321
250
|
*/
|
|
322
|
-
export
|
|
251
|
+
export function requireArealPolygons(geometry: ParsedGeometry, subject: string, context: string): MultiPolygonRings {
|
|
252
|
+
const polygons = arealPolygons(geometry)
|
|
323
253
|
|
|
324
|
-
|
|
325
|
-
* A GeoJSON `Polygon` as a RING LIST — `[outerRing, hole1, hole2, …]`.
|
|
326
|
-
*
|
|
327
|
-
* This coexists with {@linkcode PolygonLiteral} on purpose, and the difference is load-bearing. `PolygonLiteral`
|
|
328
|
-
* defaults to {@linkcode SolidPolygonPath}, a one-element tuple that cannot express a hole; a real administrative
|
|
329
|
-
* boundary routinely has them (a country with a lake, a locality with an enclave). Use this type for geometry read off
|
|
330
|
-
* a gazetteer, and `PolygonLiteral` where the solid/nested distinction is one you are asserting rather than
|
|
331
|
-
* discovering.
|
|
332
|
-
*/
|
|
333
|
-
export interface GeojsonPolygon {
|
|
334
|
-
type: "Polygon"
|
|
335
|
-
coordinates: GeojsonPosition[][]
|
|
336
|
-
}
|
|
254
|
+
if (polygons) return polygons
|
|
337
255
|
|
|
338
|
-
|
|
339
|
-
* A GeoJSON `MultiPolygon` — one ring list per polygon.
|
|
340
|
-
*/
|
|
341
|
-
export interface GeojsonMultiPolygon {
|
|
342
|
-
type: "MultiPolygon"
|
|
343
|
-
coordinates: GeojsonPosition[][][]
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* Either areal geometry, or an open fallback for the types containment cannot answer (Point, LineString, …).
|
|
348
|
-
*/
|
|
349
|
-
export type GeojsonGeometry = GeojsonPolygon | GeojsonMultiPolygon | { type: string; coordinates?: unknown }
|
|
350
|
-
|
|
351
|
-
/**
|
|
352
|
-
* Even-odd containment over a polygon's ring list (`[outer, hole1, …]`).
|
|
353
|
-
*
|
|
354
|
-
* A named alias for {@linkcode pointInPolygon}: the "rings" spelling is what makes the ring-list argument obvious at a
|
|
355
|
-
* call site that has just pulled `coordinates` off a parsed geometry.
|
|
356
|
-
*
|
|
357
|
-
* `scripts/eval/pip-containment.py` grades the same containment truth against its own ray cast and has to be matched BY
|
|
358
|
-
* HAND if this one changes — it is the one copy no import can reach.
|
|
359
|
-
*/
|
|
360
|
-
export function pointInPolygonRings(lon: number, lat: number, rings: readonly GeojsonPosition[][]): boolean {
|
|
361
|
-
return pointInPolygon(lon, lat, rings)
|
|
256
|
+
throw new Error(`${context}: ${subject} is a ${geometry.type}, expected Polygon or MultiPolygon`)
|
|
362
257
|
}
|
|
363
258
|
|
|
364
259
|
/**
|
|
@@ -368,23 +263,52 @@ export function pointInPolygonRings(lon: number, lat: number, rings: readonly Ge
|
|
|
368
263
|
* LineString cannot contain anything — and a caller must read that as "no polygon on record", the same as a missing
|
|
369
264
|
* geometry, never as a rejection. Collapsing it to `false` is how a place with a point-only record gets excluded from a
|
|
370
265
|
* containment pass instead of falling through to the approximate path.
|
|
266
|
+
*
|
|
267
|
+
* `scripts/eval/pip-containment.py` grades the same containment truth against its own ray cast and has to be matched BY
|
|
268
|
+
* HAND if this one changes — it is the one copy no import can reach.
|
|
371
269
|
*/
|
|
372
270
|
export function geometryContains(
|
|
373
|
-
geometry:
|
|
271
|
+
geometry: ParsedGeometry | null | undefined,
|
|
374
272
|
lon: number,
|
|
375
273
|
lat: number
|
|
376
274
|
): boolean | null {
|
|
377
|
-
|
|
275
|
+
const polygons = arealPolygons(geometry)
|
|
378
276
|
|
|
379
|
-
if (
|
|
380
|
-
return pointInPolygonRings(lon, lat, (geometry as GeojsonPolygon).coordinates)
|
|
381
|
-
}
|
|
277
|
+
if (!polygons) return null
|
|
382
278
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
}
|
|
279
|
+
return polygons.some((rings) => pointInPolygon(lon, lat, rings))
|
|
280
|
+
}
|
|
386
281
|
|
|
387
|
-
|
|
282
|
+
/**
|
|
283
|
+
* An axis-aligned rectangle as a closed ring, in GeoJSON `[lon, lat]` order and counter-clockwise — the exterior
|
|
284
|
+
* winding.
|
|
285
|
+
*
|
|
286
|
+
* SHARED BECAUSE THE WINDING IS A CONVENTION AND A SECOND COPY IS A SECOND PLACE FOR IT TO DRIFT. Three layer builders
|
|
287
|
+
* hand-build rectangles for their fixture rungs, and each pairs this with {@link reversedRing} to make a hole. A copy
|
|
288
|
+
* whose hole is wound the same way as its exterior produces a fixture that passes every structural check and tests
|
|
289
|
+
* nothing about hole handling — which is the exact failure the area cross-check exists to catch in production data.
|
|
290
|
+
*/
|
|
291
|
+
export function rectangleRing(minLon: number, minLat: number, maxLon: number, maxLat: number): number[][] {
|
|
292
|
+
return [
|
|
293
|
+
[minLon, minLat],
|
|
294
|
+
[maxLon, minLat],
|
|
295
|
+
[maxLon, maxLat],
|
|
296
|
+
[minLon, maxLat],
|
|
297
|
+
[minLon, minLat],
|
|
298
|
+
]
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* The same rectangle wound the other way — a hole, under the GeoJSON convention.
|
|
303
|
+
*/
|
|
304
|
+
export function reversedRing(minLon: number, minLat: number, maxLon: number, maxLat: number): number[][] {
|
|
305
|
+
return [
|
|
306
|
+
[minLon, minLat],
|
|
307
|
+
[minLon, maxLat],
|
|
308
|
+
[maxLon, maxLat],
|
|
309
|
+
[maxLon, minLat],
|
|
310
|
+
[minLon, minLat],
|
|
311
|
+
]
|
|
388
312
|
}
|
|
389
313
|
|
|
390
314
|
//#endregion
|