Skip to content

Commit

Permalink
Show more helpful error messages when uploaded shapefile is missing n…
Browse files Browse the repository at this point in the history
…ecessary parts (like .prj)
  • Loading branch information
underbluewaters committed Oct 8, 2024
1 parent 3fe885e commit a6b4f23
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 0 additions & 9 deletions packages/spatial-uploads-handler/src/handleUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ export default async function handleUpload(
}
}
if (!sourceUrl) {
console.log(outputs);
throw new Error("No sourceUrl found");
}

Expand All @@ -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: [
{
Expand Down
30 changes: 30 additions & 0 deletions packages/spatial-uploads-handler/src/processVectorUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit a6b4f23

Please sign in to comment.