diff --git a/src/create-contour/contour.js b/src/create-contour/contour.js index fc6ed1f..8f28fef 100644 --- a/src/create-contour/contour.js +++ b/src/create-contour/contour.js @@ -26,21 +26,21 @@ const execShellCommand = (cmd) => { * Relies on GRASS * * @param {String} inputPath The path of the GeoTIFF to convert - * @param {String} fileName The name of the GeoTIFF + * @param {String} datasetTimestamp The timestamp of the GeoTIFF * @param {String} interval Elevation interval between contours * * @returns {Promise} A Promise that resolves to the console output of the underlying GDAL process * * @throws If provided paths are invalid or conversion fails, an error is thrown */ -const createContourLines = async (inputPath, interval) => { +const createContourLines = async (inputPath, datasetTimestamp, interval) => { // valdate inputPath if (! await fs.existsSync(inputPath)) { throw `Input file does not exist: ${inputPath}/`; } // build command for sub-process - const contourCmd = `gdal_contour -b 2 -a TEMP -i ${interval} -f "GeoJSON" /${inputPath} /tmp/output.geojson`; + const contourCmd = `gdal_contour -b 2 -a TEMP -i ${interval} -f "GeoJSON" /${inputPath} /tmp/output${datasetTimestamp}.geojson`; return await execShellCommand(contourCmd); } diff --git a/src/create-contour/index.js b/src/create-contour/index.js index 66468d2..c8f8143 100644 --- a/src/create-contour/index.js +++ b/src/create-contour/index.js @@ -23,15 +23,6 @@ const contourLinesWorker = async (workerJob, inputs) => { const inputPath = inputs[0]; const interval = inputs[2]; - await createContourLines(inputPath, interval); - - // array aus multiLines als geoJSON - // todo check if it needs a relative path - const contourLines = fetch("/tmp/output.geojson") - .then((response) => response.json()) - .then(data => { return (data) }) - - // get region and timestamp from input (example format: langenfeld_20230629T0500Z.tif) const regex = /^([^_]+)_(\d{8}T\d{4}Z)/; const matches = inputs[1].match(regex); @@ -48,11 +39,13 @@ const contourLinesWorker = async (workerJob, inputs) => { // get timestamp for current hour //const currentTimestamp = dayjs.utc().startOf('hour'); - if (datasetTimestamp) { - // timestamp of dataset not valid - logger.info('Could not parse dataset timestamp.'); - throw 'Could not parse dataset timestamp.'; - } + await createContourLines(inputPath, datasetTimestamp, interval); + + // array aus multiLines als geoJSON + // todo check if it needs a relative path + const contourLines = fetch(`/tmp/output${datasetTimestamp}.geojson`) + .then((response) => response.json()) + .then(data => { return (data) }); // Create table // TODO check if this can be moved to seperate file