MCPcopy Create free account
hub / github.com/plotly/plotly.js / convertLayersToTopojson

Function convertLayersToTopojson

topojson/bin/process_geodata.mjs:231–256  ·  view source on GitHub ↗
({ name, resolution })

Source from the content-addressed store, hash-verified

229}
230
231async 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
259const inputFilePathUNGeojson = `${inputDir}/${unFilename}.geojson`;

Callers 1

Calls 3

rewindGeojsonFunction · 0.85
getJsonFileFunction · 0.85
prunePropertiesFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…