Registry / data / tilemapbase

tilemapbase

JSON →
library0.4.7pypypi✓ verified 87d ago

TileMapBase is a Python library that enables the use of OpenStreetMap and other WMTS tiles as basemaps within Matplotlib figures. It simplifies fetching, caching, and rendering geographical tiles, allowing users to overlay their data on real-world maps. Currently at version 0.4.7, it is actively maintained with periodic updates.

pip install tilemapbase
INSTALL
IMPORT
SIG · TILEMAPBASE
T
tilemapbase
datapythonv0.4.7
Install
3.6s avg
Import
634ms
Disk
40MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.4.7 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.655s · 42.3MB
glibc
py 3.10–3.910 runs
installs and imports cleanly · install 3.6s · import 0.612s · 43MB
40MB installed
● package 40MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

tilemapbase
✓ import tilemapbase
✗ import tilemapbase

This quickstart demonstrates how to initialize TileMapBase, define a geographical extent, create a Matplotlib figure and axes, add OpenStreetMap tiles using PlottingContext, and overlay a data point (London Eye) correctly using the `tilemapbase.crs_geographic` transform.

import matplotlib.pyplot as plt import tilemapbase # Crucial initialization step for tilemapbase. Set a user_agent to avoid 403 errors. # python_accelerated=True can speed up rendering if numba is installed. tilemapbase.init(python_accelerated=True, user_agent="my-tilemapbase-app") # Define the map extent [lon_min, lon_max, lat_min, lat_max] extent = [-0.20, 0.05, 51.45, 51.55] # Example: Central London fig, ax = plt.subplots(figsize=(10, 10), dpi=100) ax.set_xlabel("Longitude") ax.set_ylabel("Latitude") ax.set_title("London with TileMapBase") # Create a PlottingContext. This sets up the matplotlib axes for the map projection. # 'merc' is the standard projection for web maps. plot_context = tilemapbase.plotting.PlottingContext( extent, ax=ax, proj="merc" ) # Add OpenStreetMap tiles to the axes tilemapbase.plotting.add_tile_wmts( ax, url=tilemapbase.get_providers_as_dict()["OpenStreetMap"], zoom=13 ) # Set axes limits based on the PlottingContext's projected extent ax.set_xlim(plot_context.x_min, plot_context.x_max) ax.set_ylim(plot_context.y_min, plot_context.y_max) ax.set_aspect(plot_context.get_aspect()) # Example: Overlay a point (London Eye) in geographic coordinates london_eye_lon, london_eye_lat = -0.1106, 51.5033 ax.plot( london_eye_lon, london_eye_lat, 'o', color='red', markersize=8, transform=tilemapbase.crs_geographic, # Crucial: plot in geographic coordinates label="London Eye" ) ax.legend() plt.show()
Debug
Known issues
gotchaFailing to call `tilemapbase.init()` or not providing a `user_agent` string can lead to HTTP 403 (Forbidden) errors from tile servers.
fix
Always call `tilemapbase.init()` at the start of your script and provide a unique `user_agent` string, e.g., `tilemapbase.init(user_agent="my-app-name/1.0")`.
affects: All versions
breakingThe `map_to_pixels` and `pixels_to_map` functions were moved from `tilemapbase.transform` directly to the `tilemapbase` top-level module in version 0.4.0.
fix
Update your imports: change `from tilemapbase.transform import ...` to `import tilemapbase` and then use `tilemapbase.map_to_pixels(...)` or `tilemapbase.pixels_to_map(...)`.
affects: 0.4.0+
gotchaWhen overlaying your own data (e.g., points, lines) on a TileMapBase map, you must correctly handle coordinate systems. Matplotlib's default coordinates won't match the projected map tiles.
fix
If your data is in WGS84 (latitude/longitude), use `transform=tilemapbase.crs_geographic` with Matplotlib plotting functions (e.g., `ax.plot(lon, lat, transform=tilemapbase.crs_geographic)`).
affects: All versions
gotchaAggressive tile fetching or ignoring tile server terms of service can lead to IP bans or temporary blocks from tile providers.
fix
TileMapBase uses `cachecontrol` for caching, which helps. Ensure your `user_agent` is identifiable and respect providers' usage policies. For heavy usage, consider self-hosting tiles or using a commercial provider with an API key.
affects: All versions
Upgrade
Version history
0.4.7latest on PyPI · released Jan 15, 2021
Audit
Dependencies
matplotlibrequiredRequired for plotting and rendering maps.
PillowrequiredUsed for image processing and handling of tile data.
requestsrequiredFor making HTTP requests to fetch map tiles from servers.
Agent activity
22 hits · last 30 days
node
20
OpenAI (training)
1
Resources
tilemapbase — pip install tilemapbase · libregistry