@mailwoman/spatial 10.0.0 → 10.2.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.
Files changed (148) hide show
  1. package/README.md +2 -2
  2. package/lib/bbox.ts +41 -34
  3. package/lib/coordinate/bounds.ts +2 -2
  4. package/lib/coordinate/formats.ts +21 -33
  5. package/lib/distance.ts +56 -28
  6. package/lib/feature.ts +2 -2
  7. package/lib/geometries/point.ts +42 -35
  8. package/lib/geometries/polygon.ts +27 -135
  9. package/lib/geometries/ring-blob.ts +35 -132
  10. package/lib/google/place-id.ts +4 -2
  11. package/lib/h3/cell.ts +23 -78
  12. package/lib/h3/coverage.ts +13 -9
  13. package/lib/h3/interior-cells.ts +13 -34
  14. package/lib/h3/polygon-cells.ts +61 -167
  15. package/lib/{h3/index.ts → h3.ts} +1 -1
  16. package/lib/index.ts +6 -5
  17. package/lib/objects.ts +6 -6
  18. package/lib/open-location-code.ts +11 -42
  19. package/lib/osgb36.ts +28 -187
  20. package/lib/polyline.ts +5 -3
  21. package/lib/position.ts +39 -20
  22. package/lib/projection/transform.ts +43 -44
  23. package/lib/{projection/index.ts → projection.ts} +1 -1
  24. package/lib/well-known-text.ts +9 -9
  25. package/out/bbox.d.ts +17 -14
  26. package/out/bbox.d.ts.map +1 -1
  27. package/out/bbox.js +32 -23
  28. package/out/bbox.js.map +1 -1
  29. package/out/coordinate/bounds.d.ts +2 -2
  30. package/out/coordinate/bounds.js +2 -2
  31. package/out/coordinate/formats.d.ts +17 -16
  32. package/out/coordinate/formats.d.ts.map +1 -1
  33. package/out/coordinate/formats.js +20 -32
  34. package/out/coordinate/formats.js.map +1 -1
  35. package/out/distance.d.ts +51 -26
  36. package/out/distance.d.ts.map +1 -1
  37. package/out/distance.js +53 -27
  38. package/out/distance.js.map +1 -1
  39. package/out/feature.d.ts +2 -2
  40. package/out/feature.d.ts.map +1 -1
  41. package/out/geometries/point.d.ts +30 -22
  42. package/out/geometries/point.d.ts.map +1 -1
  43. package/out/geometries/point.js +37 -30
  44. package/out/geometries/point.js.map +1 -1
  45. package/out/geometries/polygon.d.ts +27 -126
  46. package/out/geometries/polygon.d.ts.map +1 -1
  47. package/out/geometries/polygon.js +14 -42
  48. package/out/geometries/polygon.js.map +1 -1
  49. package/out/geometries/ring-blob.d.ts +24 -110
  50. package/out/geometries/ring-blob.d.ts.map +1 -1
  51. package/out/geometries/ring-blob.js +30 -116
  52. package/out/geometries/ring-blob.js.map +1 -1
  53. package/out/{geometries/index.js → geometries.d.ts} +1 -1
  54. package/out/geometries.d.ts.map +1 -0
  55. package/out/{geometries/index.d.ts → geometries.js} +1 -1
  56. package/out/geometries.js.map +1 -0
  57. package/out/google/place-id.d.ts +4 -2
  58. package/out/google/place-id.d.ts.map +1 -1
  59. package/out/google/place-id.js.map +1 -1
  60. package/out/{google/index.d.ts → google.d.ts} +1 -1
  61. package/out/google.d.ts.map +1 -0
  62. package/out/{google/index.js → google.js} +1 -1
  63. package/out/google.js.map +1 -0
  64. package/out/h3/cell.d.ts +19 -73
  65. package/out/h3/cell.d.ts.map +1 -1
  66. package/out/h3/cell.js +22 -65
  67. package/out/h3/cell.js.map +1 -1
  68. package/out/h3/coverage.d.ts +12 -8
  69. package/out/h3/coverage.d.ts.map +1 -1
  70. package/out/h3/coverage.js +12 -8
  71. package/out/h3/coverage.js.map +1 -1
  72. package/out/h3/interior-cells.d.ts +9 -28
  73. package/out/h3/interior-cells.d.ts.map +1 -1
  74. package/out/h3/interior-cells.js +13 -32
  75. package/out/h3/interior-cells.js.map +1 -1
  76. package/out/h3/polygon-cells.d.ts +28 -120
  77. package/out/h3/polygon-cells.d.ts.map +1 -1
  78. package/out/h3/polygon-cells.js +50 -148
  79. package/out/h3/polygon-cells.js.map +1 -1
  80. package/out/{h3/index.d.ts → h3.d.ts} +2 -2
  81. package/out/h3.d.ts.map +1 -0
  82. package/out/{h3/index.js → h3.js} +2 -2
  83. package/out/h3.js.map +1 -0
  84. package/out/index.d.ts +6 -5
  85. package/out/index.d.ts.map +1 -1
  86. package/out/index.js +6 -5
  87. package/out/index.js.map +1 -1
  88. package/out/objects.d.ts +6 -6
  89. package/out/open-location-code.d.ts +11 -22
  90. package/out/open-location-code.d.ts.map +1 -1
  91. package/out/open-location-code.js +9 -40
  92. package/out/open-location-code.js.map +1 -1
  93. package/out/osgb36.d.ts +21 -97
  94. package/out/osgb36.d.ts.map +1 -1
  95. package/out/osgb36.js +12 -165
  96. package/out/osgb36.js.map +1 -1
  97. package/out/polyline.d.ts +5 -3
  98. package/out/polyline.d.ts.map +1 -1
  99. package/out/polyline.js +5 -3
  100. package/out/polyline.js.map +1 -1
  101. package/out/position.d.ts +36 -20
  102. package/out/position.d.ts.map +1 -1
  103. package/out/position.js +0 -1
  104. package/out/position.js.map +1 -1
  105. package/out/projection/transform.d.ts +33 -30
  106. package/out/projection/transform.d.ts.map +1 -1
  107. package/out/projection/transform.js +15 -17
  108. package/out/projection/transform.js.map +1 -1
  109. package/out/{projection/index.d.ts → projection.d.ts} +2 -2
  110. package/out/projection.d.ts.map +1 -0
  111. package/out/{projection/index.js → projection.js} +2 -2
  112. package/out/projection.js.map +1 -0
  113. package/out/{regions/index.js → regions.d.ts} +1 -1
  114. package/out/regions.d.ts.map +1 -0
  115. package/out/{regions/index.d.ts → regions.js} +1 -1
  116. package/out/regions.js.map +1 -0
  117. package/out/tools/ogr/stream.d.ts +21 -11
  118. package/out/tools/ogr/stream.d.ts.map +1 -1
  119. package/out/tools/ogr/stream.js +17 -10
  120. package/out/tools/ogr/stream.js.map +1 -1
  121. package/out/tools/{ogr/index.d.ts → ogr.d.ts} +25 -15
  122. package/out/tools/ogr.d.ts.map +1 -0
  123. package/out/tools/{ogr/index.js → ogr.js} +25 -21
  124. package/out/tools/ogr.js.map +1 -0
  125. package/out/tools/tsconfig.tsbuildinfo +1 -0
  126. package/out/tsconfig.test.tsbuildinfo +1 -1
  127. package/out/well-known-text.d.ts +9 -9
  128. package/out/well-known-text.d.ts.map +1 -1
  129. package/out/well-known-text.js +7 -7
  130. package/out/well-known-text.js.map +1 -1
  131. package/package.json +37 -129
  132. package/{lib/tools → tools}/ogr/stream.ts +26 -15
  133. package/{lib/tools/ogr/index.ts → tools/ogr.ts} +44 -30
  134. package/out/geometries/index.d.ts.map +0 -1
  135. package/out/geometries/index.js.map +0 -1
  136. package/out/google/index.d.ts.map +0 -1
  137. package/out/google/index.js.map +0 -1
  138. package/out/h3/index.d.ts.map +0 -1
  139. package/out/h3/index.js.map +0 -1
  140. package/out/projection/index.d.ts.map +0 -1
  141. package/out/projection/index.js.map +0 -1
  142. package/out/regions/index.d.ts.map +0 -1
  143. package/out/regions/index.js.map +0 -1
  144. package/out/tools/ogr/index.d.ts.map +0 -1
  145. package/out/tools/ogr/index.js.map +0 -1
  146. /package/lib/{geometries/index.ts → geometries.ts} +0 -0
  147. /package/lib/{google/index.ts → google.ts} +0 -0
  148. /package/lib/{regions/index.ts → regions.ts} +0 -0
@@ -1,21 +1,18 @@
1
1
  import { runFile } from "@mailwoman/core/process";
2
+ import { TextSpliterator } from "spliterator";
2
3
  /**
3
- * Read `projinfo --summary` output: which operation PROJ would choose, and whether it can actually run.
4
+ * Reads `projinfo --summary` output.
5
+ *
6
+ * It reports which operation PROJ would choose and whether it can run it.
4
7
  */
5
8
  export function assessDatumTransformation(summary) {
6
- // The first line naming a candidate operation is the one PROJ will choose. Everything before it is a header, and the
7
- // `Note:` line about `--spatial-test` is not a candidate.
8
- //
9
- // `projinfo --summary` prints a header plus one line per candidate operation: two to nine lines, bounded by PROJ's own
10
- // candidate enumeration rather than by input size. Reaching for a streaming reader would put a `spliterator` dependency
11
- // on this package for a fixed handful of lines.
12
- // oxlint-disable-next-line mailwoman/prefer-spliterator -- bounded output, see above
13
- const lines = summary.split("\n");
14
- const best = lines
15
- .map((line) => line.trim())
16
- .find((line) => line.includes(", ") && !line.startsWith("Note:") && !line.startsWith("Candidate operations"));
9
+ // The first line naming a candidate operation is the one PROJ will choose.
10
+ // Earlier lines are headers.
11
+ // The `Note:` line about `--spatial-test` also describes no candidate operation.
12
+ // The reader trims each line.
13
+ const best = TextSpliterator.from(summary).find((line) => line.includes(", ") && !line.startsWith("Note:") && !line.startsWith("Candidate operations"));
17
14
  if (!best)
18
- return { usable: false, reason: "projinfo named no candidate operation" };
15
+ return { best: null, usable: false, reason: "projinfo named no candidate operation" };
19
16
  if (best.includes("grid missing"))
20
17
  return { best, usable: false, reason: "its grid is not installed" };
21
18
  if (best.toLowerCase().includes("ballpark"))
@@ -23,14 +20,15 @@ export function assessDatumTransformation(summary) {
23
20
  return { best, usable: true, reason: "the best operation is available" };
24
21
  }
25
22
  /**
26
- * The target every layer ingest reprojects to — H3 takes WGS84 latitude and longitude.
23
+ * The target every layer ingest reprojects to.
24
+ * H3 takes WGS84 latitude and longitude.
27
25
  */
28
26
  export const WGS84_EPSG = 4326;
29
27
  /**
30
28
  * Refuse an ingest whose best available datum transformation is a ballpark one, or is missing its grid.
31
29
  *
32
- * @throws {Error} When PROJ names no candidate, would use a ballpark offset, or would use an operation whose grid is
33
- * not installed.
30
+ * @throws {Error} When proj names no candidate, would use a ballpark offset,
31
+ * or would use an operation whose grid is not installed.
34
32
  */
35
33
  export async function assertDatumTransformationAvailable(sourceEPSG, options) {
36
34
  const targetEPSG = options.targetEPSG ?? WGS84_EPSG;
@@ -42,7 +40,7 @@ export async function assertDatumTransformationAvailable(sourceEPSG, options) {
42
40
  ? `Install the grid with \`projsync --area-of-use "${options.areaOfUse}"\` and re-run.`
43
41
  : "Install the grid with `projsync` for the source's area of use and re-run.";
44
42
  throw new Error(`${options.context}: the best EPSG:${sourceEPSG} → EPSG:${targetEPSG} transformation is unusable — ${verdict.reason} ` +
45
- `(${verdict.best ?? "projinfo named no candidate"}). PROJ falls back to a ballpark datum shift, which is metres ` +
43
+ `(${verdict.best ?? "projinfo named no candidate"}). PROJ falls back to a ballpark datum shift, which is meters ` +
46
44
  `wrong and looks exactly like a correct answer. ${remedy}`);
47
45
  }
48
46
  //# sourceMappingURL=transform.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"transform.js","sourceRoot":"","sources":["../../lib/projection/transform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAA;AA4CjD;;GAEG;AACH,MAAM,UAAU,yBAAyB,CAAC,OAAe;IACxD,qHAAqH;IACrH,0DAA0D;IAC1D,EAAE;IACF,uHAAuH;IACvH,wHAAwH;IACxH,gDAAgD;IAChD,qFAAqF;IACrF,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAEjC,MAAM,IAAI,GAAG,KAAK;SAChB,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;SAC1B,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,sBAAsB,CAAC,CAAC,CAAA;IAE9G,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,uCAAuC,EAAE,CAAA;IAEpF,IAAI,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,2BAA2B,EAAE,CAAA;IAEtG,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,yBAAyB,EAAE,CAAA;IAE9G,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,iCAAiC,EAAE,CAAA;AACzE,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG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AE9E,MAAM,IAAI,KAAK,CACd,GAAG,OAAO,CAAC,OAAO,mBAAmB,UAAU,WAAW,UAAU,iCAAiC,OAAO,CAAC,MAAM,GAAG;QACrH,IAAI,OAAO,CAAC,IAAI,IAAI,6BAA6B,gEAAgE;QACjH,kDAAkD,MAAM,EAAE,CAC3D,CAAA;AACF,CAAC"}
@@ -16,9 +16,9 @@ export declare const CoordinateProjection: {
16
16
  */
17
17
  readonly WGS84: "4326";
18
18
  /**
19
- * North American Datum 1983, a geodetic reference system used in the TIGER/Line data.
19
+ * North American Datum 1983, a geodetic reference system used in the tiger/Line data.
20
20
  */
21
21
  readonly NAD83: "4269";
22
22
  };
23
23
  export type CoordinateProjection = (typeof CoordinateProjection)[keyof typeof CoordinateProjection];
24
- //# sourceMappingURL=index.d.ts.map
24
+ //# sourceMappingURL=projection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projection.d.ts","sourceRoot":"","sources":["../lib/projection.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AACH,eAAO,MAAM,oBAAoB;IAChC;;;;OAIG;aACH,KAAK,EAAE,MAAM;IACb;;OAEG;aACH,KAAK,EAAE,MAAM;CACJ,CAAA;AAEV,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,OAAO,oBAAoB,CAAC,CAAA"}
@@ -16,8 +16,8 @@ export const CoordinateProjection = {
16
16
  */
17
17
  WGS84: "4326",
18
18
  /**
19
- * North American Datum 1983, a geodetic reference system used in the TIGER/Line data.
19
+ * North American Datum 1983, a geodetic reference system used in the tiger/Line data.
20
20
  */
21
21
  NAD83: "4269",
22
22
  };
23
- //# sourceMappingURL=index.js.map
23
+ //# sourceMappingURL=projection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projection.js","sourceRoot":"","sources":["../lib/projection.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IACnC;;;;OAIG;IACH,KAAK,EAAE,MAAM;IACb;;OAEG;IACH,KAAK,EAAE,MAAM;CACJ,CAAA"}
@@ -5,4 +5,4 @@
5
5
  */
6
6
  export * from "#regions/codes";
7
7
  export * from "#regions/names";
8
- //# sourceMappingURL=index.js.map
8
+ //# sourceMappingURL=regions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"regions.d.ts","sourceRoot":"","sources":["../lib/regions.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA"}
@@ -5,4 +5,4 @@
5
5
  */
6
6
  export * from "#regions/codes";
7
7
  export * from "#regions/names";
8
- //# sourceMappingURL=index.d.ts.map
8
+ //# sourceMappingURL=regions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"regions.js","sourceRoot":"","sources":["../lib/regions.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,gBAAgB,CAAA;AAC9B,cAAc,gBAAgB,CAAA"}
@@ -4,12 +4,16 @@
4
4
  * @author Teffen Ellis, et al.
5
5
  * @file One ogr2ogr harness for every streaming extraction.
6
6
  */
7
+ import type { PathBuilderLike } from "path-ts";
7
8
  export interface OGRProcess {
8
9
  stdout: NodeJS.ReadableStream;
9
10
  /**
10
- * Resolves on a clean exit; rejects with the exit code and the stderr tail otherwise. A truncated stream reads as a
11
- * short but well-formed feature list, which is exactly the partial result that must throw rather than be reported as
12
- * a smaller extract — so consume the stream fully, then await this.
11
+ * Resolves on a clean exit.
12
+ * Rejects with the exit code and the stderr tail otherwise.
13
+ *
14
+ * A truncated stream can look like a shorter, valid feature list.
15
+ * That partial result must raise an error instead of looking like a smaller extract.
16
+ * Consume the stream fully, then await this promise.
13
17
  */
14
18
  settled: Promise<void>;
15
19
  /**
@@ -18,17 +22,23 @@ export interface OGRProcess {
18
22
  kill: () => void;
19
23
  }
20
24
  /**
21
- * Spawn `ogr2ogr` with stderr accumulated for the failure message. The caller owns the stdout format (GeoJSONSeq, CSV,
22
- * …) and its parsing; {@link ogr2ogrGeoJSONSeq} is the GeoJSONSeq reading over this.
25
+ * Spawn `ogr2ogr` with stderr accumulated for the failure message.
26
+ *
27
+ * The caller owns the stdout format (GeoJSONSeq, CSV, …) and its parsing;
28
+ * {@link ogr2ogrGeoJSONSeq} is the GeoJSONSeq reading over this.
23
29
  */
24
- export declare function spawnOGR2OGR(args: readonly string[], context: string): OGRProcess;
30
+ export declare function spawnOGR2OGR(args: readonly PathBuilderLike[], context: string): OGRProcess;
25
31
  /**
26
32
  * Stream a GeoJSONSeq extraction as parsed features.
27
33
  *
28
- * Strips the RFC-8142 record separator (U+001E) GDAL MAY prefix records with — `.trim()` does not remove it (not
29
- * whitespace), so an RS-framed record would fail to parse and be silently skipped, all of them, and an empty extract
30
- * would read as a real absence. A malformed record is tolerated (skipped) rather than thrown; a non-zero exit throws
31
- * after the stream drains.
34
+ * Strips the RFC-8142 record separator (U+001E) gdal may prefix records with.
35
+ * `.trim()` leaves U+001E intact.
36
+ *
37
+ * The parser strips it first because `tryParsingJSON` would otherwise skip each RS-prefixed record.
38
+ * If the code skipped every record, an empty extract would look like a real absence.
39
+ *
40
+ * A malformed record is tolerated (skipped) rather than thrown.
41
+ * A non-zero exit throws after the stream drains.
32
42
  */
33
- export declare function ogr2ogrGeoJSONSeq<T>(args: readonly string[], context: string): AsyncGenerator<T>;
43
+ export declare function ogr2ogrGeoJSONSeq<T>(args: readonly PathBuilderLike[], context: string): AsyncGenerator<T>;
34
44
  //# sourceMappingURL=stream.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../../lib/tools/ogr/stream.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,MAAM,WAAW,UAAU;IAC1B,MAAM,EAAE,MAAM,CAAC,cAAc,CAAA;IAC7B;;;;OAIG;IACH,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;IACtB;;OAEG;IACH,IAAI,EAAE,MAAM,IAAI,CAAA;CAChB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,UAAU,CAoCjF;AAED;;;;;;;GAOG;AACH,wBAAuB,iBAAiB,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,cAAc,CAAC,CAAC,CAAC,CAoBvG"}
1
+ {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../../tools/ogr/stream.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAM9C,MAAM,WAAW,UAAU;IAC1B,MAAM,EAAE,MAAM,CAAC,cAAc,CAAA;IAC7B;;;;;;;OAOG;IACH,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;IACtB;;OAEG;IACH,IAAI,EAAE,MAAM,IAAI,CAAA;CAChB;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,SAAS,eAAe,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,UAAU,CAqC1F;AAED;;;;;;;;;;;GAWG;AACH,wBAAuB,iBAAiB,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,eAAe,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,cAAc,CAAC,CAAC,CAAC,CAoBhH"}
@@ -10,8 +10,10 @@ import { TextSpliterator } from "spliterator";
10
10
  const RECORD_SEPARATOR = 0x1e;
11
11
  const STDERR_TAIL_CHARS = 800;
12
12
  /**
13
- * Spawn `ogr2ogr` with stderr accumulated for the failure message. The caller owns the stdout format (GeoJSONSeq, CSV,
14
- * …) and its parsing; {@link ogr2ogrGeoJSONSeq} is the GeoJSONSeq reading over this.
13
+ * Spawn `ogr2ogr` with stderr accumulated for the failure message.
14
+ *
15
+ * The caller owns the stdout format (GeoJSONSeq, CSV, …) and its parsing;
16
+ * {@link ogr2ogrGeoJSONSeq} is the GeoJSONSeq reading over this.
15
17
  */
16
18
  export function spawnOGR2OGR(args, context) {
17
19
  const child = spawnProcess("ogr2ogr", [...args], { stdio: ["ignore", "pipe", "pipe"] });
@@ -31,15 +33,16 @@ export function spawnOGR2OGR(args, context) {
31
33
  }
32
34
  });
33
35
  });
34
- // A failed spawn rejects `settled` BEFORE any consumer awaits it — the consumer is still draining the stream on a
35
- // later tick, and a consumer that abandons the stream never awaits it at all — so an unobserved rejection would trip
36
- // the process's unhandled-rejection hook. Observed at birth instead; every consumer still awaits the real verdict.
36
+ // A failed spawn can reject `settled` before a consumer awaits it.
37
+ // A consumer may still be draining stdout on a later tick or may abandon the stream.
38
+ // Attach a handler at birth to prevent an unhandled-rejection event.
39
+ // Every consumer still awaits the real verdict.
37
40
  settled.catch(() => undefined);
38
41
  return {
39
42
  stdout: child.stdout,
40
43
  settled,
41
44
  kill: () => {
42
- if (child.exitCode === null && child.signalCode === null) {
45
+ if (child.exitCode === null && !child.signalCode) {
43
46
  child.kill();
44
47
  }
45
48
  },
@@ -48,10 +51,14 @@ export function spawnOGR2OGR(args, context) {
48
51
  /**
49
52
  * Stream a GeoJSONSeq extraction as parsed features.
50
53
  *
51
- * Strips the RFC-8142 record separator (U+001E) GDAL MAY prefix records with — `.trim()` does not remove it (not
52
- * whitespace), so an RS-framed record would fail to parse and be silently skipped, all of them, and an empty extract
53
- * would read as a real absence. A malformed record is tolerated (skipped) rather than thrown; a non-zero exit throws
54
- * after the stream drains.
54
+ * Strips the RFC-8142 record separator (U+001E) gdal may prefix records with.
55
+ * `.trim()` leaves U+001E intact.
56
+ *
57
+ * The parser strips it first because `tryParsingJSON` would otherwise skip each RS-prefixed record.
58
+ * If the code skipped every record, an empty extract would look like a real absence.
59
+ *
60
+ * A malformed record is tolerated (skipped) rather than thrown.
61
+ * A non-zero exit throws after the stream drains.
55
62
  */
56
63
  export async function* ogr2ogrGeoJSONSeq(args, context) {
57
64
  const proc = spawnOGR2OGR(args, context);
@@ -1 +1 @@
1
- {"version":3,"file":"stream.js","sourceRoot":"","sources":["../../../lib/tools/ogr/stream.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAE7C,MAAM,gBAAgB,GAAG,IAAI,CAAA;AAC7B,MAAM,iBAAiB,GAAG,GAAG,CAAA;AAgB7B;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,IAAuB,EAAE,OAAe;IACpE,MAAM,KAAK,GAAG,YAAY,CAAC,SAAS,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,CAAA;IACvF,IAAI,MAAM,GAAG,EAAE,CAAA;IAEf,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;IAEhC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE;QACzC,MAAM,IAAI,KAAK,CAAA;IAChB,CAAC,CAAC,CAAA;IAEF,MAAM,OAAO,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrD,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;QAEzB,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;YAC1B,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;gBAChB,OAAO,EAAE,CAAA;YACV,CAAC;iBAAM,CAAC;gBACP,MAAM,CAAC,IAAI,KAAK,CAAC,GAAG,OAAO,oBAAoB,IAAI,KAAK,MAAM,CAAC,KAAK,CAAC,CAAC,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GR-readable source declares about itself, read before any feature is — the identity check every
7
7
  * polygon-layer ingest opens with.
8
8
  *
9
- * OGR IS BUILD TOOLING, NEVER A SERVE DEPENDENCY (SCOPE invariant 6). The check refuses a source whose
9
+ * OGR is build tooling, never A serve dependency (scope invariant 6). The check refuses a source whose
10
10
  * declared authority code is not the one the ingest was written for, because reading one projection's
11
11
  * coordinates as another's is silent — and it runs the datum-transformation guard even where no shift is
12
12
  * needed, because skipping it on the reasoning that a source needs no shift makes the guard fire on the day
13
13
  * a source arrives that does.
14
14
  */
15
15
  /**
16
- * What one layer declares about itself.
16
+ * A layer's EPSG code, feature count, name and attribute field names, read before any feature.
17
17
  */
18
- export interface OGRLayerIdentity {
18
+ export interface OGRLayerSchema {
19
19
  epsg: number;
20
20
  featureCount: number;
21
21
  layer: string;
22
22
  /**
23
23
  * The layer's own attribute field names — empty when the source reports none.
24
+ *
25
+ * ogr2ogr rejects a `select` that asks for a missing column, so query builders read this set.
24
26
  */
25
27
  fields: ReadonlySet<string>;
28
+ }
29
+ /**
30
+ * What one layer declares about itself.
31
+ */
32
+ export interface OGRLayerIdentity extends OGRLayerSchema {
26
33
  /**
27
34
  * The layer's own declared extent, `[minLon, minLat, maxLon, maxLat]`, where the source declares one.
28
35
  */
29
- extent?: readonly [number, number, number, number];
36
+ extent: readonly [number, number, number, number] | null;
30
37
  }
31
38
  export interface ReadOGRLayerIdentityOptions {
32
39
  /**
@@ -34,13 +41,15 @@ export interface ReadOGRLayerIdentityOptions {
34
41
  */
35
42
  path: string;
36
43
  /**
37
- * Layer inside it, asserted against what the source answers. Omitted, the source's first layer answers and only its
38
- * presence is checked.
44
+ * Layer inside it, asserted against what the source answers.
45
+ *
46
+ * Omitted, the source's first layer answers and only its presence is checked.
39
47
  */
40
48
  layer?: string;
41
49
  /**
42
- * The EPSG code the source must declare. A source declaring anything else is a product change, not a variation to
43
- * absorb.
50
+ * The epsg code the source must declare.
51
+ *
52
+ * A source declaring anything else is a product change rather than a variation to absorb.
44
53
  */
45
54
  expectEPSG: number;
46
55
  /**
@@ -50,7 +59,7 @@ export interface ReadOGRLayerIdentityOptions {
50
59
  /**
51
60
  * Forwarded to the datum-transformation guard.
52
61
  */
53
- areaOfUse?: string;
62
+ areaOfUse?: string | null;
54
63
  /**
55
64
  * Refuse a layer that declares no extent.
56
65
  */
@@ -64,11 +73,11 @@ export interface ReadOGRLayerIdentityOptions {
64
73
  */
65
74
  messages?: {
66
75
  /**
67
- * After `declares no EPSG authority code — `.
76
+ * After `declares no epsg authority code — `.
68
77
  */
69
78
  noAuthorityCode?: string;
70
79
  /**
71
- * After `expected EPSG:<code> — `.
80
+ * After `expected epsg:<code> — `.
72
81
  */
73
82
  epsgMismatch?: string;
74
83
  /**
@@ -78,10 +87,11 @@ export interface ReadOGRLayerIdentityOptions {
78
87
  };
79
88
  }
80
89
  /**
81
- * Read what the source declares about itself, and refuse a projection the calling ingest was not written for.
90
+ * Read what the source declares about itself.
91
+ * Refuse a projection the calling ingest was not written for.
82
92
  *
83
- * @throws {Error} When the layer is missing, declares no EPSG authority code, declares one other than `expectEPSG`,
84
- * reports no feature count, or fails a `requireExtent`/`requireFields` condition.
93
+ * @throws {Error} When the layer is missing, declares no epsg authority code, declares one other than
94
+ * `expectEPSG`, reports no feature count, or fails a `requireExtent`/`requireFields` condition.
85
95
  */
86
96
  export declare function readOGRLayerIdentity(options: ReadOGRLayerIdentityOptions): Promise<OGRLayerIdentity>;
87
- //# sourceMappingURL=index.d.ts.map
97
+ //# sourceMappingURL=ogr.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ogr.d.ts","sourceRoot":"","sources":["../../tools/ogr.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAOH;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,MAAM,CAAA;IACpB,KAAK,EAAE,MAAM,CAAA;IACb;;;;OAIG;IACH,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,gBAAiB,SAAQ,cAAc;IACvD;;OAEG;IACH,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAA;CACxD;AAED,MAAM,WAAW,2BAA2B;IAC3C;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;;OAIG;IACH,UAAU,EAAE,MAAM,CAAA;IAClB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB;;OAEG;IACH,QAAQ,CAAC,EAAE;QACV;;WAEG;QACH,eAAe,CAAC,EAAE,MAAM,CAAA;QACxB;;WAEG;QACH,YAAY,CAAC,EAAE,MAAM,CAAA;QACrB;;WAEG;QACH,WAAW,CAAC,EAAE,MAAM,CAAA;KACpB,CAAA;CACD;AAgBD;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,2BAA2B,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAgG1G"}
@@ -6,50 +6,54 @@
6
6
  * What an OGR-readable source declares about itself, read before any feature is — the identity check every
7
7
  * polygon-layer ingest opens with.
8
8
  *
9
- * OGR IS BUILD TOOLING, NEVER A SERVE DEPENDENCY (SCOPE invariant 6). The check refuses a source whose
9
+ * OGR is build tooling, never A serve dependency (scope invariant 6). The check refuses a source whose
10
10
  * declared authority code is not the one the ingest was written for, because reading one projection's
11
11
  * coordinates as another's is silent — and it runs the datum-transformation guard even where no shift is
12
12
  * needed, because skipping it on the reasoning that a source needs no shift makes the guard fire on the day
13
13
  * a source arrives that does.
14
14
  */
15
- import { parseJSONStrict } from "@mailwoman/core/json";
15
+ import { parseJSONStrict, stringifyJSON } from "@mailwoman/core/json";
16
16
  import { runFile } from "@mailwoman/core/process";
17
17
  import { assertDatumTransformationAvailable } from "#projection/transform";
18
18
  /**
19
- * A summary is small; the ceiling only guards against a pathological driver.
19
+ * A summary is small.
20
+ * The ceiling only guards against a pathological driver.
20
21
  */
21
22
  const OGRINFO_MAX_BUFFER = 32 * 1024 * 1024;
22
23
  /**
23
- * Ordinates in a 2D extent: `minLon, minLat, maxLon, maxLat`. A shorter array is a 3D or degenerate extent this reader
24
- * does not understand, not a 2D one with something missing.
24
+ * Ordinates in a 2D extent: `minLon, minLat, maxLon, maxLat`.
25
+ *
26
+ * A shorter array is a 3D or degenerate extent this reader does not understand
27
+ * rather than a 2D one with something missing.
25
28
  */
26
29
  const EXTENT_ORDINATES = 4;
27
30
  /**
28
- * Read what the source declares about itself, and refuse a projection the calling ingest was not written for.
31
+ * Read what the source declares about itself.
32
+ * Refuse a projection the calling ingest was not written for.
29
33
  *
30
- * @throws {Error} When the layer is missing, declares no EPSG authority code, declares one other than `expectEPSG`,
31
- * reports no feature count, or fails a `requireExtent`/`requireFields` condition.
34
+ * @throws {Error} When the layer is missing, declares no epsg authority code, declares one other than
35
+ * `expectEPSG`, reports no feature count, or fails a `requireExtent`/`requireFields` condition.
32
36
  */
33
37
  export async function readOGRLayerIdentity(options) {
34
- const { stdout } = await runFile("ogrinfo", ["-json", "-so", options.path, ...(options.layer === undefined ? [] : [options.layer])], { maxBuffer: OGRINFO_MAX_BUFFER });
38
+ const { stdout } = await runFile("ogrinfo", ["-json", "-so", options.path, ...(options.layer ? [options.layer] : [])], { maxBuffer: OGRINFO_MAX_BUFFER });
35
39
  const info = parseJSONStrict(stdout);
36
40
  const described = info.layers?.[0];
37
41
  if (!described?.name) {
38
- throw new Error(options.layer === undefined
39
- ? `${options.context}: ${options.path} carries no readable layer`
40
- : `${options.context}: ${options.path} does not carry a layer named ${JSON.stringify(options.layer)}`);
42
+ throw new Error(options.layer
43
+ ? `${options.context}: ${options.path} does not carry a layer named ${stringifyJSON(options.layer)}`
44
+ : `${options.context}: ${options.path} carries no readable layer`);
41
45
  }
42
- if (options.layer !== undefined && described.name !== options.layer) {
43
- throw new Error(`${options.context}: ${options.path} does not carry a layer named ${JSON.stringify(options.layer)}`);
46
+ if (options.layer && described.name !== options.layer) {
47
+ throw new Error(`${options.context}: ${options.path} does not carry a layer named ${stringifyJSON(options.layer)}`);
44
48
  }
45
- // The subject a refusal names: the layer where one was asked for, the dataset itself where the source's own first
46
- // layer answered.
49
+ // The subject a refusal names: the layer where one was asked for, the dataset itself
50
+ // where the source's own first layer answered.
47
51
  const subject = options.layer ?? options.path;
48
52
  const geometry = described.geometryFields?.[0];
49
53
  const code = geometry?.coordinateSystem?.projjson?.id?.code;
50
54
  if (typeof code !== "number") {
51
55
  throw new TypeError(`${options.context}: ${subject} declares no EPSG authority code — ${options.messages?.noAuthorityCode ??
52
- "the projection cannot be checked, and reading its metres as degrees is silent"}`);
56
+ "the projection cannot be checked, and reading its meters as degrees is silent"}`);
53
57
  }
54
58
  if (code !== options.expectEPSG) {
55
59
  throw new Error(`${options.context}: ${subject} declares EPSG:${code}, expected EPSG:${options.expectEPSG} — ${options.messages?.epsgMismatch ??
@@ -58,7 +62,7 @@ export async function readOGRLayerIdentity(options) {
58
62
  if (typeof described.featureCount !== "number") {
59
63
  throw new TypeError(`${options.context}: ${subject} reports no feature count`);
60
64
  }
61
- let extent;
65
+ let extent = null;
62
66
  if (geometry?.extent && geometry.extent.length >= EXTENT_ORDINATES) {
63
67
  extent = [geometry.extent[0], geometry.extent[1], geometry.extent[2], geometry.extent[3]];
64
68
  }
@@ -67,7 +71,7 @@ export async function readOGRLayerIdentity(options) {
67
71
  }
68
72
  await assertDatumTransformationAvailable(code, {
69
73
  context: options.context,
70
- ...(options.areaOfUse === undefined ? {} : { areaOfUse: options.areaOfUse }),
74
+ areaOfUse: options.areaOfUse ?? null,
71
75
  });
72
76
  const fields = new Set((described.fields ?? []).map((field) => field.name).filter((name) => name !== undefined));
73
77
  if (options.requireFields && !fields.size) {
@@ -78,7 +82,7 @@ export async function readOGRLayerIdentity(options) {
78
82
  featureCount: described.featureCount,
79
83
  layer: described.name,
80
84
  fields,
81
- ...(extent === undefined ? {} : { extent }),
85
+ extent,
82
86
  };
83
87
  }
84
- //# sourceMappingURL=index.js.map
88
+ //# sourceMappingURL=ogr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ogr.js","sourceRoot":"","sources":["../../tools/ogr.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACrE,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAA;AAEjD,OAAO,EAAE,kCAAkC,EAAE,MAAM,uBAAuB,CAAA;AA+E1E;;;GAGG;AACH,MAAM,kBAAkB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAA;AAE3C;;;;;GAKG;AACH,MAAM,gBAAgB,GAAG,CAAC,CAAA;AAE1B;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,OAAoC;IAC9E,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,OAAO,CAC/B,SAAS,EACT,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EACzE,EAAE,SAAS,EAAE,kBAAkB,EAAE,CACjC,CAAA;IAED,MAAM,IAAI,GAAG,eAAe,CAUzB,MAAM,CAAC,CAAA;IAEV,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAA;IAElC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,CAAC;QACtB,MAAM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