This is a static archive of our old OSM Help Site. Please post any new questions and answers at community.openstreetmap.org.

Point to pixel ratio in open street map image

1
1

I am planning to use .osm data for solving graph problems (TSP, VRP, etc.). After solving routes using the osm xml data, I plan to plot the results on a osm image using markers for vertices and paths so the end user could see the routes in a readable and comprehensible image.

The problem is the data given on osm xml data is only latitude longitude values. So how is it scaled in the image given zoom level and bounding box? Or any suggestions on solving this problem?

asked 30 Jul '11, 13:58

jplaras's gravatar image

jplaras
41346
accept rate: 0%


One Answer:

8

The tiles offered by the OpenStreetMap tile servers are in the spherical mercator projection. As described in the wiki you can convert from latitude to longitude using the following formulae:

n = 2 ^ zoom
xtile = ((lon_deg + 180) / 360) * n
ytile = (1 - (log(tan(lat_rad) + sec(lat_rad)) / pi)) / 2 * n

If you do so you normally only keep the integral part of xtile and ytile which determine the name of the tile in the http://a.tile.openstreetmap.org/zoom/xtile/ytile.png naming scheme.

You can however keep the fractional part of xtile and ytile and multiply by 256 - the width of the tile - and derive which pixel of the tile contains the longitude and latitude that you started with. This allows you to plot your coordinates on top of standard OpenStreetMap tiles.

answered 30 Jul '11, 17:35

petschge's gravatar image

petschge
8.3k217398
accept rate: 21%