Skip to content

Commit

Permalink
make filename unique
Browse files Browse the repository at this point in the history
  • Loading branch information
sdobbert authored and sdobbert committed Feb 20, 2024
1 parent 117b681 commit 4721534
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/create-contour/contour.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>} 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);
}
Expand Down
21 changes: 7 additions & 14 deletions src/create-contour/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit 4721534

Please sign in to comment.