@@ -57,8 +57,7 @@ function addCentroidsToGeojson(geojsonPath) {
57
57
}
58
58
59
59
async function createLandLayer ( { bounds, name, resolution, source } ) {
60
- // TODO: Figure out way to only include North and Central America via filter, dissolve
61
- const inputFilePath = `${ outputDirGeojson } /${ unFilename } _${ resolution } m/${ source } .geojson` ;
60
+ const inputFilePath = `${ outputDirGeojson } /${ name } _${ resolution } m/countries.geojson` ;
62
61
const outputFilePath = `${ outputDirGeojson } /${ name } _${ resolution } m/land.geojson` ;
63
62
const commands = [
64
63
inputFilePath ,
@@ -216,54 +215,29 @@ async function convertLayersToTopojson({ name, resolution }) {
216
215
217
216
// Get polygon features from UN GeoJSON and patch Antarctica gap
218
217
const inputFilePathUNGeojson = `${ inputDir } /${ unFilename } .geojson` ;
219
- const inputFilePathAntarcticaPatch = './tasks/topojson/antarctica_patch.geojson' ;
220
- const outputFilePath50m = `${ outputDirGeojson } /${ unFilename } _50m/all_features.geojson` ;
221
- const outputPath110m = `${ outputDirGeojson } /${ unFilename } _110m` ;
222
- // const commandsAllFeatures = [
223
- // inputFilePathUNGeojson,
224
- // // inputFilePathAntarcticaPatch,
225
- // // 'combine-files',
226
- // `-filter 'iso3cd === "ATA"' target=1 + name=antarctica`,
227
- // // '-merge-layers target=antarctica,antarctica_patch force',
228
- // '-clean snap-interval=0.015 target=antarctica',
229
- // // '-dissolve2 target=antarctica copy-fields=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',
230
- // // '-dissolve2 target=antarctica',
231
- // `-filter 'georeg !== "ANT"' target=1`,
232
- // '-merge-layers target=1,antarctica force name=all_features',
233
- // `-o target=1 ${outputFilePath50m}`
234
- // ].join(" ")
235
218
const commandsAllFeaturesCommon = [
236
219
inputFilePathUNGeojson ,
237
220
`-filter 'iso3cd === "ATA"' target=1 + name=antarctica` ,
221
+ // Use 'snap-interval' to patch gap in Antarctica
238
222
'-clean snap-interval=0.015 target=antarctica' ,
223
+ // Add rectangle to extend Antarctica to bottom of world
239
224
'-rectangle bbox=-180,-90,180,-89 name=antarctica_rectangle' ,
240
225
'-merge-layers target=antarctica,antarctica_rectangle force' ,
241
226
'-dissolve2 target=antarctica copy-fields=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' ,
227
+ // Remove unpatched Antarctica
242
228
`-filter 'georeg !== "ANT"' target=1` ,
229
+ // Merge patched Antarctica
243
230
'-merge-layers target=1,antarctica force name=all_features' ,
244
231
]
232
+
233
+ // Process 50m UN geodata
234
+ const outputFilePath50m = `${ outputDirGeojson } /${ unFilename } _50m/all_features.geojson` ;
245
235
const commandsAllFeatures50m = [
246
236
...commandsAllFeaturesCommon ,
247
237
`-o target=1 ${ outputFilePath50m } `
248
238
] . join ( " " )
249
239
await mapshaper . runCommands ( commandsAllFeatures50m ) ;
250
240
251
- // const geojson = getJsonFile(outputFilePath50m);
252
- // const simplifiedGeojson = {
253
- // ...geojson,
254
- // features: geojson.features.map((f) => simplify(f, { tolerance: 0.1, highQuality: true }))
255
- // };
256
- // if (!fs.existsSync(outputPath110m)) fs.mkdirSync(outputPath110m, { recursive: true });
257
- // fs.writeFileSync(`${outputPath110m}/all_features.geojson`, JSON.stringify(simplifiedGeojson));
258
-
259
- // const commandsAllFeatures110m = [
260
- // outputFilePath50m,
261
- // '-simplify 7% rdp',
262
- // `-o ${outputFilePath110m}`
263
- // ].join(" ")
264
- // await mapshaper.runCommands(commandsAllFeatures110m);
265
-
266
- // Process 50m UN geodata
267
241
// Get countries from all polygon features
268
242
const inputFilePathCountries50m = outputFilePath50m ;
269
243
const outputFilePathCountries50m = `${ outputDirGeojson } /${ unFilename } _50m/countries.geojson` ;
@@ -276,7 +250,7 @@ const commandsCountries50m = [
276
250
await mapshaper . runCommands ( commandsCountries50m ) ;
277
251
278
252
// Get land from all polygon features
279
- const inputFilePathLand50m = outputFilePath50m ;
253
+ const inputFilePathLand50m = outputFilePathCountries50m ;
280
254
const outputFilePathLand50m = `${ outputDirGeojson } /${ unFilename } _50m/land.geojson` ;
281
255
const commandsLand50m = [
282
256
inputFilePathLand50m ,
@@ -300,6 +274,7 @@ const outputFilePathCountries110m = `${outputDirGeojson}/${unFilename}_110m/coun
300
274
const commandsCountries110m = [
301
275
inputFilePathCountries110m ,
302
276
`-filter '${ filters . countries } '` ,
277
+ // Use 'snap-interval' to fix alignment issues with USA and Alaska, Mexico
303
278
'-clean snap-interval=0.015' ,
304
279
`-o ${ outputFilePathCountries110m } `
305
280
] . join ( ' ' ) ;
@@ -319,23 +294,6 @@ for (const resolution of resolutions) {
319
294
for ( const { source } of Object . values ( vectors ) ) {
320
295
await convertShpToGeo ( getNEFilename ( { resolution, source } ) ) ;
321
296
}
322
-
323
- // // Get countries from all polygon features
324
- // const inputFilePathCountries = `${outputDirGeojson}/${unFilename}_${resolution}m/all_features.geojson`;
325
- // const outputFilePathCountries = `${outputDirGeojson}/${unFilename}_${resolution}m/countries.geojson`;
326
- // const commandsCountries = [
327
- // inputFilePathCountries,
328
- // `-filter '${filters.countries}'`,
329
- // `-o ${outputFilePathCountries}`
330
- // ].join(' ');
331
- // await mapshaper.runCommands(commandsCountries);
332
-
333
- // // Get land from all polygon features
334
- // const inputFilePathLand = outputFilePathCountries;
335
- // // const inputFilePathLand = `${outputDirGeojson}/${unFilename}_${resolution}m/all_features.geojson`;
336
- // const outputFilePathLand = `${outputDirGeojson}/${unFilename}_${resolution}m/land.geojson`;
337
- // const commandsLand = [inputFilePathLand, '-dissolve2', `-clean -o ${outputFilePathLand}`].join(' ');
338
- // await mapshaper.runCommands(commandsLand);
339
297
}
340
298
341
299
for ( const resolution of resolutions ) {
0 commit comments