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

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%


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.

permanent link

answered 30 Jul '11, 17:35

petschge's gravatar image

petschge
8.3k217398
accept rate: 21%

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
×98
×60

question asked: 30 Jul '11, 13:58

question was seen: 7,684 times

last updated: 30 Jul '11, 17:35

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