mirror of
https://github.com/koala73/worldmonitor.git
synced 2026-04-25 17:14:57 +02:00
fix: add India boundary override from Natural Earth 50m data (#1796)
Adds India (IN) to country-boundary-overrides.geojson using the same Natural Earth 50m Admin 0 Countries dataset already used for Pakistan. The override system automatically replaces the base geometry on app load, providing a higher-resolution MultiPolygon boundary (1518 points). Renames the fetch script to reflect its broader purpose and updates doc references in CONTRIBUTING.md and maps-and-geocoding.mdx. Fixes koala73/worldmonitor#1721 Co-authored-by: stablegenius49 <185121704+stablegenius49@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Elie Habib <elie.habib@gmail.com>
This commit is contained in:
@@ -259,10 +259,10 @@ For endpoints that deal with non-JSON payloads (XML feeds, binary data, HTML emb
|
||||
|
||||
### Country boundary overrides
|
||||
|
||||
Country outlines are loaded from `public/data/countries.geojson`. Optional higher-resolution overrides (sourced from [Natural Earth](https://www.naturalearthdata.com/)) are served from R2 CDN. The app loads overrides after the main file and replaces geometry for any country whose `ISO3166-1-Alpha-2` (or `ISO_A2`) matches. To refresh the Pakistan boundary from Natural Earth, run:
|
||||
Country outlines are loaded from `public/data/countries.geojson`. Optional higher-resolution overrides (sourced from [Natural Earth](https://www.naturalearthdata.com/)) are served from R2 CDN. The app loads overrides after the main file and replaces geometry for any country whose `ISO3166-1-Alpha-2` (or `ISO_A2`) matches. To refresh boundary overrides from Natural Earth, run:
|
||||
|
||||
```bash
|
||||
node scripts/fetch-pakistan-boundary-override.mjs
|
||||
node scripts/fetch-country-boundary-overrides.mjs
|
||||
rclone copy public/data/country-boundary-overrides.geojson r2:worldmonitor-maps/
|
||||
```
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ The override mechanism lets us improve individual country boundaries without rep
|
||||
```
|
||||
5. No code changes needed — the app picks up the new geometry automatically
|
||||
|
||||
**Example script**: `scripts/fetch-pakistan-boundary-override.mjs` downloads the full Natural Earth 50m dataset (~24 MB), extracts Pakistan's feature, and writes the override file.
|
||||
**Example script**: `scripts/fetch-country-boundary-overrides.mjs` downloads the full Natural Earth 50m dataset (~24 MB), extracts country features (currently Pakistan and India), and writes the override file.
|
||||
|
||||
### Geopolitical Sensitivity
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,12 +1,14 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Fetches Pakistan's boundary from Natural Earth 50m Admin 0 Countries and writes
|
||||
* Fetches country boundaries from Natural Earth 50m Admin 0 Countries and writes
|
||||
* country-boundary-overrides.geojson locally. After running, upload to R2:
|
||||
* rclone copy public/data/country-boundary-overrides.geojson r2:worldmonitor-maps/
|
||||
*
|
||||
* Note: downloads the full NE 50m countries file (~24 MB) to extract Pakistan.
|
||||
* Currently extracts: Pakistan (PK), India (IN)
|
||||
*
|
||||
* Usage: node scripts/fetch-pakistan-boundary-override.mjs
|
||||
* Note: downloads the full NE 50m countries file (~24 MB) to extract boundaries.
|
||||
*
|
||||
* Usage: node scripts/fetch-country-boundary-overrides.mjs
|
||||
* Requires network access.
|
||||
*/
|
||||
|
||||
@@ -19,6 +21,12 @@ const NE_50M_URL = 'https://raw.githubusercontent.com/nvkelso/natural-earth-vect
|
||||
const OUT_DIR = join(__dirname, '..', 'public', 'data');
|
||||
const OUT_FILE = join(OUT_DIR, 'country-boundary-overrides.geojson');
|
||||
|
||||
/** Countries to extract from Natural Earth and include as boundary overrides. */
|
||||
const OVERRIDE_COUNTRIES = [
|
||||
{ iso2: 'PK', iso3: 'PAK', name: 'Pakistan' },
|
||||
{ iso2: 'IN', iso3: 'IND', name: 'India' },
|
||||
];
|
||||
|
||||
async function main() {
|
||||
console.log('Fetching Natural Earth 50m countries...');
|
||||
const resp = await fetch(NE_50M_URL, { signal: AbortSignal.timeout(60_000) });
|
||||
@@ -29,27 +37,31 @@ async function main() {
|
||||
if (!data?.features?.length) {
|
||||
throw new Error('Invalid GeoJSON: no features');
|
||||
}
|
||||
const pak = data.features.find((f) => f.properties?.ISO_A2 === 'PK' || f.properties?.['ISO3166-1-Alpha-2'] === 'PK');
|
||||
if (!pak) {
|
||||
throw new Error('Pakistan (PK) feature not found in Natural Earth data');
|
||||
}
|
||||
const override = {
|
||||
type: 'FeatureCollection',
|
||||
features: [
|
||||
{
|
||||
type: 'Feature',
|
||||
properties: {
|
||||
name: 'Pakistan',
|
||||
'ISO3166-1-Alpha-2': 'PK',
|
||||
'ISO3166-1-Alpha-3': 'PAK',
|
||||
},
|
||||
geometry: pak.geometry,
|
||||
|
||||
const features = [];
|
||||
for (const country of OVERRIDE_COUNTRIES) {
|
||||
const feature = data.features.find(
|
||||
(f) => f.properties?.ISO_A2 === country.iso2 || f.properties?.['ISO3166-1-Alpha-2'] === country.iso2,
|
||||
);
|
||||
if (!feature) {
|
||||
throw new Error(`${country.name} (${country.iso2}) feature not found in Natural Earth data`);
|
||||
}
|
||||
features.push({
|
||||
type: 'Feature',
|
||||
properties: {
|
||||
name: country.name,
|
||||
'ISO3166-1-Alpha-2': country.iso2,
|
||||
'ISO3166-1-Alpha-3': country.iso3,
|
||||
},
|
||||
],
|
||||
};
|
||||
geometry: feature.geometry,
|
||||
});
|
||||
console.log(`Extracted ${country.name} (${country.iso2})`);
|
||||
}
|
||||
|
||||
const override = { type: 'FeatureCollection', features };
|
||||
mkdirSync(OUT_DIR, { recursive: true });
|
||||
writeFileSync(OUT_FILE, JSON.stringify(override) + '\n', 'utf8');
|
||||
console.log('Wrote', OUT_FILE);
|
||||
console.log('Wrote', OUT_FILE, `(${features.length} countries)`);
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
Reference in New Issue
Block a user