// SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial /** * One chunk of the soil ingest as its own process, spawned by `buildSoilDatabase` and never run by hand. */ import { requiredArgument } from "@mailwoman/core/scripting/arguments" import { INGEST_CHUNK_FLAGS, runIngestChunkScript } from "@mailwoman/core/scripting/ingest-chunk-script" import type { DatabaseClient } from "@mailwoman/sqlite/client" import type { SoilDatabase } from "#schema" import { createShapefileFeatureSource } from "#sdk/ingest" import { ingestSoilChunk } from "#sdk/ingest/chunk" await runIngestChunkScript({ context: "soil ingest-chunk", options: { ...INGEST_CHUNK_FLAGS, shapefile: { type: "string" }, "area-symbol": { type: "string" }, "fid-from": { type: "string" }, "fid-to": { type: "string" }, "no-mapping-mukeys": { type: "string" }, }, run: async (database: DatabaseClient, values, chunk) => ingestSoilChunk(database, { source: await createShapefileFeatureSource({ shapefilePath: requiredArgument("soil ingest-chunk", "shapefile", values.shapefile ?? null), areaSymbol: requiredArgument("soil ingest-chunk", "area-symbol", values["area-symbol"] ?? null), fidFrom: Number(requiredArgument("soil ingest-chunk", "fid-from", values["fid-from"] ?? null)), fidTo: Number(requiredArgument("soil ingest-chunk", "fid-to", values["fid-to"] ?? null)), // A range's own count isn't knowable up front — `ogrinfo` reports the layer's total // and no narrower count — so the chunk makes no assertion about its size // and the parent checks the per-area sum against the shapefile's. declaredFeatureCount: 0, }), indexResolution: chunk.indexResolution, coverageResolution: chunk.coverageResolution, // An empty string is an empty set rather than "every map unit": a build // where every map unit has soil mapping passes one. // `"".split(",")` yields one empty element that has to be dropped // rather than joined against as a mukey. noMappingMukeys: new Set((values["no-mapping-mukeys"] ?? "").split(",").filter((mukey) => mukey.length)), onProgress: chunk.onProgress, }), })