This program uses the fast flow-based method developed by Michael T. Gastner, Vivien Seguy, and Pratyush More. For more information, you may refer to the following paper:
Gastner MT, Seguy V, More P. Fast flow-based algorithm for creating density-equalizing map projections. Proc Natl Acad Sci USA 115(10):E2156–E2164 (2018). https://doi.org/10.1073/pnas.0400280101
Data produced by code in this repository are subject to the MIT license found here and should cite the aforementioned paper by Gastner et al. (2018).
Run the following command (replace your-geojson-file.geojson file with your geographic data and your-csv-file.csv with your visual variables file, containing target areas for each geographic region):
cartogram your-geojson-file.geojson your-csv-file.csv- The first argument's input is a GeoJSON or JSON file, in the standard GeoJSON format.
- The second argument's input is a
.csvfile with data about target areas.
Note: use the -h flag to display more options.
The CSV file should be in the following format:
| NAME_1 | Data (e.g., Population) | Color |
|---|---|---|
| Bruxelles | 1208542 | #e74c3c |
| Vlaanderen | 6589069 | #f1c40f |
| Wallonie | 3633795 | #34495e |
-
NAME_1should be the same as the identifying property's name in the GeoJSON. The rows should also have the same data as is present in the identifying property. -
Datacontains the data you would like your cartogram to based on. -
Coloris the color you would like the geographic region to be. Colors may be represented in the following manner:cornflowerblue: html color codes supported byCSS3(case-insensitive), full list of supported colors may be found in the "Extended colors" section of web colors."rgb(255, 0, 120)"orrgb(255 0 120)or"255, 0, 120"or255 0 120: red, green and blue values out of 255.#e74c3c: hex code of color, must start with#.
You may find sample GeoJSON (containing geographic data) and CSV (containing information about target areas, colors and other visual variables) files in the cartogram-cpp/sample_data directory.
To test whether whether the program was installed successfully and is working fine, you may run the following command from the repository root:
cartogram sample_data/world_by_country_since_2022/world_by_country_since_2022.geojson sample_data/world_by_country_since_2022/world_population_by_country_2010.csv --plot_polygons --worldYou may inspect the resultant SVG to check if everything looks as expected.
We manage dependencies with a Python virtual environment and Conan 2. The project supports GCC, Clang, and Apple Clang, all with C++20 support. Please ensure that Python 3.10 or later and a C++20-supported compiler are installed before proceeding.
Only Debug build commands are shown below, but the same commands can be run with Release build by replacing Debug with Release.
- Create a virtual environment with the required dependencies:
virtualenv .venv && .venv/bin/pip install -r requirements.txt- Setup Conan
.venv/bin/conan remote update conancenter --url=https://center2.conan.ioThe following command will detect your system's profile and set it up for you. If you already have a profile set up, this may yeild an error, in which case you may skip this step.
.venv/bin/conan profile detect- Install dependencies via Conan
.venv/bin/conan install . --build=missing -s build_type=Debug -s compiler.cppstd=20- Configure and Build with CMake
.venv/bin/cmake -B build/Debug -S . -DCMAKE_TOOLCHAIN_FILE=build/Debug/generators/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
.venv/bin/cmake --build build/Debug -j4
sudo .venv/bin/cmake --install build # optional, to install the program globallyTo run all the tests, execute the following command from the root directory of the repository:
.venv/bin/ctest --test-dir build/Debug --output-on-failureTo run only the unit tests:
.venv/bin/ctest --test-dir build/Debug --output-on-failure -L unit.venv/bin/ctest --test-dir build/Debug --output-on-failure test_string_to_decimal_converter.cppThis test will run all the maps in the cartogram-cpp/sample_data folder.
To run only the stress tests:
.venv/bin/ctest --test-dir build/Debug --output-on-failure -L stressFuzzer tests run maps in the cartogram-cpp/sample_data folder with random data.
To run only the fuzzer tests:
.venv/bin/ctest --test-dir build/Debug -L fuzzer --verboseThis test will take a while to finish.
Add --verbose to the command to see more details about the test results.
For Windows users, we recommend using our program through Windows Subsystem for Linux (WSL).
- If you are unable to copmile on the latest version of Ubuntu/MacOS, please open an issue. In the meanwhile, follow the instructions for installation via Docker.
- If compilation suddenly stopped working for you, you may remove the
builddirectory withrm -rf buildand run the installation commands again. - If switching between
DebugandReleasebuilds, you may need to remove thebuilddirectory withrm -rf buildand run the installation commands again. - If running
.venv/bin/cmake -B build ...gives you an error, it is likely that a dependency was not installed correctly. Rerun the appropriate commands above to install the required dependencies and try again. If it still fails, make sure you have the virtual environment activated by running. .venv/bin/activatein your terminal, and then try again. - If you get an error which mentions permission issues, try running the command that gave you the error with
sudoprefixed, as done withsudo make install -C buildabove. - If VScode's
CMake: Installdoes not work, make sure you own/usr/local/binand the working directory. You may assign ownership to your account withsudo chown -R $(whoami) ., replacing.with the directory of choice.
To benchmark the program, first install hyperfine. You can install it using Homebrew on macOS:
brew install hyperfineOr using apt on Debian-based distributions:
apt install hyperfineThen, go to the cartogram-cpp/tests directory and run the following command:
bash stress_test.shGo to the cartogram-cpp directory in your preferred terminal and execute the following command:
sudo make uninstall -C buildUpon successful uninstallation, the following will be outputted:
> Built target uninstall
Further, running cartogram should no longer work.
Pushing changes to go-cart.io
To push changes to production, please follow the the instructions on go-cart-io/carotgram-docker.
Contributions are highly encouraged! Please feel free to take a stab at any at any of the open issues and send in a pull request. If you need help getting setup or more guidance contributing, please @ any of the main contributors (@adisidev, @nihalzp, @mgastner) under any of the open issues (or after creating your own issue), and we'll be happy to guide you!
If you'd like to contribute to the project, please run our tests after you make any changes.
Maintainers, please make sure all the CI checks pass before approving the pull request.