Skip to content

Commit a6b4f23

Browse files
Show more helpful error messages when uploaded shapefile is missing necessary parts (like .prj)
1 parent 3fe885e commit a6b4f23

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

packages/spatial-uploads-handler/src/geostatsForVectorLayer.ts

+3
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ export async function geostatsForVectorLayers(
6868
hasZ: false,
6969
} as GeostatsLayer;
7070
const dataset = await gdal.openAsync(filepath);
71+
if (dataset.srs === null) {
72+
throw new Error("No spatial reference system found in dataset.");
73+
}
7174
dataset.layers.forEach((lyr, lidx) => {
7275
const extent = lyr.getExtent();
7376
if (extent) {

packages/spatial-uploads-handler/src/handleUpload.ts

-9
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ export default async function handleUpload(
232232
}
233233
}
234234
if (!sourceUrl) {
235-
console.log(outputs);
236235
throw new Error("No sourceUrl found");
237236
}
238237

@@ -242,14 +241,6 @@ export default async function handleUpload(
242241
await putObject(logPath, s3LogPath, logger);
243242
const geostats = Array.isArray(stats) ? stats[0] : stats;
244243

245-
console.log(
246-
"buliding response",
247-
outputs.map((o) => ({
248-
...o,
249-
local: undefined,
250-
filename: o.filename,
251-
}))
252-
);
253244
const response: { layers: ProcessedUploadLayer[]; logfile: string } = {
254245
layers: [
255246
{

packages/spatial-uploads-handler/src/processVectorUpload.ts

+30
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,36 @@ export async function processVectorUpload(options: {
9494
"Problem finding shapefile in zip archive",
9595
1 / 30
9696
);
97+
98+
// Make sure there is also a .prj projection file
99+
const projFile = await logger.exec(
100+
[
101+
"find",
102+
[
103+
workingDirectory,
104+
"-type",
105+
"f",
106+
"-not",
107+
"-path",
108+
"*/.*",
109+
"-not",
110+
"-path",
111+
"*/__",
112+
"-name",
113+
"*.prj",
114+
],
115+
],
116+
"Problem finding projection file (.prj) in zip archive",
117+
1 / 30
118+
);
119+
120+
if (!projFile) {
121+
throw new Error("No projection file found (.prj) in zip archive");
122+
}
123+
if (!shapefile) {
124+
throw new Error("No shape-file (.shp) found in zip archive");
125+
}
126+
97127
// Consider that there may be multiple shapefiles in the zip archive
98128
// and choose the first one
99129
workingFilePath = shapefile.split("\n")[0].trim();

0 commit comments

Comments
 (0)