({ name, resolution })
| 229 | } |
| 230 | |
| 231 | async function convertLayersToTopojson({ name, resolution }) { |
| 232 | const regionDir = path.join(outputDirGeojson, `${name}_${resolution}m`); |
| 233 | if (!fs.existsSync(regionDir)) return; |
| 234 | |
| 235 | const outputFile = `${outputDirTopojson}/${name}_${resolution}m.json`; |
| 236 | // Scopes with polygons that cross the antimeridian need to be stitched |
| 237 | if (['antarctica', 'world'].includes(name)) { |
| 238 | const geojsonObjects = {}; |
| 239 | for (const layer of Object.keys(config.layers)) { |
| 240 | const filePath = path.join(regionDir, `${layer}.geojson`); |
| 241 | geojsonObjects[layer] = geoStitch(rewindGeojson(getJsonFile(filePath))); |
| 242 | } |
| 243 | // Convert geojson to topojson |
| 244 | const topojsonTopology = topology(geojsonObjects, 1000000); |
| 245 | fs.writeFileSync(outputFile, JSON.stringify(topojsonTopology)); |
| 246 | } else { |
| 247 | // In Mapshaper, layer names default to file names |
| 248 | const commands = [`${regionDir}/*.geojson combine-files`, `-o format=topojson ${outputFile}`].join(' '); |
| 249 | await mapshaper.runCommands(commands); |
| 250 | } |
| 251 | |
| 252 | // Remove extra information from features |
| 253 | const topojson = getJsonFile(outputFile); |
| 254 | const prunedTopojson = pruneProperties(topojson); |
| 255 | fs.writeFileSync(outputFile, JSON.stringify(prunedTopojson)); |
| 256 | } |
| 257 | |
| 258 | // Get required polygon features from UN GeoJSON |
| 259 | const inputFilePathUNGeojson = `${inputDir}/${unFilename}.geojson`; |
no test coverage detected
searching dependent graphs…