A Python program that downloads a rectangular map region by its geographic coordinates and saves it as a PNG image. It works by downloading map tiles at a given zoom level and cropping border tiles to fit the region.
This program should work with any raster map that uses Web Mercator, including Google Maps, Esri and OpenStreetMap.
Please note that downloading map tiles without using the API may violate the map service's terms of use.
Make sure you have Python 3 installed.
Install the required packages.
pip install -r requirements.txt
Run main.py
.
On the first run, the program will create a preferences file next to main.py
. Run the program again. Now you will be asked to enter the coordinates and zoom level in the command line.
-
Enter the coordinates of the top-left and bottom-right corners of a rectangular region as decimal degrees (latitude before longitude) with any separator you want, e.g.
40.612123, -73.895381
. -
Enter the zoom level at which you want to get the image. This article explains how it affects the scale and resolution.
Google Maps satellite imagery will be used by default.
"url"
is the URL template that the program will use to download map tiles."tile_size"
is the size of a single tile in pixels. The default is 256."tile_format"
determines how tiles will be decoded as well as the number of channels in the final image. The default is"jpg"
. Use"png"
for transparent tiles, such as in roads-only layers."dir"
is the directory where your images will be saved. If the directory doesn't exist, it will be created automatically."headers"
are the headers that the program will use to make HTTP requests.
Optional:
preferences.json
can also be used to specify the coordinates and zoom level. If you leave one or more of the following fields empty, you will be asked to use the command line instead.
"tl"
and"br"
are the coordinates of the top-left and bottom-right corners of a rectangular region."zoom"
is the zoom level.
If you encounter any problems with the program, feel free to open an issue.
Here are some tile URLs that you can use:
- Google maps satellite imagery:
https://mt.google.com/vt/lyrs=s&x={x}&y={y}&z={z}
(Default"url"
) - Google Maps raster road map:
https://mt.google.com/vt/lyrs=m&x={x}&y={y}&z={z}
- OpenStreetMap:
https://tile.openstreetmap.org/{z}/{x}/{y}.png
- Esri satellite imagery:
https://services.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}
If you need to use tiles from a different map service, you can try to get the URL by inspecting network activity in your browser. Open developer tools (Ctrl+Shift+I) and go to the Network panel. Now, if you scroll the map, it will show you what resources are being loaded. Find a tile, copy the URL and replace its coordinate and zoom values with {x}
, {y}
and {z}
.
Images in high resolution: https://mega.nz/folder/7sxTwALS#n2bFCYk9JsiU7nbVQH-ntw