A comprehensive, modular geospatial analysis toolkit for working with world maps. It ships with a command line interface as well as a small FastAPI backend used by the included web game.
- π Fetch World Map Data: Download world political maps at different resolutions
- πΊοΈ Country Analysis: Extract and analyze specific country polygons
- π Closest Country Detection: Find the closest countries to any geographic point
- π― Random Point Generation: Generate random points within country polygons
- π Voronoi Analysis: Create Voronoi diagrams and analyze geographic regions
- π§ TSP Solving: Solve traveling salesman problems for geographic points
- π Rich Visualizations: Create beautiful maps and charts
- π§ Modular Design: Clean, organized code structure for easy extension
- Clone this repository:
git clone https://github.com/your-username/fun-with-maps.git
cd fun-with-maps
- Install the required packages:
pip install -r requirements.txt
- (Optional) Install the CLI in editable mode:
pip install -e .
For development with additional tools:
pip install -r requirements.txt -r requirements-dev.txt
pip install -e .
pre-commit install
uv is a drop-in replacement for pip
that
speeds up dependency installation. Once uv
itself is installed you can install
the project requirements with:
pip install uv # one-time installation
./scripts/install_with_uv.sh
For development dependencies use:
./scripts/install_with_uv.sh -r requirements-dev.txt -e .
pre-commit install
After installing with pip install -e .
, the fun-with-maps-cli
command
provides access to all features. You can still run the interactive script with
python scripts/main.py
if desired.
# Show available commands
fun-with-maps-cli --help
# Download the world map
fun-with-maps-cli fetch-world-map --output world.geojson
# List countries from a map file
fun-with-maps-cli list-countries world.geojson
# Retrieve adminβ1 capitals
fun-with-maps-cli get-admin1-capitals "Argentina"
The repository ships with a Dockerfile
and a simple docker-compose.yml
configuration. These run the FastAPI server automatically so you don't need to
invoke uvicorn
yourself. Start the service with:
docker-compose up --build
This builds the image (if necessary) and launches the web game at http://localhost:8000.
If you prefer plain Docker, you can achieve the same result with:
docker build -t fun-with-maps .
docker run -p 8000:8000 fun-with-maps
Open the URL above to play the game.
from fun_with_maps import fetch_world_map, get_country_polygon, generate_random_points_in_polygon
# Fetch world map data (1:10m scale by default)
world_map = fetch_world_map()
# Get a specific country
country_polygon = get_country_polygon(world_map, "France")
# Generate random points within the country
points = generate_random_points_in_polygon(country_polygon, 100)
This project includes comprehensive test coverage using pytest. To run the tests:
Test dependencies are listed in requirements-dev.txt
:
pip install -r requirements-dev.txt
# Run all tests
pytest
# Run with verbose output
pytest -v
# Run with coverage report
pytest --cov
# Run only unit tests (excluding integration tests)
pytest -m "not integration"
# Run only integration tests
pytest -m integration
tests/test_map_fetcher.py
- Tests for world map fetching functionalitytests/test_country_analysis.py
- Tests for country polygon extraction and analysistests/test_closest_country.py
- Tests for closest country detectiontests/test_point_generation.py
- Tests for random point generationtests/test_visualization.py
- Tests for visualization functionstests/test_examples.py
- Tests for example and demo functionstests/test_integration.py
- Integration tests for complete workflowstests/conftest.py
- Shared test fixtures and configuration
The tests cover:
- β Unit Tests: Individual function testing with mocked dependencies
- β Integration Tests: End-to-end workflow testing
- β Error Handling: Graceful handling of edge cases and failures
- β Data Validation: Input/output validation and type checking
- β Performance Tests: Basic performance validation
fun-with-maps/
βββ fun_with_maps/ # Main package
β βββ core/ # Core functionality
β β βββ map_fetcher.py # World map data fetching
β β βββ country_analysis.py # Country polygon extraction
β β βββ closest_country.py # Find closest countries
β β βββ point_generation.py # Generate random points
β β βββ country_selector.py # Country selection utilities
β βββ analysis/ # Analysis algorithms
β β βββ voronoi_analysis.py # Voronoi diagram generation
β β βββ tsp_solver.py # Traveling salesman solver
β β βββ data_processing.py # Data processing utilities
β β βββ parallel_processing.py # Parallel processing tools
β βββ visualization/ # Visualization tools
β β βββ visualization.py # General visualization functions
β β βββ voronoi_visualization.py # Voronoi-specific plots
β βββ utils/ # Utility functions
β βββ utils.py # Helper utilities
βββ scripts/ # Entry point scripts
β βββ main.py # Main interactive script
β βββ cli.py # Command-line interface
β βββ diagnose_voronoi.py # Diagnostic utilities
βββ examples/ # Example code
β βββ examples.py # Usage examples
βββ tests/ # Test suite
βββ output/ # Generated outputs (gitignored)
β βββ reports/ # PDF reports
β βββ images/ # Generated images
β βββ data/ # Downloaded data
βββ docs/ # Documentation (future)
# Map fetching
from fun_with_maps.core.map_fetcher import fetch_world_map
world_map = fetch_world_map(resolution="medium")
# Country analysis
from fun_with_maps.core.country_analysis import get_country_polygon
country = get_country_polygon(world_map, "Germany")
# Point generation
from fun_with_maps.core.point_generation import generate_random_points_in_polygon
points = generate_random_points_in_polygon(country, count=1000)
# Closest country detection
from fun_with_maps.core.closest_country import find_closest_countries
closest = find_closest_countries(world_map, points)
# Voronoi analysis
from fun_with_maps.analysis.voronoi_analysis import get_admin1_capitals
capitals = get_admin1_capitals("France")
# TSP solving
from fun_with_maps.analysis.tsp_solver import solve_tsp
tour, cost = solve_tsp(capitals)
# Basic visualization
from fun_with_maps.visualization.visualization import visualize_country_polygon
visualize_country_polygon(country, "Germany")
# Voronoi visualization
from fun_with_maps.visualization.voronoi_visualization import display_voronoi_diagram
display_voronoi_diagram(country, capitals, "Germany")