Skip to main content

API-compatible replacement for the Mercantile library with full type safety.

Project description

tilemath

A modern, type-safe Python library for spherical mercator coordinate and tile utilities. Designed as an API-compatible replacement for mercantile with full type safety and minimal dependencies.

Features

  • Full Type Safety: Complete type annotations for all functions and classes
  • API Compatible: Drop-in replacement for mercantile with the same interface
  • Minimal Dependencies: Zero runtime dependencies for core functionality
  • Modern Python: Built for Python 3.10+ with modern language features
  • Fast: Optimized implementations of coordinate transformations and tile operations

Installation

pip install tilemath

Or with uv:

uv add tilemath

Quick Start

import tilemath.mercantile as mercantile

# Convert longitude/latitude to tile coordinates
tile = mercantile.tile(-122.4194, 37.7749, 12)  # San Francisco
print(f"Tile: {tile.x}, {tile.y}, {tile.z}")

# Get bounding box for a tile
bbox = mercantile.bounds(tile)
print(f"Bounds: {bbox}")

# Convert tile to quadkey
quadkey = mercantile.quadkey(tile)
print(f"Quadkey: {quadkey}")

API Reference

The library provides the same API as mercantile, including:

  • tile(lng, lat, zoom) - Get tile containing a longitude/latitude
  • bounds(tile) - Get bounding box of a tile
  • xy(lng, lat) - Convert longitude/latitude to web mercator coordinates
  • lnglat(x, y) - Convert web mercator coordinates to longitude/latitude
  • quadkey(tile) - Convert tile to Microsoft quadkey
  • quadkey_to_tile(quadkey) - Convert quadkey to tile
  • tiles(west, south, east, north, zooms) - Generate tiles for a bounding box
  • children(tile) - Get child tiles
  • parent(tile) - Get parent tile
  • neighbors(tile) - Get neighboring tiles

Type Safety

tilemath adds complete type annotations:

from tilemath.mercantile import Tile, Bbox

# All functions have proper type hints
def process_tile(tile: Tile) -> Bbox:
    return bounds(tile)

# Type checkers will catch errors
tile = Tile(x=1, y=2, z=3)
bbox: Bbox = process_tile(tile)

Requirements

  • Python 3.10 or higher
  • No runtime dependencies

Development

This project uses uv for dependency management and development workflows.

Setup

# Clone the repository
git clone https://github.com/eddieland/tilemath.git
cd tilemath

# Install dependencies
make install

Running Tests

# Run all tests
make test

# Run specific test file
uv run pytest tests/test_mercantile_upstream.py -v

Code Quality

# Run linting and type checking
make lint

# Run everything (install, lint, test)
make

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

Acknowledgments

This project is inspired by and aims to be compatible with mercantile by Sean Gillies and contributors.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tilemath-0.1.0.tar.gz (47.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tilemath-0.1.0-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file tilemath-0.1.0.tar.gz.

File metadata

  • Download URL: tilemath-0.1.0.tar.gz
  • Upload date:
  • Size: 47.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for tilemath-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7f78f700591916bdf41756a4aa5bacf829a8fc1e988c1bab54eb9376d6b7e98a
MD5 4ba9512a015a832b2d6626aa957577fb
BLAKE2b-256 513dbefa8bab3895c63d9fdcb7d4a4baa9792030e75165b9cb79af8203c5a108

See more details on using hashes here.

Provenance

The following attestation bundles were made for tilemath-0.1.0.tar.gz:

Publisher: publish.yml on eddieland/tilemath

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tilemath-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: tilemath-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for tilemath-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e0969cd22c1ffe1c2b5ca973ba00259dc55f04a48630c6162a006c93ee078281
MD5 7a49bf0070e367051474511e54da2b97
BLAKE2b-256 b39063951cb041538fdbdc634276fa17277bfa55c578a6361af861063965ad10

See more details on using hashes here.

Provenance

The following attestation bundles were made for tilemath-0.1.0-py3-none-any.whl:

Publisher: publish.yml on eddieland/tilemath

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page