Pixel-level long/lat calculations, and a database question!

One (hopefully) simple, one (probably) not!

  1. I’ve read the page at http://wiki.openstreetmap.org/index.php/Slippy_map_tilenames to I can easily get the Tile X/Y coordinates for a given long/lat/zoom. However, how can I calculate the pixel-level X, Y position within that tile for the exact long/lat position?

For example, the tile at 51.4977798462, -0.173695996404 at level 5 is X=15, Y=10. But which pixel that tile best describes the given long / lat at the given zoom level?

  1. I was hoping to load some of the map data into a database which the aim of creating a vector-based rendering engine. I know, it’s a lot to hope for, but I don’t suppose there are tools available that will import usable osm data into a database (I’ll be wanting to use SQL Server, being Windows-based), including such information which will let me determine which geometry I need to draw (i.e. bounding boxes and min/max zoom levels).

Any help would be greatly appreciated. Thanks in advance. :slight_smile:

For your second question take a look at how the mapnik layer is rendered.
http://wiki.openstreetmap.org/index.php/Mapnik
Osm data is imported into a PostGIS database using osm2pgsql. Perhaps osm2pgsql can be adapted to talk to SQL Server.