Skip to content

🗺 A set of CLI tools for working with .mbtiles map files, including a map downloader.

License

Notifications You must be signed in to change notification settings

ZUB3C/sqlitedb-map-tools

 
 

Repository files navigation

🗺 SQLiteDB Map Tools

License Python Versions Status MyPy Ruff

A set of CLI tools for working with .mbtiles map files, including a map downloader.

  • mbtiles2sqlitedb: Converts .mbtiles format to .sqlitedb format, compatible with OsmAnd and Locus.
  • sqlitedb-cut: Extracts a rectangular section of a map from a .sqlitedb file into a separate map file.
  • sqlitedb-merge: Merges multiple .sqlitedb map files into a single file.
  • nakarteme-dl: Downloads .mbtiles map files from nakarte.me.

Additionally, you can compress tiles using JPEG to reduce file size (see examples).

📦 Installing

Python 3.10 or above is required.

Using pipx (recommended)

pipx install git+https://github.com/ZUB3C/sqlitedb-map-tools.git

Using pip

pip install git+https://github.com/ZUB3C/sqlitedb-map-tools.git

🌿 Convert .mbtiles to .sqlitedb

mbtiles2sqlitedb [OPTIONS] INPUT_FILE OUTPUT_FILE

Converts .mbtiles format to .sqlitedb format suitable for OsmAnd and Locus.

-f, --force                 Override the output file if it exists.
-j, --jpeg-quality INTEGER  Convert tiles to JPEG with the specified
                            quality.

Examples

Simple:

mbtiles2sqlitedb input.mbtiles output.sqlitedb

Convert tiles to JPEG with compression level set to 80:

mbtiles2sqlitedb -j 80 input.mbtiles output.sqlitedb

✂️ Cut .sqlitedb map

sqlitedb-cut [OPTIONS] INPUT_FILE OUTPUT_FILE

Extracts a rectangular section of a map from a .sqlitedb file into a separate map.

-l, --upper-left FLOAT...    Coordinates of the upper-left corner of the
                             section to be extracted.  [required]
-r, --bottom-right FLOAT...  Coordinates of the bottom-right corner of the
                             section to be extracted.  [required]
-f, --force                  Override the output file if it exists.

Example

This command extracts a rectangular section from map.sqlitedb and saves it as map-fragment.sqlitedb, using the specified coordinates for the upper-left and bottom-right corners:

sqlitedb-cut map.sqlitedb map-fragment.sqlitedb --upper-left 44.00961 42.23831 --bottom-right 43.15811 43.01285

🧩 Merge .sqlitedb maps

sqlitedb-merge [OPTIONS] INPUT_FILES OUTPUT_FILE

Merges multiple .sqlitedb map files into a single file.

If multiple files contain tiles with the same coordinates, the tile from the first file in the argument list will be used.

-f, --force  Override the output file if it exists.

Example

sqlitedb-merge map1.sqlitedb map2.sqlitedb merged-map.sqlitedb

⬇️ Download nakarte.me maps

nakarteme-dl [OPTIONS] MAPS...

Downloads .mbtiles map files from tiles.nakarte.me.

Use all as the map name to download all available maps.

-o, --output DIRECTORY  Directory where maps will be downloaded.
-f, --force             Override the output file if it exists.

Example

nakarteme-dl -o mbtiles topo500 topo1000

⬇️ Download raster map

raster-map-dl [OPTIONS] OUTPUT_FILE

Download tiles from remote server to .sqlitedb file.

-f, --force                     Override the output file if it exists.
-u, --url-mask TEXT             Server url mask from where you want to
                                download tiles. It should have `{x}`, `{y}`
                                and `{z}` in it. For example, https://tile.o
                                penstreetmap.org/{z}/{x}/{y}.png.
                                [required]
-l, --upper-left FLOAT...       Coordinates of the upper-left corner of the
                                section to be extracted.  [required]
-r, --bottom-right FLOAT...     Coordinates of the bottom-right corner of
                                the section to be extracted.  [required]
--min-zoom INTEGER              Minimum zoom with which tiles will be
                                downloaded. By default 0.
--max-zoom INTEGER              Minimum zoom with which tiles will be
                                downloaded. By default 18.
--max-rpc, --max-requests-per-second INTEGER
                                Max requests per second limit. By default no
                                limit.
-t, --timeout INTEGER           Request timeount in seconds. By default 300.
--max-retry-count INTEGER       Maximum number of retries to server if
                                timeout is reached. By default 10.
-c, --chuck-size INTEGER        Size of a chunk with tiles stored in RAM.
                                After filling a chunk with tiles, they are
                                saved to .sqlitedb output file. By default
                                2048

Example

raster-map-dl opentopomap-elbrus-region.sqlitedb -u "https://c.tile.opentopomap.org/{z}/{x}/{y}.png" --min-zoom 10 --max-zoom 16 --upper-left 44.00961 42.23831 --bottom-right 43.15811 43.01285

🔧 Development

Install Rye by following the installation guide.

Use rye sync to install dependencies and required Python version.

Use rye check --fix and rye fmt to lint and format code. Assumed to be run before each commit to guarantee code quality.

Use rye run basedpyright to ensure typing is correct.

📜 License

This project is licensed under the GPLv3+ license - see the license file for details.

About

🗺 A set of CLI tools for working with .mbtiles map files, including a map downloader.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages

  • Python 100.0%