Fig's Homepage
Map Downloader V2

Map Downloader V2

V1 of my map downloading script worked well, but it was confined to command line use which limited it's usability.

This new version uses the NiceGUI UI framework for Python to create a web-based interface for the download logic.

mapapp.jpg
Screenshot of version 2 of the map app showing the UI with a naviagable map

Code Structure

For readablity, I've separated out the dataclass declarations, tilemap data, and utility functions into their own files and imported them into the main file.

classes.py

Tiles:

x_min: int = 0
x_max: int = 0
y_min: int = 0
y_max: int = 0

AppState:

lat: float = 0.0
lon: float = 0.0
zoom: int = 15
url_pattern: str = tile_maps[0].url
format: str = "png"
tile_search_progress: float = 0.0
tile_download_progress: float = 0.0
tile_stitch_progress: float = 0.0
status: str = ""
filename: str = "output.png"

tile_maps.py

Tile properties for all the various tile maps are stored in tile_maps.py

name: str
url: str
min_zoom: int
max_zoom: int

utils.py

utils.py is home to various constants.

geocode_place
Uses the geocode.maps.co api to convert place names and postcodes to latitude and longitude.
deg2num
Takes latitude and longitude and zoom level, and returns the X and Y tile coordinates.
rect_coords_to_tiles
Converts 4 sets of latitude and longitude (bounding box corners) and returns the corner tile coordinates. The corners are labled in the order: bottom left, top left, top right, bottom right.
find_latest_tile
Checks for existance of a tile at a URL and returns the X and Y tile coordinates along with the URL.
donwload_tile
Saves tile images locally as PNG files.
stitch_in_chunks
Join the saved PNGs together in a grid and export the resulting image to a file.