Skip to content

niloy-biswas/Population-Density-Map

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Population Density Map

3D population density maps built with R and Rayshader, using Kontur population data.

Project Structure

Population/
├── run_country.R          # Entry point — run maps from here
├── scripts/
│   ├── countries.R        # All country configs (edit here to tweak maps)
│   ├── helpers.R          # Palette creation utilities
│   ├── create_pop_matrix.R
│   ├── plot_population_3d.R
│   ├── annotate_population_map.R
│   ├── setup_packages.R   # Run once to install dependencies
│   └── legacy/            # Old per-country scripts (reference only)
├── data/                  # Kontur .gpkg population + boundary files
└── output/
    ├── plots/             # Raw 3D renders
    └── annotated/         # Final annotated maps

Setup

1. Install R Download from cran.r-project.org (v4.4+)

2. Install XQuartz (macOS only — required for rgl) Download from xquartz.org, install, then restart Mac.

3. Install R packages Open scripts/setup_packages.R and run it once.

Running a Map

Open run_country.R, uncomment the country you want, and source the file:

run_country("bangladesh")
# run_country("finland")
# run_country("india")
# ... etc

Output saves automatically to output/annotated/<Country>_population_density.png.

Adding a New Country

  1. Get data from Kontur:

    • Population file: kontur_population_XX_*.gpkg
    • Boundaries file: kontur_boundaries_XX_*.gpkg
    • Place both in data/
  2. Add a config block to scripts/countries.R:

my_country = list(
  name       = "My Country",
  hex_file   = "data/kontur_population_XX_20231101.gpkg",
  admin_file = "data/kontur_boundaries_XX_20230628.gpkg",
  crs        = 3857,        # find at epsg.io
  size       = 3000,
  palette    = list(source = "metbrewer", name = "Benedictus", direction = -1),
  zscale     = 40,
  camera     = list(theta = 0, phi = 55, zoom = 0.75, fov = 100),
  light_dir  = 315,
  width      = 1400, height = 1800,
  solid      = FALSE, shadow_depth = 0
)
  1. Uncomment in run_country.R:
run_country("my_country")

See the comment block at the top of scripts/countries.R for what each parameter does.

Maps

Bangladesh

Bangladesh

Dhaka

Dhaka

Chittagong

Chittagong

Barishal

Barishal

India

India

Nepal

Nepal

Bhutan

Bhutan

Sri Lanka

Sri Lanka

Myanmar

Myanmar

Maldives

Maldives

Israel

Israel

Palestine

Palestine

Israel & Palestine

Israel & Palestine

Finland

Finland

Contributing

Fork the repo, add your country config to scripts/countries.R, and submit a pull request.

About

Explore population density patterns in this repository featuring a captivating map generated with the Rayshader package in R.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages