From a6b4f23f6a0342c25d1ce6827579791b4a4646f7 Mon Sep 17 00:00:00 2001 From: Chad Burt Date: Tue, 8 Oct 2024 11:00:59 -0700 Subject: [PATCH] Show more helpful error messages when uploaded shapefile is missing necessary parts (like .prj) --- .../src/geostatsForVectorLayer.ts | 3 ++ .../src/handleUpload.ts | 9 ------ .../src/processVectorUpload.ts | 30 +++++++++++++++++++ 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/packages/spatial-uploads-handler/src/geostatsForVectorLayer.ts b/packages/spatial-uploads-handler/src/geostatsForVectorLayer.ts index 0ab1acf5..a7249019 100644 --- a/packages/spatial-uploads-handler/src/geostatsForVectorLayer.ts +++ b/packages/spatial-uploads-handler/src/geostatsForVectorLayer.ts @@ -68,6 +68,9 @@ export async function geostatsForVectorLayers( hasZ: false, } as GeostatsLayer; const dataset = await gdal.openAsync(filepath); + if (dataset.srs === null) { + throw new Error("No spatial reference system found in dataset."); + } dataset.layers.forEach((lyr, lidx) => { const extent = lyr.getExtent(); if (extent) { diff --git a/packages/spatial-uploads-handler/src/handleUpload.ts b/packages/spatial-uploads-handler/src/handleUpload.ts index 118b803c..854e5ac9 100644 --- a/packages/spatial-uploads-handler/src/handleUpload.ts +++ b/packages/spatial-uploads-handler/src/handleUpload.ts @@ -232,7 +232,6 @@ export default async function handleUpload( } } if (!sourceUrl) { - console.log(outputs); throw new Error("No sourceUrl found"); } @@ -242,14 +241,6 @@ export default async function handleUpload( await putObject(logPath, s3LogPath, logger); const geostats = Array.isArray(stats) ? stats[0] : stats; - console.log( - "buliding response", - outputs.map((o) => ({ - ...o, - local: undefined, - filename: o.filename, - })) - ); const response: { layers: ProcessedUploadLayer[]; logfile: string } = { layers: [ { diff --git a/packages/spatial-uploads-handler/src/processVectorUpload.ts b/packages/spatial-uploads-handler/src/processVectorUpload.ts index 2b7ef7a7..473de8e3 100644 --- a/packages/spatial-uploads-handler/src/processVectorUpload.ts +++ b/packages/spatial-uploads-handler/src/processVectorUpload.ts @@ -94,6 +94,36 @@ export async function processVectorUpload(options: { "Problem finding shapefile in zip archive", 1 / 30 ); + + // Make sure there is also a .prj projection file + const projFile = await logger.exec( + [ + "find", + [ + workingDirectory, + "-type", + "f", + "-not", + "-path", + "*/.*", + "-not", + "-path", + "*/__", + "-name", + "*.prj", + ], + ], + "Problem finding projection file (.prj) in zip archive", + 1 / 30 + ); + + if (!projFile) { + throw new Error("No projection file found (.prj) in zip archive"); + } + if (!shapefile) { + throw new Error("No shape-file (.shp) found in zip archive"); + } + // Consider that there may be multiple shapefiles in the zip archive // and choose the first one workingFilePath = shapefile.split("\n")[0].trim();