Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

feat: Switch geodata providers #7393

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 47 commits into
base: master
Choose a base branch
Loading
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
e8d763d
Add new dev dependencies
camdecoster Mar 20, 2025
7f7b690
Add build scripts
camdecoster Mar 20, 2025
6b596c0
Update some topojson references
camdecoster Mar 20, 2025
353bf94
Add npm build scripts
camdecoster Mar 20, 2025
fc6022f
Add 'usa' config
camdecoster Mar 20, 2025
2910eea
Add clipping bounds for Antarctica
camdecoster Mar 20, 2025
5d66dad
Apply suggestions from code review
camdecoster Mar 20, 2025
3b47c67
Add geodata archive, update get_geodata script paths
camdecoster Mar 21, 2025
b434656
Switch config file to JS
camdecoster Mar 21, 2025
a4d0b21
Switch coastlines layer source
camdecoster Mar 21, 2025
e257b7b
Add Oceania clipping bounds
camdecoster Mar 21, 2025
1154ff1
Switch layer name to 'ocean'
camdecoster Mar 21, 2025
86d5b00
Update test config
camdecoster Mar 26, 2025
86f048c
Switch to UN/NE geodata hybrid
camdecoster Mar 30, 2025
ac61095
Merge remote-tracking branch 'origin/master' into cam/7334/switch-geo…
camdecoster Apr 6, 2025
f4c3d48
Fix zip/unzip of UN geojson
camdecoster Apr 7, 2025
22a8e0a
Fix saving 110m maps
camdecoster Apr 7, 2025
247f925
Update dist with new maps
camdecoster Apr 8, 2025
3cf9730
Update geo tests
camdecoster Apr 8, 2025
24e8558
Update cibuild npm script
camdecoster Apr 8, 2025
b2ae532
Add draftlog
camdecoster Apr 8, 2025
85ad69c
Remove sane-topojson package
camdecoster Apr 15, 2025
b903b9f
Add small fixes
camdecoster Apr 15, 2025
e74c65c
Remove log statements
camdecoster Apr 15, 2025
33a2e00
add some mocks to blacklist
emilykl Apr 22, 2025
4868250
update baselines for new geodata
emilykl Apr 22, 2025
bce8d21
update blacklist in compare_pixels_test
emilykl Apr 22, 2025
da44084
Save UN geodata in build folder
camdecoster Apr 22, 2025
69f104e
make sure slash is added when concatenating topojson path
emilykl Apr 23, 2025
c684b72
use local topojson for image tests
emilykl Apr 23, 2025
362233a
update paths in jasmine geo_test
emilykl Apr 23, 2025
4d37b8c
filter out extra features
emilykl Apr 23, 2025
bb8377b
update image baselines for new geodata
emilykl Apr 23, 2025
6356355
Merge pull request #7406 from plotly/cam/7334/switch-geodata-provider…
emilykl Apr 23, 2025
5482adf
Filter out extra Hawaii feature during processing
camdecoster Apr 24, 2025
2710e7c
Revert "filter out extra features"
camdecoster Apr 24, 2025
b8bfea6
Adjust world rectangle to account for coordinate issues
camdecoster May 6, 2025
d6ea8ab
Fix Anarctica geometry and simplification
camdecoster May 6, 2025
3ec56ab
Fix land layer, clean up comments
camdecoster May 6, 2025
79017d5
Remove unused filter
camdecoster May 6, 2025
0f9049c
Remove turf simplify
camdecoster May 6, 2025
4a6fb9d
Update topojson
camdecoster May 6, 2025
33d3425
Filter Greenland out of Europe
camdecoster May 6, 2025
c74f711
Erase Caspian Sea
camdecoster May 6, 2025
f7cdc5f
Update topojson
camdecoster May 7, 2025
9711ef7
Update country codes for disputed territories at Egypt/Sudan border
camdecoster May 21, 2025
51a596e
Update topojson
camdecoster May 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove log statements
  • Loading branch information
camdecoster committed Apr 15, 2025
commit e74c65c8246f88eb062d0700cdfd7542085209e4
20 changes: 3 additions & 17 deletions 20 tasks/topojson/get_geodata.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,26 @@ const { resolutions, unDownloadUrl, unFilename, vectors } = config;
const tasksPath = './tasks/topojson';
const outputPath = './build/geodata';

// Download Natural Earth vectors
// Download Natural Earth vector maps
for (const vector of Object.values(vectors)) {
for (const resolution of resolutions) {
const url = getNEDownloadUrl({ resolution, vector });
const filename = getNEFilename({ resolution, source: vector.source });
const archivePath = `${outputPath}/${filename}.zip`;

if (fs.existsSync(archivePath)) {
console.log(`File ${archivePath} already exists. Skipping download.`);
} else {
if (!fs.existsSync(archivePath)) {
try {
console.log(`Downloading data from ${url}`);

const response = await fetch(url);
if (!response.ok || !response.body) throw new Error(`Bad response: ${response.status}`);

if (!fs.existsSync(outputPath)) fs.mkdirSync(outputPath, { recursive: true });
const file = fs.createWriteStream(archivePath);
await pipeline(Readable.fromWeb(response.body), file);

console.log('Decompressing NE shapefile');
// Use the shell to handle decompressing
if (!fs.existsSync(outputPath)) fs.mkdirSync(outputPath, { recursive: true });
exec(`unzip -o ${archivePath} -d ${outputPath}`);

console.log(`NE Shapefile decompressed to ${outputPath}`);
} catch (error) {
console.error(`Error when downloading file '${archivePath}': ${error}`);
continue;
Expand All @@ -50,26 +44,18 @@ const geojsonPath = `${outputPath}`;
const geojsonFilePath = `${geojsonPath}/${unFilename}.geojson`;

if (fs.existsSync(archivePath)) {
console.log(`File ${archivePath} already exists. Skipping download.`);
if (fs.existsSync(geojsonFilePath)) console.log(`File ${geojsonFilePath} already exists. Skipping decompression.`);
else exec(`unzip -o ${archivePath} -d ${geojsonPath}`);
if (!fs.existsSync(geojsonFilePath)) exec(`unzip -o ${archivePath} -d ${geojsonPath}`);
} else {
try {
console.log(`Downloading data from ${url}`);

const response = await fetch(url);
if (!response.ok || !response.body) throw new Error(`Bad response: ${response.status}`);

// if (!fs.existsSync(outputPath)) fs.mkdirSync(outputPath, { recursive: true });
const file = fs.createWriteStream(geojsonFilePath);
await pipeline(Readable.fromWeb(response.body), file);
console.log(`UN GeoJSON file saved to ${geojsonFilePath}`);

console.log('Compressing UN GeoJSON for future use');
// Use the shell to handle compression
exec(`zip -j ${archivePath} ${geojsonFilePath}`);

console.log(`UN GeoJSON archive saved to ${archivePath}`);
} catch (error) {
console.error(`Error when downloading file '${geojsonFilePath}': ${error}`);
}
Expand Down
17 changes: 1 addition & 16 deletions 17 tasks/topojson/process_geodata.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ async function convertShpToGeo(filename) {
const outputFilePath = `${outputDirGeojson}/${filename}.geojson`;
const commands = [inputFilePath, `-proj wgs84`, `-o format=geojson ${outputFilePath}`].join(' ');
await mapshaper.runCommands(commands);

console.log(`GeoJSON saved to ${outputFilePath}`);
}

function getJsonFile(filename) {
Expand All @@ -32,7 +30,6 @@ function getJsonFile(filename) {
}

async function createCountriesLayer({ bounds, filter, name, resolution, source }) {
console.log(`Building ${resolution}m countries layer for '${name}'`);
const inputFilePath = `${outputDirGeojson}/${unFilename}_${resolution}m/${source}.geojson`;
const outputFilePath = `${outputDirGeojson}/${name}_${resolution}m/countries.geojson`;
const commands = [
Expand All @@ -43,7 +40,6 @@ async function createCountriesLayer({ bounds, filter, name, resolution, source }
].join(' ');
await mapshaper.runCommands(commands);
addCentroidsToGeojson(outputFilePath);
// TODO: Add simplification command if on 110m resolution? Or take care of somewhere else?
}

function addCentroidsToGeojson(geojsonPath) {
Expand All @@ -62,7 +58,6 @@ function addCentroidsToGeojson(geojsonPath) {

async function createLandLayer({ bounds, name, resolution, source }) {
// TODO: Figure out way to only include North and Central America via filter, dissolve
console.log(`Building ${resolution}m land layer for '${name}'`);
const inputFilePath = `${outputDirGeojson}/${unFilename}_${resolution}m/${source}.geojson`;
const outputFilePath = `${outputDirGeojson}/${name}_${resolution}m/land.geojson`;
const commands = [
Expand All @@ -75,7 +70,6 @@ async function createLandLayer({ bounds, name, resolution, source }) {
}

async function createCoastlinesLayer({ bounds, name, resolution, source }) {
console.log(`Building ${resolution}m coastlines layer for '${name}'`);
// TODO: Update source to be a path?
const inputFilePath = `${outputDirGeojson}/${unFilename}_${resolution}m/${source}.geojson`;
const outputFilePath = `${outputDirGeojson}/${name}_${resolution}m/coastlines.geojson`;
Expand All @@ -90,7 +84,6 @@ async function createCoastlinesLayer({ bounds, name, resolution, source }) {
}

async function createOceanLayer({ bounds, name, resolution, source }) {
console.log(`Building ${resolution}m ocean layer for '${name}'`);
const inputFilePath = `./tasks/topojson/world_rectangle.geojson`;
const outputFilePath = `${outputDirGeojson}/${name}_${resolution}m/ocean.geojson`;
const eraseFilePath = `${outputDirGeojson}/${unFilename}_${resolution}m/${source}.geojson`;
Expand All @@ -104,7 +97,6 @@ async function createOceanLayer({ bounds, name, resolution, source }) {
}

async function createRiversLayer({ name, resolution, source }) {
console.log(`Building ${resolution}m rivers layer for '${name}'`);
const inputFilePath = `${outputDirGeojson}/${getNEFilename({ resolution, source })}.geojson`;
const outputFilePath = `${outputDirGeojson}/${name}_${resolution}m/rivers.geojson`;
const commands = [
Expand All @@ -116,7 +108,6 @@ async function createRiversLayer({ name, resolution, source }) {
}

async function createLakesLayer({ name, resolution, source }) {
console.log(`Building ${resolution}m lakes layer for '${name}'`);
const inputFilePath = `${outputDirGeojson}/${getNEFilename({ resolution, source })}.geojson`;
const outputFilePath = `${outputDirGeojson}/${name}_${resolution}m/lakes.geojson`;
const commands = [
Expand All @@ -128,7 +119,6 @@ async function createLakesLayer({ name, resolution, source }) {
}

async function createSubunitsLayer({ name, resolution, source }) {
console.log(`Building ${resolution}m subunits layer for '${name}'`);
const filter = ['AUS', 'BRA', 'CAN', 'USA'].map((id) => `adm0_a3 === "${id}"`).join(' || ');
const inputFilePath = `${outputDirGeojson}/${getNEFilename({ resolution, source })}.geojson`;
const outputFilePath = `${outputDirGeojson}/${name}_${resolution}m/subunits.geojson`;
Expand Down Expand Up @@ -211,10 +201,7 @@ function getCentroid(feature) {

async function convertLayersToTopojson({ name, resolution }) {
const regionDir = path.join(outputDirGeojson, `${name}_${resolution}m`);
if (!fs.existsSync(regionDir)) {
console.log(`Couldn't find ${regionDir}`);
return;
}
if (!fs.existsSync(regionDir)) return;

const outputFile = `${outputDirTopojson}/${name}_${resolution}m.json`;
// Layer names default to file names
Expand All @@ -225,8 +212,6 @@ async function convertLayersToTopojson({ name, resolution }) {
const topojson = getJsonFile(outputFile);
const prunedTopojson = pruneProperties(topojson);
fs.writeFileSync(outputFile, JSON.stringify(prunedTopojson));

console.log(`Topojson saved to: ${outputFile}`);
}

// Get polygon features from UN GeoJSON
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.