Carto Tools is a C++ application for performing geospatial tasks on GeoJSON files, such as intersection reports, GeoJSON similarity calculations, and area error calculations.
Before building the project, ensure you have the following software installed:
brew install cmake make boostsudo apt update
sudo apt install cmake make libboost-all-devBuild the Docker image using the provided Dockerfile:
docker build -t carto-tools .Create and run the Docker container with Volume Mounting:
docker run -it --name carto-container -v $(pwd):/app carto-toolsFor consecutive runs, start the container:
docker start -ai carto-containerTo build and install the project, navigate to the project directory and use the following single command:
cmake -B build && make -C build && make install -C buildThe application supports multiple tasks via command-line arguments. Below are the available commands:
Generate a report of intersections in a GeoJSON file. The report includes:
- The number of self-intersections.
- The number of intersections with other polygons. (overlapping polygons intersections)
- SVG visualization of the intersections (if any).
carto --intersection --map <geojson_file>Example:
carto --intersection --map ./data/belgium/belgium_intersections.geojsonCalculate similarity metrics (Frechet Distance, Hausdorff Distance, and Symmetric Difference) between two GeoJSON files.
Both GeoJSON files must share at least one common property within their features (shared identifier, name). For example, the two files could represent the same map before and after a cartogram transformation, such as one generated at go-cart.io.
carto --similarity --map_1 <geojson_file_1> --map_2 <geojson_file_2>Example:
carto --similarity --map_1 ./data/belgium/belgium.geojson --map_2 ./data/belgium/belgium_cartogram.geojsonCalculate the Max Relative Area Error and the Area Weighted Mean Error of a GeoJSON file compared to a target area CSV file. The target area CSV file template can be generated using the --create_csv command described below. Simply fill in the empty column with the target area values.
carto --area_error --map <geojson_file> --target_area_csv <csv_file>Example:
carto --area_error --map ./data/belgium/belgium_cartogram.geojson --target_area_csv ./data/belgium/belgium_population.csvGenerate a CSV file template for target area values. The CSV file will contain one column that is empty for the user to fill in the target area values. The completed CSV file can be used as input for the --area_error command.
carto --create_csv --map <geojson_file>Example:
carto --create_csv --map ./data/belgium/belgium.geojsonThe repository includes several shell scripts to automate common tasks. These scripts assume that your analysis data is located in a specific directory. By default, the scripts will look for files in the current directory unless a different directory is specified as an argument.
- The scripts assume that the GeoJSON files follow a naming convention:
<base_name>_input.geojson,<base_name>_cartogram.geojson, and<base_name>_fcarto.geojson. - The
area_error.shscript also assumes the presence of a target area CSV file named<base_name>.csv.
This script calculates similarity metrics between _input.geojson files and their corresponding _cartogram.geojson and _fcarto.geojson files.
./similarity.sh [directory]Example:
./similarity.sh ./data/belgiumThis script generates intersection reports for _input.geojson, _cartogram.geojson, and _fcarto.geojson files.
./intersections.sh [directory]Example:
./intersections.sh ./data/belgiumThis script calculates area error metrics for _input.geojson, _cartogram.geojson, and _fcarto.geojson files using a corresponding target area CSV file.
./area_error.sh [directory]Example:
./area_error.sh ./data/belgiumIf you encounter any problems, have feature requests, or have suggestions, please create an issue in the repository.
This project is licensed under the MIT License.