- Go to https://www.openstreetmap.org/export#map=11/48.6129/38.2221
- Choose your area for export
- Put export bounding box longitude and latitude into
calc_tiles.pyand run it to calculate which tiles to has to be downloaded - Create
tilesdirectory - Put calculated coordinates into
download_tiles.jsand run it do download tiles (couldn't make downloading work in Python) - Put calculated coordinates into
stitch_tiles.pyand run it - The output will be stored in
map.pngfile
Created
May 20, 2023 17:00
-
-
Save roman01la/35171dfcf2b64983486dcb1c2f844be9 to your computer and use it in GitHub Desktop.
Export large scale map from OSM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import math | |
| zoom = 14 | |
| lon1 = 48.7752 | |
| lon2 = 48.4675 | |
| lat1 = 37.8500 | |
| lat2 = 38.5984 | |
| def lat_to_x(lat, zoom): | |
| return int((lat + 180.0) / 360.0 * (1 << zoom)) | |
| def lon_to_y(lon, zoom): | |
| return int((1.0 - math.log(math.tan(math.radians(lon)) + 1 / | |
| math.cos(math.radians(lon))) / math.pi) / 2.0 * (1 << zoom)) | |
| x1 = lat_to_x(lat1, zoom) | |
| x2 = lat_to_x(lat2, zoom) | |
| y1 = lon_to_y(lon1, zoom) | |
| y2 = lon_to_y(lon2, zoom) | |
| print(x1, x2, y1, y2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fs = require("fs"); | |
| const axios = require("axios"); | |
| const coords = []; | |
| for (let idx = x1; idx <= x2; idx++) { | |
| for (let jdx = y1; jdx <= y2; jdx++) { | |
| coords.push([idx, jdx]); | |
| } | |
| } | |
| urls.map(([idx, jdx], iidx) => | |
| axios(`https://tile.openstreetmap.org/14/${idx}/${jdx}.png`, { | |
| responseType: "arraybuffer", | |
| }).then((response) => { | |
| console.log(iidx, urls.length); | |
| const buff = Buffer.from(response.data, "binary"); | |
| fs.writeFileSync(`tiles/${idx}_${jdx}.png`, buff); | |
| }) | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from PIL import Image | |
| x1 = 0 | |
| x2 = 0 | |
| y1 = 0 | |
| y2 = 0 | |
| width = (x2 - x1 + 1) * 256 | |
| height = (y2 - y1 + 1) * 256 | |
| result_image = Image.new('RGB', (width, height)) | |
| for x in range(x1, x2 + 1): | |
| for y in range(y1, y2 + 1): | |
| tile_image = Image.open(f"tiles/{x}_{y}.png") | |
| result_image.paste(tile_image, ((x - x1) * 256, (y - y1) * 256)) | |
| result_image.save("map.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment