Skip to content

Commit a6efc84

Browse files
committed
Fix linting/formatting of new JS files
1 parent 3a7bd66 commit a6efc84

File tree

2 files changed

+41
-46
lines changed

2 files changed

+41
-46
lines changed

tasks/topojson/get_geodata.mjs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ for (const vector of Object.values(vectors)) {
2727
// Use the shell to handle decompressing
2828
if (!fs.existsSync(outputPath)) fs.mkdirSync(outputPath, { recursive: true });
2929
exec(`unzip -o ${archivePath} -d ${outputPath}`);
30-
3130
} catch (error) {
3231
console.error(`Error when downloading file '${archivePath}': ${error}`);
3332
continue;
@@ -54,7 +53,6 @@ if (fs.existsSync(archivePath)) {
5453

5554
// Use the shell to handle compression
5655
exec(`zip -j ${archivePath} ${geojsonFilePath}`);
57-
5856
} catch (error) {
5957
console.error(`Error when downloading file '${geojsonFilePath}': ${error}`);
6058
}

tasks/topojson/process_geodata.mjs

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import rewind from '@mapbox/geojson-rewind'
1+
import rewind from '@mapbox/geojson-rewind';
22
import { geoIdentity, geoPath } from 'd3-geo';
3-
import { geoStitch } from "d3-geo-projection"
3+
import { geoStitch } from 'd3-geo-projection';
44
import fs from 'fs';
55
import mapshaper from 'mapshaper';
66
import path from 'path';
7-
import { topology } from 'topojson-server'
7+
import { topology } from 'topojson-server';
88
import config, { getNEFilename } from './config.mjs';
99

1010
const { filters, inputDir, layers, resolutions, scopes, unFilename, vectors } = config;
@@ -46,15 +46,13 @@ function addCentroidsToGeojson(geojsonPath) {
4646
}
4747

4848
// Wind the polygon rings in the correct direction to indicate what is solid and what is whole
49-
const rewindGeojson = (geojson, clockwise = true) => rewind(geojson, clockwise)
49+
const rewindGeojson = (geojson, clockwise = true) => rewind(geojson, clockwise);
5050

5151
// Clamp x-coordinates to the antimeridian
5252
function clampToAntimeridian(inputFilepath, outputFilepath) {
53-
outputFilepath ||= inputFilepath
54-
const jsonString = fs.readFileSync(inputFilepath, 'utf8')
55-
const updatedString = jsonString
56-
.replaceAll(/179\.9999\d+,/g, '180,')
57-
.replaceAll(/180\.0000\d+,/g, '180,')
53+
outputFilepath ||= inputFilepath;
54+
const jsonString = fs.readFileSync(inputFilepath, 'utf8');
55+
const updatedString = jsonString.replaceAll(/179\.9999\d+,/g, '180,').replaceAll(/180\.0000\d+,/g, '180,');
5856

5957
fs.writeFileSync(outputFilepath, updatedString);
6058
}
@@ -165,7 +163,7 @@ async function createCoastlinesLayer({ bounds, name, resolution, source }) {
165163
`-o ${outputFilePath}`
166164
].join(' ');
167165
await mapshaper.runCommands(commands);
168-
clampToAntimeridian(outputFilePath)
166+
clampToAntimeridian(outputFilePath);
169167
}
170168

171169
async function createOceanLayer({ bounds, name, resolution, source }) {
@@ -222,14 +220,14 @@ async function convertLayersToTopojson({ name, resolution }) {
222220

223221
const outputFile = `${outputDirTopojson}/${name}_${resolution}m.json`;
224222
// Scopes with polygons that cross the antimeridian need to be stitched
225-
if (["antarctica", "world"].includes(name)) {
226-
const geojsonObjects = {}
223+
if (['antarctica', 'world'].includes(name)) {
224+
const geojsonObjects = {};
227225
for (const layer of Object.keys(config.layers)) {
228-
const filePath = path.join(regionDir, `${layer}.geojson`)
229-
geojsonObjects[layer] = geoStitch(rewindGeojson(getJsonFile(filePath)))
226+
const filePath = path.join(regionDir, `${layer}.geojson`);
227+
geojsonObjects[layer] = geoStitch(rewindGeojson(getJsonFile(filePath)));
230228
}
231229
// Convert geojson to topojson
232-
const topojsonTopology = topology(geojsonObjects, 1000000)
230+
const topojsonTopology = topology(geojsonObjects, 1000000);
233231
fs.writeFileSync(outputFile, JSON.stringify(topojsonTopology));
234232
} else {
235233
// In Mapshaper, layer names default to file names
@@ -251,13 +249,16 @@ const outputFilePathFiji50m = `${outputDirGeojson}/${unFilename}_50m/fiji.geojso
251249
const outputFilePathFijiAntimeridian50m = `${outputDirGeojson}/${unFilename}_50m/fiji_antimeridian.geojson`;
252250
const outputFilePathRussia50m = `${outputDirGeojson}/${unFilename}_50m/russia.geojson`;
253251
const outputFilePathRussiaAntimeridian50m = `${outputDirGeojson}/${unFilename}_50m/russia_antimeridian.geojson`;
254-
const copyFieldsList = "objectid,iso3cd,m49_cd,nam_en,lbl_en,georeg,geo_cd,sub_cd,int_cd,subreg,intreg,iso2cd,lbl_fr,name_fr,globalid,stscod,isoclr,ct,FID"
252+
const copyFieldsList =
253+
'objectid,iso3cd,m49_cd,nam_en,lbl_en,georeg,geo_cd,sub_cd,int_cd,subreg,intreg,iso2cd,lbl_fr,name_fr,globalid,stscod,isoclr,ct,FID';
255254
// The following fix up code is necessary to isolate/join/cut the polygons that cross the antimeridian.
256255
// This is necessary for two reasons: the UN geojson is poor around the antimeridian and Mapshaper
257256
// doesn't handle antimeridian cutting.
258257

259258
// Fix up Antarctica polygons
260-
await mapshaper.runCommands(`${inputFilePathUNGeojson} -filter 'iso3cd === "ATA"' target=1 -o ${outputFilePathAntarctica50m}`)
259+
await mapshaper.runCommands(
260+
`${inputFilePathUNGeojson} -filter 'iso3cd === "ATA"' target=1 -o ${outputFilePathAntarctica50m}`
261+
);
261262
const commandsAntarctica = [
262263
outputFilePathAntarctica50m,
263264
// Use 'snap-interval' to patch gap in Antarctica
@@ -267,19 +268,21 @@ const commandsAntarctica = [
267268
'-merge-layers target=antarctica,antarctica_rectangle force',
268269
`-dissolve2 target=antarctica copy-fields=${copyFieldsList}`,
269270
`-o force target=antarctica ${outputFilePathAntarctica50m}`
270-
].join(" ")
271-
await mapshaper.runCommands(commandsAntarctica)
271+
].join(' ');
272+
await mapshaper.runCommands(commandsAntarctica);
272273

273274
// Fix up Fiji polygons
274-
await mapshaper.runCommands(`${inputFilePathUNGeojson} -filter 'iso3cd === "FJI"' target=1 -o ${outputFilePathFiji50m}`)
275+
await mapshaper.runCommands(
276+
`${inputFilePathUNGeojson} -filter 'iso3cd === "FJI"' target=1 -o ${outputFilePathFiji50m}`
277+
);
275278
const commandsIsolateFijiAntimeridian = [
276279
outputFilePathFiji50m,
277280
'-explode',
278281
`-each 'id = this.id'`,
279282
`-filter '[31, 36, 39, 40].includes(id)' target=fiji + name=fiji_antimeridian`,
280283
`-o target=fiji_antimeridian ${outputFilePathFijiAntimeridian50m}`
281-
].join(" ")
282-
await mapshaper.runCommands(commandsIsolateFijiAntimeridian)
284+
].join(' ');
285+
await mapshaper.runCommands(commandsIsolateFijiAntimeridian);
283286

284287
const commandsFixFijiAntimeridian = [
285288
outputFilePathFijiAntimeridian50m,
@@ -293,8 +296,8 @@ const commandsFixFijiAntimeridian = [
293296
`-dissolve2 target=complete copy-fields=${copyFieldsList}`,
294297
'-proj wgs84',
295298
`-o force target=complete ${outputFilePathFijiAntimeridian50m}`
296-
].join(" ")
297-
await mapshaper.runCommands(commandsFixFijiAntimeridian)
299+
].join(' ');
300+
await mapshaper.runCommands(commandsFixFijiAntimeridian);
298301

299302
const commandsFiji = [
300303
`-i combine-files ${outputFilePathFiji50m} ${outputFilePathFijiAntimeridian50m}`,
@@ -304,19 +307,21 @@ const commandsFiji = [
304307
'-merge-layers target=fiji,fiji_antimeridian force name=fiji',
305308
`-dissolve2 target=fiji copy-fields=${copyFieldsList}`,
306309
`-o force target=fiji ${outputFilePathFiji50m}`
307-
].join(" ")
308-
await mapshaper.runCommands(commandsFiji)
310+
].join(' ');
311+
await mapshaper.runCommands(commandsFiji);
309312

310313
// Fix up Russia polygons
311-
await mapshaper.runCommands(`${inputFilePathUNGeojson} -filter 'iso3cd === "RUS"' target=1 -o ${outputFilePathRussia50m}`)
314+
await mapshaper.runCommands(
315+
`${inputFilePathUNGeojson} -filter 'iso3cd === "RUS"' target=1 -o ${outputFilePathRussia50m}`
316+
);
312317
const commandsIsolateRussiaAntimeridian = [
313318
outputFilePathRussia50m,
314319
'-explode',
315320
`-each 'id = this.id'`,
316321
`-filter '[13, 15].includes(id)' target=russia + name=russia_antimeridian`,
317322
`-o target=russia_antimeridian ${outputFilePathRussiaAntimeridian50m}`
318-
].join(" ")
319-
await mapshaper.runCommands(commandsIsolateRussiaAntimeridian)
323+
].join(' ');
324+
await mapshaper.runCommands(commandsIsolateRussiaAntimeridian);
320325

321326
const commandsFixRussiaAntimeridian = [
322327
outputFilePathRussiaAntimeridian50m,
@@ -330,8 +335,8 @@ const commandsFixRussiaAntimeridian = [
330335
`-dissolve2 target=complete copy-fields=${copyFieldsList}`,
331336
'-proj wgs84',
332337
`-o force target=complete ${outputFilePathRussiaAntimeridian50m}`
333-
].join(" ")
334-
await mapshaper.runCommands(commandsFixRussiaAntimeridian)
338+
].join(' ');
339+
await mapshaper.runCommands(commandsFixRussiaAntimeridian);
335340

336341
const commandsRussia = [
337342
`-i combine-files ${outputFilePathRussia50m} ${outputFilePathRussiaAntimeridian50m}`,
@@ -341,8 +346,8 @@ const commandsRussia = [
341346
'-merge-layers target=russia,russia_antimeridian force name=russia',
342347
`-dissolve2 target=russia copy-fields=${copyFieldsList}`,
343348
`-o force target=russia ${outputFilePathRussia50m}`
344-
].join(" ")
345-
await mapshaper.runCommands(commandsRussia)
349+
].join(' ');
350+
await mapshaper.runCommands(commandsRussia);
346351

347352
// Process 50m UN geodata
348353

@@ -366,16 +371,12 @@ const commandsCountries50m = [
366371
`-o ${outputFilePathCountries50m}`
367372
].join(' ');
368373
await mapshaper.runCommands(commandsCountries50m);
369-
clampToAntimeridian(outputFilePathCountries50m)
374+
clampToAntimeridian(outputFilePathCountries50m);
370375

371376
// Get land from all polygon features
372377
const inputFilePathLand50m = outputFilePathCountries50m;
373378
const outputFilePathLand50m = `${outputDirGeojson}/${unFilename}_50m/land.geojson`;
374-
const commandsLand50m = [
375-
inputFilePathLand50m,
376-
'-dissolve2',
377-
`-o ${outputFilePathLand50m}`
378-
].join(' ');
379+
const commandsLand50m = [inputFilePathLand50m, '-dissolve2', `-o ${outputFilePathLand50m}`].join(' ');
379380
await mapshaper.runCommands(commandsLand50m);
380381

381382
// Process 110m UN geodata
@@ -395,11 +396,7 @@ await mapshaper.runCommands(commandsCountries110m);
395396
// Get land from all polygon features
396397
const inputFilePathLand110m = outputFilePathCountries110m;
397398
const outputFilePathLand110m = `${outputDirGeojson}/${unFilename}_110m/land.geojson`;
398-
const commandsLand110m = [
399-
inputFilePathLand110m,
400-
'-dissolve2',
401-
`-o ${outputFilePathLand110m}`
402-
].join(' ');
399+
const commandsLand110m = [inputFilePathLand110m, '-dissolve2', `-o ${outputFilePathLand110m}`].join(' ');
403400
await mapshaper.runCommands(commandsLand110m);
404401

405402
for (const resolution of resolutions) {

0 commit comments

Comments
 (0)