NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

Hello,

I'm relatively new to this world. I think my objective is pretty simple but I'm having a little trouble trying to achieve it.

What I need: take a part of my city and generate the corresponding tiles for use them offline with GPS data. Basically draw a point at the position I'm in.

What I'm doing: first, I'm locating my area with OSM data using Maperitive. I manually draw a bounding area and I generate the tiles. So far everything works fine.

The problem: the boundaries I draw don't match with the real tiles boundaries. The resulting JSON contains the boundaries I draw, but not the real tiles boundaries, plus the tiles also don't have matching boundaries between different zoom levels. This makes sense because of the standard division of the world. Just in case, I illustrate with some images that I found and that describe the situation:

alt text

alt text

alt text

The question: is there any way to crop an area and get all the necessary tiles to make them match with the original boundaries?

Greetings.

asked 28 Feb '22, 10:06

Sergio's gravatar image

Sergio
11112
accept rate: 0%


After reading and reading I ended up by resolving my particular problem. The first point is that I wasn't giving it the right focus.

It wasn't about the "real tile boundaries" I was talking about, it was about that the tiles are the boundaries. Each tile represent an XYZ point on the global map, and the way Maperitive downloads and stores them is that. It creates the first folder (Z), the sub folders (X) and the files (Y). The nomenclature of every data is the value for the axis.

Solution: for knowing in what tile my coordinates were, I just had to transform my Lat, Lon values as the documentation says. Finally, knowing that the image files are 256x256 and starting from the upper left corner, the only thing needed is to know where the point is inside the image multiplying the floating part by 256.

I coded a Python solution to get this knowing Lat, Lon:

import math
lat_deg = 43.253192
lon_deg = -2.914479
zoom = 19
lat_rad = math.radians(lat_deg)
n = 2.0 ** zoom
xtile = float((lon_deg + 180.0) / 360.0 * n)
ytile = float((1.0 - math.asinh(math.tan(lat_rad)) / math.pi) / 2.0 * n)
print("Tesela para ", lat_deg, lon_deg)
print("--------------------------------------")
print("Carpeta raiz:", zoom)
print("Sub carpeta:", (int)(xtile))
print("Fichero de imagen", (int)(ytile))
print("Pixel X en tesela: ", (xtile % 1)*256)
print("Pixel Y en tesela: ",  (ytile % 1)*256)

And that's all. I hope this helps someone with no experiencie like me.

permanent link

answered 01 Mar '22, 02:21

Sergio's gravatar image

Sergio
11112
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×710
×48

question asked: 28 Feb '22, 10:06

question was seen: 1,220 times

last updated: 01 Mar '22, 02:21

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum