Skip to content

Commit e74c65c

Browse files
committed
Remove log statements
1 parent b903b9f commit e74c65c

File tree

2 files changed

+4
-33
lines changed

2 files changed

+4
-33
lines changed

tasks/topojson/get_geodata.mjs

+3-17
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,26 @@ const { resolutions, unDownloadUrl, unFilename, vectors } = config;
99
const tasksPath = './tasks/topojson';
1010
const outputPath = './build/geodata';
1111

12-
// Download Natural Earth vectors
12+
// Download Natural Earth vector maps
1313
for (const vector of Object.values(vectors)) {
1414
for (const resolution of resolutions) {
1515
const url = getNEDownloadUrl({ resolution, vector });
1616
const filename = getNEFilename({ resolution, source: vector.source });
1717
const archivePath = `${outputPath}/${filename}.zip`;
1818

19-
if (fs.existsSync(archivePath)) {
20-
console.log(`File ${archivePath} already exists. Skipping download.`);
21-
} else {
19+
if (!fs.existsSync(archivePath)) {
2220
try {
23-
console.log(`Downloading data from ${url}`);
24-
2521
const response = await fetch(url);
2622
if (!response.ok || !response.body) throw new Error(`Bad response: ${response.status}`);
2723

2824
if (!fs.existsSync(outputPath)) fs.mkdirSync(outputPath, { recursive: true });
2925
const file = fs.createWriteStream(archivePath);
3026
await pipeline(Readable.fromWeb(response.body), file);
3127

32-
console.log('Decompressing NE shapefile');
3328
// Use the shell to handle decompressing
3429
if (!fs.existsSync(outputPath)) fs.mkdirSync(outputPath, { recursive: true });
3530
exec(`unzip -o ${archivePath} -d ${outputPath}`);
3631

37-
console.log(`NE Shapefile decompressed to ${outputPath}`);
3832
} catch (error) {
3933
console.error(`Error when downloading file '${archivePath}': ${error}`);
4034
continue;
@@ -50,26 +44,18 @@ const geojsonPath = `${outputPath}`;
5044
const geojsonFilePath = `${geojsonPath}/${unFilename}.geojson`;
5145

5246
if (fs.existsSync(archivePath)) {
53-
console.log(`File ${archivePath} already exists. Skipping download.`);
54-
if (fs.existsSync(geojsonFilePath)) console.log(`File ${geojsonFilePath} already exists. Skipping decompression.`);
55-
else exec(`unzip -o ${archivePath} -d ${geojsonPath}`);
47+
if (!fs.existsSync(geojsonFilePath)) exec(`unzip -o ${archivePath} -d ${geojsonPath}`);
5648
} else {
5749
try {
58-
console.log(`Downloading data from ${url}`);
59-
6050
const response = await fetch(url);
6151
if (!response.ok || !response.body) throw new Error(`Bad response: ${response.status}`);
6252

63-
// if (!fs.existsSync(outputPath)) fs.mkdirSync(outputPath, { recursive: true });
6453
const file = fs.createWriteStream(geojsonFilePath);
6554
await pipeline(Readable.fromWeb(response.body), file);
66-
console.log(`UN GeoJSON file saved to ${geojsonFilePath}`);
6755

68-
console.log('Compressing UN GeoJSON for future use');
6956
// Use the shell to handle compression
7057
exec(`zip -j ${archivePath} ${geojsonFilePath}`);
7158

72-
console.log(`UN GeoJSON archive saved to ${archivePath}`);
7359
} catch (error) {
7460
console.error(`Error when downloading file '${geojsonFilePath}': ${error}`);
7561
}

tasks/topojson/process_geodata.mjs

+1-16
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ async function convertShpToGeo(filename) {
1818
const outputFilePath = `${outputDirGeojson}/${filename}.geojson`;
1919
const commands = [inputFilePath, `-proj wgs84`, `-o format=geojson ${outputFilePath}`].join(' ');
2020
await mapshaper.runCommands(commands);
21-
22-
console.log(`GeoJSON saved to ${outputFilePath}`);
2321
}
2422

2523
function getJsonFile(filename) {
@@ -32,7 +30,6 @@ function getJsonFile(filename) {
3230
}
3331

3432
async function createCountriesLayer({ bounds, filter, name, resolution, source }) {
35-
console.log(`Building ${resolution}m countries layer for '${name}'`);
3633
const inputFilePath = `${outputDirGeojson}/${unFilename}_${resolution}m/${source}.geojson`;
3734
const outputFilePath = `${outputDirGeojson}/${name}_${resolution}m/countries.geojson`;
3835
const commands = [
@@ -43,7 +40,6 @@ async function createCountriesLayer({ bounds, filter, name, resolution, source }
4340
].join(' ');
4441
await mapshaper.runCommands(commands);
4542
addCentroidsToGeojson(outputFilePath);
46-
// TODO: Add simplification command if on 110m resolution? Or take care of somewhere else?
4743
}
4844

4945
function addCentroidsToGeojson(geojsonPath) {
@@ -62,7 +58,6 @@ function addCentroidsToGeojson(geojsonPath) {
6258

6359
async function createLandLayer({ bounds, name, resolution, source }) {
6460
// TODO: Figure out way to only include North and Central America via filter, dissolve
65-
console.log(`Building ${resolution}m land layer for '${name}'`);
6661
const inputFilePath = `${outputDirGeojson}/${unFilename}_${resolution}m/${source}.geojson`;
6762
const outputFilePath = `${outputDirGeojson}/${name}_${resolution}m/land.geojson`;
6863
const commands = [
@@ -75,7 +70,6 @@ async function createLandLayer({ bounds, name, resolution, source }) {
7570
}
7671

7772
async function createCoastlinesLayer({ bounds, name, resolution, source }) {
78-
console.log(`Building ${resolution}m coastlines layer for '${name}'`);
7973
// TODO: Update source to be a path?
8074
const inputFilePath = `${outputDirGeojson}/${unFilename}_${resolution}m/${source}.geojson`;
8175
const outputFilePath = `${outputDirGeojson}/${name}_${resolution}m/coastlines.geojson`;
@@ -90,7 +84,6 @@ async function createCoastlinesLayer({ bounds, name, resolution, source }) {
9084
}
9185

9286
async function createOceanLayer({ bounds, name, resolution, source }) {
93-
console.log(`Building ${resolution}m ocean layer for '${name}'`);
9487
const inputFilePath = `./tasks/topojson/world_rectangle.geojson`;
9588
const outputFilePath = `${outputDirGeojson}/${name}_${resolution}m/ocean.geojson`;
9689
const eraseFilePath = `${outputDirGeojson}/${unFilename}_${resolution}m/${source}.geojson`;
@@ -104,7 +97,6 @@ async function createOceanLayer({ bounds, name, resolution, source }) {
10497
}
10598

10699
async function createRiversLayer({ name, resolution, source }) {
107-
console.log(`Building ${resolution}m rivers layer for '${name}'`);
108100
const inputFilePath = `${outputDirGeojson}/${getNEFilename({ resolution, source })}.geojson`;
109101
const outputFilePath = `${outputDirGeojson}/${name}_${resolution}m/rivers.geojson`;
110102
const commands = [
@@ -116,7 +108,6 @@ async function createRiversLayer({ name, resolution, source }) {
116108
}
117109

118110
async function createLakesLayer({ name, resolution, source }) {
119-
console.log(`Building ${resolution}m lakes layer for '${name}'`);
120111
const inputFilePath = `${outputDirGeojson}/${getNEFilename({ resolution, source })}.geojson`;
121112
const outputFilePath = `${outputDirGeojson}/${name}_${resolution}m/lakes.geojson`;
122113
const commands = [
@@ -128,7 +119,6 @@ async function createLakesLayer({ name, resolution, source }) {
128119
}
129120

130121
async function createSubunitsLayer({ name, resolution, source }) {
131-
console.log(`Building ${resolution}m subunits layer for '${name}'`);
132122
const filter = ['AUS', 'BRA', 'CAN', 'USA'].map((id) => `adm0_a3 === "${id}"`).join(' || ');
133123
const inputFilePath = `${outputDirGeojson}/${getNEFilename({ resolution, source })}.geojson`;
134124
const outputFilePath = `${outputDirGeojson}/${name}_${resolution}m/subunits.geojson`;
@@ -211,10 +201,7 @@ function getCentroid(feature) {
211201

212202
async function convertLayersToTopojson({ name, resolution }) {
213203
const regionDir = path.join(outputDirGeojson, `${name}_${resolution}m`);
214-
if (!fs.existsSync(regionDir)) {
215-
console.log(`Couldn't find ${regionDir}`);
216-
return;
217-
}
204+
if (!fs.existsSync(regionDir)) return;
218205

219206
const outputFile = `${outputDirTopojson}/${name}_${resolution}m.json`;
220207
// Layer names default to file names
@@ -225,8 +212,6 @@ async function convertLayersToTopojson({ name, resolution }) {
225212
const topojson = getJsonFile(outputFile);
226213
const prunedTopojson = pruneProperties(topojson);
227214
fs.writeFileSync(outputFile, JSON.stringify(prunedTopojson));
228-
229-
console.log(`Topojson saved to: ${outputFile}`);
230215
}
231216

232217
// Get polygon features from UN GeoJSON

0 commit comments

Comments
 (0)