Skip to content

dbell1867/map_coverage

Repository files navigation

UK Map Coverage with 1-Mile Radius Circles

This Marimo notebook calculates how many 1-mile radius circles are needed to cover the entire United Kingdom, saves the circle center points to a SQLite database, and visualizes them on an interactive map.

Features

  • Fetches actual UK boundary data from GeoJSON sources
  • Calculates optimal grid spacing using hexagonal-like packing (�3 × radius H 1.732 miles)
  • Filters points to only include those within UK boundaries
  • Stores all circle center coordinates (latitude/longitude) in SQLite database
  • Visualizes coverage on an interactive Folium map
  • Shows detailed statistics about coverage

Installation

  1. Ensure you have Python 3.13+ and uv package manager installed
  2. Install dependencies:
uv sync

Usage

Run the Marimo notebook:

uv run marimo edit main.py

This will open the notebook in your browser where you can:

  • See the step-by-step calculation process
  • View the total number of circles needed
  • Explore the interactive map visualization
  • Access the database with all circle centers

Database

The circle center points are saved to uk_coverage.db with the following schema:

CREATE TABLE circle_centers (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    latitude REAL NOT NULL,
    longitude REAL NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)

Query the Database

You can query the database using Python:

import sqlite3

conn = sqlite3.connect('uk_coverage.db')
cursor = conn.cursor()

# Get all circle centers
cursor.execute("SELECT latitude, longitude FROM circle_centers")
points = cursor.fetchall()

print(f"Total circles: {len(points)}")
conn.close()

How It Works

  1. UK Boundary: Fetches actual UK administrative boundaries from GeoJSON data
  2. Grid Generation: Creates a hexagonal-like grid with 1.732-mile spacing between centers
  3. Filtering: Only keeps points that fall within UK boundaries
  4. Database Storage: Saves all valid circle centers to SQLite
  5. Visualization: Displays a sample of circles on an interactive map (showing 500 circles to avoid performance issues)

Adjusting Parameters

To change the circle radius or coverage area, modify these variables in main.py:

  • radius_miles: Change the circle radius (line 81)
  • spacing_miles: Adjust grid spacing for different coverage patterns (line 82)
  • UK boundary URL can be changed in the get_uk_boundary() function (line 43)

Technical Details

  • Uses hexagonal-like packing with spacing = radius × �3 for optimal coverage
  • Coordinates are in WGS84 (EPSG:4326) decimal degrees
  • Distance calculations account for Earth's curvature at UK latitude (~55°N)
  • Map visualization samples 500 circles for performance (all points are in database)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages