Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f4c3d48

Browse filesBrowse files
committed
Fix zip/unzip of UN geojson
1 parent ac61095 commit f4c3d48
Copy full SHA for f4c3d48

File tree

Expand file treeCollapse file tree

3 files changed

+27
-14
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+27
-14
lines changed

‎tasks/topojson/config.mjs

Copy file name to clipboardExpand all lines: tasks/topojson/config.mjs
+16-4Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,22 @@ const config = {
7070
inputDir: './build/geodata',
7171
vectors: {
7272
// 'coastlines', 'countries', and 'land' are derived from UN geodata
73-
ocean: 'ocean',
74-
lakes: 'lakes',
75-
rivers: 'rivers_lake_centerlines',
76-
subunits: 'admin_1_states_provinces_lakes'
73+
ocean: {
74+
source: 'ocean',
75+
type: 'physical'
76+
},
77+
lakes: {
78+
source: 'lakes',
79+
type: 'physical'
80+
},
81+
rivers: {
82+
source: 'rivers_lake_centerlines',
83+
type: 'physical'
84+
},
85+
subunits: {
86+
source: 'admin_1_states_provinces_lakes',
87+
type: 'cultural'
88+
}
7789
},
7890
layers: {
7991
coastlines: 'land',

‎tasks/topojson/get_geodata.mjs

Copy file name to clipboardExpand all lines: tasks/topojson/get_geodata.mjs
+10-9Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ const tasksPath = './tasks/topojson';
1010
const outputPath = './build/geodata';
1111

1212
// Download Natural Earth vectors
13-
for (const [vector, source] of Object.entries(vectors)) {
13+
for (const vector of Object.values(vectors)) {
1414
for (const resolution of resolutions) {
1515
const url = getNEDownloadUrl({ resolution, vector });
16-
const filename = getNEFilename({ resolution, source });
16+
const filename = getNEFilename({ resolution, source: vector.source });
1717
const archivePath = `${outputPath}/${filename}.zip`;
1818

1919
if (fs.existsSync(archivePath)) {
@@ -46,11 +46,12 @@ for (const [vector, source] of Object.entries(vectors)) {
4646
// Download UN GeoJSON file
4747
const url = unDownloadUrl;
4848
const archivePath = `${tasksPath}/${unFilename}.zip`;
49-
const geojsonPath = `${outputPath}/${unFilename}.geojson`;
49+
const geojsonPath = `${outputPath}`;
50+
const geojsonFilePath = `${geojsonPath}/${unFilename}.geojson`;
5051

5152
if (fs.existsSync(archivePath)) {
5253
console.log(`File ${archivePath} already exists. Skipping download.`);
53-
if (fs.existsSync(geojsonPath)) console.log(`File ${geojsonPath} already exists. Skipping decompression.`);
54+
if (fs.existsSync(geojsonFilePath)) console.log(`File ${geojsonFilePath} already exists. Skipping decompression.`);
5455
else exec(`unzip -o ${archivePath} -d ${geojsonPath}`);
5556
} else {
5657
try {
@@ -59,17 +60,17 @@ if (fs.existsSync(archivePath)) {
5960
const response = await fetch(url);
6061
if (!response.ok || !response.body) throw new Error(`Bad response: ${response.status}`);
6162

62-
if (!fs.existsSync(outputPath)) fs.mkdirSync(outputPath, { recursive: true });
63-
const file = fs.createWriteStream(geojsonPath);
63+
// if (!fs.existsSync(outputPath)) fs.mkdirSync(outputPath, { recursive: true });
64+
const file = fs.createWriteStream(geojsonFilePath);
6465
await pipeline(Readable.fromWeb(response.body), file);
65-
console.log(`UN GeoJSON file saved to ${geojsonPath}`);
66+
console.log(`UN GeoJSON file saved to ${geojsonFilePath}`);
6667

6768
console.log('Compressing UN GeoJSON for future use');
6869
// Use the shell to handle compression
69-
exec(`zip ${archivePath} ${geojsonPath}`);
70+
exec(`zip -j ${archivePath} ${geojsonFilePath}`);
7071

7172
console.log(`UN GeoJSON archive saved to ${archivePath}`);
7273
} catch (error) {
73-
console.error(`Error when downloading file '${geojsonPath}': ${error}`);
74+
console.error(`Error when downloading file '${geojsonFilePath}': ${error}`);
7475
}
7576
}

‎tasks/topojson/process_geodata.mjs

Copy file name to clipboardExpand all lines: tasks/topojson/process_geodata.mjs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ const simplifiedGeojson = {
243243
fs.writeFileSync(`${outputDirGeojson}/${unFilename}_110m/all_features.geojson`, JSON.stringify(simplifiedGeojson));
244244

245245
for (const resolution of resolutions) {
246-
for (const source of Object.values(vectors)) {
246+
for (const { source } of Object.values(vectors)) {
247247
await convertShpToGeo(getNEFilename({ resolution, source }));
248248
}
249249

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.