Skip to content

Enhance Map Tile Downloader with Multi-Zoom Support, Parallel Downloads and API Key Management #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BAIDU_API_KEY=your_api_key_here
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
*.zip
*.tar
*.gz
*.7z

!map_r.png
!map_s.jpg
!map_s.jpg

.venv
venv
.env
60 changes: 45 additions & 15 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,74 @@

## Getting Started

### Environment Setup

This project requires a Baidu Maps API key. Create a `.env` file in the root directory with your API key:

```
BAIDU_API_KEY=your_api_key_here
```

You can copy the provided `.env.example` file and replace the placeholder with your actual API key:

```bash
cp .env.example .env
# Edit the .env file to add your API key
```

### Installation

Install the required dependencies:

```bash
pip install -r requirements.txt
```

### Download Baidu Maps tiles

Edit `download_tiles.py` to specify the area and the zoom level you want.
Edit `download_tiles.py` to specify the area, zoom levels, and whether you want satellite or road maps:

```py
zoom = 8
zoom_levels = list(range(8, 18)) # Download tiles for zoom levels 8 through 17

lat_start, lon_start = 31.717714,105.540665
lat_stop, lon_stop = 39.659668,111.262224
lat_start, lon_start = 30.763961, 119.926525
lat_stop, lon_stop = 32.053984, 121.408616

satellite = True # roads if false
satellite = False # Set to True for satellite images, False for road maps

download_tiles(zoom, lat_start, lat_stop, lon_start, lon_stop, satellite)
download_tiles(zoom_levels, lat_start, lat_stop, lon_start, lon_stop, satellite)
```

You can easily find Baidu coordinates with [http://api.map.baidu.com/lbsapi/getpoint/](http://api.map.baidu.com/lbsapi/getpoint/).

Then, run `$ python download_tiles.py` and get individual tiles in `tile` folder.

The script now supports:
- Downloading multiple zoom levels in a single run
- Automatic retries for failed downloads (up to 3 times by default)
- Progress tracking with failed download counts
- Parallel downloading using threads

### Merge Baidu Maps tiles

Edit `merge_tiles.py` to specify the area and the zoom level you want, it's just the same as before.
Edit `merge_tiles.py` to specify the area and zoom level for the tiles you want to merge:

zoom = 19
```py
zoom = 19

lat_start, lon_start = 31.022547,121.429391
lat_stop, lon_stop = 31.041453,121.45749
lat_start, lon_start = 31.022547,121.429391
lat_stop, lon_stop = 31.041453,121.45749

satellite = True # roads if false

Then, run `$ python merge_tiles.py` and get `map_s.jpg` for satellite or `map_r.png` for roads.
satellite = True # Set to False for road maps
```

Then, run `$ python merge_tiles.py` and get `map_s.jpg` for satellite or `map_r.png` for road maps.

Note: merging the tiles requires [Python Image Library](http://www.pythonware.com/products/pil/).
Note: merging the tiles requires [Python Image Library (PIL)](https://python-pillow.org/).

## Reference

- <http://api.map.baidu.com/lbsapi/getpoint/>
- <http://developer.baidu.com/map/jsdemo.htm#a1_2>
- <http://developer.baidu.com/map/reference/index.php>
- <http://lbsyun.baidu.com/index.php?title=jspopular>
- <http://lbsyun.baidu.com/index.php?title=jspopular>
Loading