Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 4 additions & 26 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run Makefile with Selenium
name: Run Makefile

on:
# Schedule to run on the 1st day of each month
Expand Down Expand Up @@ -26,40 +26,18 @@ jobs:
- name: Check out repository
uses: actions/checkout@v3

- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: '3.12'

- name: Install Python dependencies
run: |
python -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install -r scripts/requirements.txt

- name: Install Xvfb and dependencies
run: |
sudo apt-get update
sudo apt-get install -y xvfb
sudo apt-get install -y chromium-browser

- name: Install GDAL (ogr2ogr)
run: |
sudo apt-get update
sudo apt-get install -y gdal-bin
ogr2ogr --version

- name: Run Makefile with Xvfb
- name: Run Makefile
run: |
Xvfb :99 -screen 0 1024x768x24 &
export DISPLAY=:99
source venv/bin/activate
make all
make data

- name: Run Make Clean
run: |
source venv/bin/activate
make clean

- name: Push and Commit
Expand All @@ -70,4 +48,4 @@ jobs:
run: |
git config --global user.email "${{env.CI_COMMIT_EMAIL}}"
git config --global user.name "${{env.CI_COMMIT_NAME}}"
git diff --quiet && echo "No changes to commit" || (git add data/country-codes.csv && git commit -m "${{env.CI_COMMIT_MESSAGE}}" && git push)
git diff --quiet && echo "No changes to commit" || (git add data/countries.geojson && git commit -m "${{env.CI_COMMIT_MESSAGE}}" && git push)
24 changes: 6 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
VENV = venv
PYTHON = $(VENV)/bin/python3
PIP = $(VENV)/bin/pip
EXTRACTED_DIR = extracted_files

.PHONY: data clean

all: data

data: $(VENV)/bin/activate
$(PYTHON) scripts/process.py

$(VENV)/bin/activate: scripts/requirements.txt
python3 -m venv $(VENV)
$(PIP) install -r scripts/requirements.txt

clean:
rm -rf __pycache__
rm -rf $(VENV)
find . -maxdepth 1 -name "*.zip" -exec rm -f {} +
if [ -d $(EXTRACTED_DIR) ]; then rm -rf $(EXTRACTED_DIR); fi

download:
if [ ! -f ne_10m_admin_0_countries.zip ]; then curl -L -o ne_10m_admin_0_countries.zip https://naciscdn.org/naturalearth/10m/cultural/ne_10m_admin_0_countries.zip; fi

data: download
ogr2ogr -f GeoJSON -makevalid -lco COORDINATE_PRECISION=6 -sql "SELECT admin as name, iso_a3 as \"ISO3166-1-Alpha-3\", iso_a2 as \"ISO3166-1-Alpha-2\" FROM ne_10m_admin_0_countries" data/countries.geojson /vsizip/ne_10m_admin_0_countries.zip
Copy link
Contributor Author

@wiki0831 wiki0831 Apr 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why makevalid

the original geojson from NaturalEarth contain invalid geometry features and this flag auto correct the invalid features.

also fixes:

example:
Screenshot 2025-04-10 at 2 27 09 AM (2)

Copy link
Contributor Author

@wiki0831 wiki0831 Apr 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why "COORDINATE_PRECISION=6"

source dataset from natural earth is at 10m res and 6 decimal place is sufficient

reducing to 6th decimal also reduces the file size.

re:

57 changes: 41 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,48 @@ Perfect for use in apps and visualizations.

The data comes from [Natural Earth][naturalearth], a community effort to make visually pleasing, well-crafted maps with cartography or GIS software at small scale.

The shape of the countries has two fields :
* name : the common name for the country
* ISO3166-1-Alpha-3 : three letters iso code of the country

More info about countries can be obtained from datapackage https://github.com/datasets/country-codes by a join on field ISO3166-1-Alpha-3

[naturalearth]: http://www.naturalearthdata.com/
[datapackage]: http://dataprotocols.org/data-packages/
[naturalearth]: https://www.naturalearthdata.com/
[datapackage]: https://datapackage.org/standard/data-package/

## Preparation

To run the script in order to update the data : see [scripts README](scripts/README.md)
To run the script and update the data:

### Prerequisites

1. Install required tools:
- [GDAL](https://gdal.org/en/latest/download.html) - for geographic data processing

2. Verify GDAL installation:
```bash
ogr2ogr --version
```

### Data Processing

The project uses `ogr2ogr` to convert Natural Earth's country boundaries from Shapefile to GeoJSON format, with the following features:
- Coordinate precision set to 6 decimal places
- Geometry validation enabled (`-makevalid`):
- Fixes self-intersecting polygons
- Corrects ring orientation
- Removes duplicate vertices
- Ensures geometric validity for better compatibility with GIS tools
- Selected fields:
- `name`: Common name of the country (from admin field)
- `ISO3166-1-Alpha-2`: Two-letter ISO country code (from iso_a2 field)
- `ISO3166-1-Alpha-3`: Three-letter ISO country code (from iso_a3 field)

To process the data:
```bash
make data
```

This will:
1. Download the Natural Earth countries dataset
2. Convert it to GeoJSON format with the specified settings
3. Save the result in `data/countries.geojson`

## License

Expand All @@ -32,12 +62,7 @@ formally required a link back or credit to [Natural Earth][naturalearth], [Lexma
All source code is licenced under the [MIT licence][mit].

[mit]: https://opensource.org/licenses/MIT
[naturalearth]: http://www.naturalearthdata.com/
[pddl]: http://opendatacommons.org/licenses/pddl/1.0/
[lexman]: http://github.com/lexman
[okfn]: http://okfn.org/





[naturalearth]: https://www.naturalearthdata.com/
[pddl]: https://opendatacommons.org/licenses/pddl/1.0/
[lexman]: https://github.com/lexman
[okfn]: https://okfn.org/
26 changes: 0 additions & 26 deletions scripts/README.md

This file was deleted.

114 changes: 0 additions & 114 deletions scripts/process.py

This file was deleted.

1 change: 0 additions & 1 deletion scripts/requirements.txt

This file was deleted.

Loading