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

OSM2 VectorTiles lat/long to tile

2

After a frustrating few days I came to the conclusion that the Slippy Map Wiki only works for raster tiles, not for OSM2VectorTiles data. I can work with the data once I find the correct tile_data BLOB, but actually locating the correct tile via a user lat/long is problematic. The equations given in the wiki above identify raster tiles correctly, but I'm trying to get this working for an offline version of OpenStreetMap rendering/navigation (meaning I can't just use mapbox's JS API to convert it, also I can't find where the conversion happens in the github repo).

Can anyone offer any advice as to how I can convert a lat/long to the correct tile in an OSM2VT SQLite database?

The query, that works for raster tiles, may be of some use:

    public void UserQuery()
    {
        Console.Write("Please enter a latitude value: ");
        double userLat = Convert.ToDouble(Console.ReadLine());
        Console.Write("Please enter a longitude value: ");
        double userLong = Convert.ToDouble(Console.ReadLine());

        _merc.TileLat = Math.Floor((1.0 - Math.Log(Math.Tan(DegreesToRadians(userLat)) + 1.0 / Math.Cos(DegreesToRadians(userLat))) / Math.PI) * Math.Pow(2, ZoomLevel));
        _merc.TileLong = Math.Floor((userLong + 180.0) / 360.0 * Math.Pow(2, ZoomLevel));
    }

asked 07 Jul '16, 11:01

JamesGould's gravatar image

JamesGould
19691020
accept rate: 33%


One Answer:

2

You may find the following code from tilemaker relevant:

https://github.com/systemed/tilemaker/blob/master/src/coordinates.cpp

I don't have any experience with osm2vectortiles because I find Docker and npm about as appealing as sandpapering my eyeballs, but I presume it uses the same tile layout.

answered 07 Jul '16, 14:00

Richard's gravatar image

Richard ♦
30.9k44279412
accept rate: 18%

Source code available on GitHub .