Skip to content

Commit d6ea8ab

Browse files
committed
Fix Anarctica geometry and simplification
1 parent b8bfea6 commit d6ea8ab

1 file changed

Lines changed: 115 additions & 28 deletions

File tree

tasks/topojson/process_geodata.mjs

Lines changed: 115 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ async function createCoastlinesLayer({ bounds, name, resolution, source }) {
8484
}
8585

8686
async function createOceanLayer({ bounds, name, resolution, source }) {
87-
const inputFilePath = `./tasks/topojson/world_rectangle.geojson`;
87+
const inputFilePath = './tasks/topojson/world_rectangle.geojson';
8888
const outputFilePath = `${outputDirGeojson}/${name}_${resolution}m/ocean.geojson`;
8989
const eraseFilePath = `${outputDirGeojson}/${unFilename}_${resolution}m/${source}.geojson`;
9090
const commands = [
@@ -214,41 +214,128 @@ async function convertLayersToTopojson({ name, resolution }) {
214214
fs.writeFileSync(outputFile, JSON.stringify(prunedTopojson));
215215
}
216216

217-
// Get polygon features from UN GeoJSON
218-
const inputFilePath = `${inputDir}/${unFilename}.geojson`;
217+
// Get polygon features from UN GeoJSON and patch Antarctica gap
218+
const inputFilePathUNGeojson = `${inputDir}/${unFilename}.geojson`;
219+
const inputFilePathAntarcticaPatch = './tasks/topojson/antarctica_patch.geojson';
219220
const outputFilePath50m = `${outputDirGeojson}/${unFilename}_50m/all_features.geojson`;
220221
const outputPath110m = `${outputDirGeojson}/${unFilename}_110m`;
221-
const commandsAllFeatures = [inputFilePath, `-o target=1 ${outputFilePath50m}`].join(' ');
222-
await mapshaper.runCommands(commandsAllFeatures);
223-
224-
const geojson = getJsonFile(outputFilePath50m);
225-
const simplifiedGeojson = {
226-
...geojson,
227-
features: geojson.features.map((f) => simplify(f, { tolerance: 0.01, highQuality: true }))
228-
};
229-
if (!fs.existsSync(outputPath110m)) fs.mkdirSync(outputPath110m, { recursive: true });
230-
fs.writeFileSync(`${outputPath110m}/all_features.geojson`, JSON.stringify(simplifiedGeojson));
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+
const commandsAllFeaturesCommon = [
236+
inputFilePathUNGeojson,
237+
`-filter 'iso3cd === "ATA"' target=1 + name=antarctica`,
238+
'-clean snap-interval=0.015 target=antarctica',
239+
'-rectangle bbox=-180,-90,180,-89 name=antarctica_rectangle',
240+
'-merge-layers target=antarctica,antarctica_rectangle force',
241+
'-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',
242+
`-filter 'georeg !== "ANT"' target=1`,
243+
'-merge-layers target=1,antarctica force name=all_features',
244+
]
245+
const commandsAllFeatures50m = [
246+
...commandsAllFeaturesCommon,
247+
`-o target=1 ${outputFilePath50m}`
248+
].join(" ")
249+
await mapshaper.runCommands(commandsAllFeatures50m);
250+
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+
// Get countries from all polygon features
268+
const inputFilePathCountries50m = outputFilePath50m;
269+
const outputFilePathCountries50m = `${outputDirGeojson}/${unFilename}_50m/countries.geojson`;
270+
const commandsCountries50m = [
271+
inputFilePathCountries50m,
272+
`-filter '${filters.countries}'`,
273+
'-clean',
274+
`-o ${outputFilePathCountries50m}`
275+
].join(' ');
276+
await mapshaper.runCommands(commandsCountries50m);
277+
278+
// Get land from all polygon features
279+
const inputFilePathLand50m = outputFilePath50m;
280+
const outputFilePathLand50m = `${outputDirGeojson}/${unFilename}_50m/land.geojson`;
281+
const commandsLand50m = [
282+
inputFilePathLand50m,
283+
'-dissolve2',
284+
`-o ${outputFilePathLand50m}`
285+
].join(' ');
286+
await mapshaper.runCommands(commandsLand50m);
287+
288+
// Create 110m geodata
289+
const outputFilePath110m = `${outputDirGeojson}/${unFilename}_110m/all_features.geojson`;
290+
const commandsAllFeatures110m = [
291+
...commandsAllFeaturesCommon,
292+
'-simplify 10% rdp',
293+
`-o target=1 ${outputFilePath110m}`
294+
].join(" ")
295+
await mapshaper.runCommands(commandsAllFeatures110m);
296+
297+
// Get countries from all polygon features
298+
const inputFilePathCountries110m = outputFilePath110m;
299+
const outputFilePathCountries110m = `${outputDirGeojson}/${unFilename}_110m/countries.geojson`;
300+
const commandsCountries110m = [
301+
inputFilePathCountries110m,
302+
`-filter '${filters.countries}'`,
303+
'-clean snap-interval=0.015',
304+
`-o ${outputFilePathCountries110m}`
305+
].join(' ');
306+
await mapshaper.runCommands(commandsCountries110m);
307+
308+
// Get land from all polygon features
309+
const inputFilePathLand110m = outputFilePathCountries110m;
310+
const outputFilePathLand110m = `${outputDirGeojson}/${unFilename}_110m/land.geojson`;
311+
const commandsLand110m = [
312+
inputFilePathLand110m,
313+
'-dissolve2',
314+
`-o ${outputFilePathLand110m}`
315+
].join(' ');
316+
await mapshaper.runCommands(commandsLand110m);
231317

232318
for (const resolution of resolutions) {
233319
for (const { source } of Object.values(vectors)) {
234320
await convertShpToGeo(getNEFilename({ resolution, source }));
235321
}
236322

237-
// Get countries from all polygon features
238-
const inputFilePathCountries = `${outputDirGeojson}/${unFilename}_${resolution}m/all_features.geojson`;
239-
const outputFilePathCountries = `${outputDirGeojson}/${unFilename}_${resolution}m/countries.geojson`;
240-
const commandsCountries = [
241-
inputFilePathCountries,
242-
`-filter '${filters.countries}'`,
243-
`-o ${outputFilePathCountries}`
244-
].join(' ');
245-
await mapshaper.runCommands(commandsCountries);
246-
247-
// Get land from all polygon features
248-
const inputFilePathLand = `${outputDirGeojson}/${unFilename}_${resolution}m/all_features.geojson`;
249-
const outputFilePathLand = `${outputDirGeojson}/${unFilename}_${resolution}m/land.geojson`;
250-
const commandsLand = [inputFilePathLand, `-filter '${filters.land}'`, `-clean -o ${outputFilePathLand}`].join(' ');
251-
await mapshaper.runCommands(commandsLand);
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);
252339
}
253340

254341
for (const resolution of resolutions) {

0 commit comments

Comments
 (0)