I have downloaded multiple tiles from OpenStreetMaps, and I need to join all the tiles to form a single image, the truth is I am quite new to this topic and I do not know a lot.
Until now I made a small script to join the tiles, the objective is to join the tiles so that they coincide with each other, so that they form an image of the map region ... with the script I managed to join the tiles but not the problem is that they do not match.
I share my script and I would appreciate any help you can give me.
This is my scritp:
import numpy as np
from PIL import Image
import glob
def join_images_horizontally(imgs):
'''
Esta función une imagenes horizontalmente.
'''
#crea dos listas: una para alturas y otra para anchuras
widths, heights = zip(*(i.size for i in imgs))
width_of_new_image = sum(widths)
height_of_new_image = min(heights) #toma la altura minima
# crear nueva imagen
new_im = Image.new('RGB', (width_of_new_image, height_of_new_image))
new_pos = 0
for im in imgs:
new_im.paste(im, (new_pos,0))
new_pos += im.size[0] #position for the next image
new_im.save('/home/orlando/git/orlando3dmaps/src/imghorizontal.png')
def join_images_vertically(imgs):
'''
Esta función une imagenes verticalmente.
'''
#crea dos listas: una para alturas y otra para anchuras
widths, heights = zip(*(i.size for i in imgs))
width_of_new_image = min(widths) #toma la altura minima
height_of_new_image = sum(heights)
# ccrear nueva imagen
new_im = Image.new('RGB',(width_of_new_image, height_of_new_image))
new_pos = 0
for im in imgs:
new_im.paste(im, (0, new_pos))
new_pos += im.size[1] #posicion para la siguiente imagen
new_im.save('/home/orlando/git/orlando3dmaps/src/imgvertical.png')
def main():
'''
Inicializa el código.
'''
# Abrir archivos de imagen
imgs = [Image.open(im) for im in list_im]
###fusionar imagenes horizontalmente
#join_images_horizontally(imgs)
###fusionar imagenes verticalmente
join_images_vertically(imgs)
#lista de imagenes
list_im = glob.glob("/home/orlando/git/orlando3dmaps/src/tiles/11/494/*.png") #change it to use your images
if __name__ == '__main__':
'''
Este programa fusiona imagenes vertical y horizontalmente.
'''
main()
This generates an output like the following image: enter image description here
The way to join is fine, but the problem as I said is that they are not in the correct order, they do not match the map.
This is how it should look:enter image description here
Thank you in advance for your help.