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

I'm trying to interact with .mbtiles databases to pull street level data relating to a lat/long query. I do not need to render the map itself, just access the information relating to the particular tile.

At the moment I'm struggling to find a vector tile that extends past zoom_level 14, which is the max for the SQLite databases over at OSM2VectorTiles. I wanted to download raw OSM data, convert it to an SQLite database and then query with it that way (if it provides a zoom level beyond 14, I need residential street names etc) but I'm not sure if that's the right path.

Is there a particular way to query a lat/long in an offline client which pulls back vector data from the tile and then print it into a console?

I've been posting both here and on gis.stackexchange.com for a few days with varying problems but everything seems to be a dead end. Any lat/long values that I query using my code (below) relate to a raster tile based database which isn't functioning as intended when using vector tile information.

My current query to convert a lat/long and read data from the tile_data BLOB found in an .mbtiles database:

    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));
    }

    private double DegreesToRadians(double angle)
    {
        return Math.PI * angle / 180;
    }

asked 07 Jul '16, 13:22

JamesGould's gravatar image

JamesGould
19691020
accept rate: 33%


It seems to me that the vector tile route is unnecessarily convoluted. Download a suitable OSM PBF data extract, load it into a PostGIS database with osm2pgsql, and then make your queries against that. You don't say which "street level data" you want to "pull" but if it's the name and geometry of a street, you'd be doing something like

SELECT name, highway, way 
FROM planet_osm_line
WHERE ST_DWITHIN(ST_TRANSFORM(ST_SETSRID(ST_MAKEPOINT(mylon, mylat),4326),3857), way, 100)
AND highway IS NOT NULL
ORDER BY ST_DISTANCE(ST_TRANSFORM(ST_SETSRID(ST_MAKEPOINT(mylon, mylat),4326),3857), way)
LIMIT 10;

This will look for all street geometries coming near 100 Mercator units (that's roughly metres but depends on where you are) of your point, and list the 10 that come closest.

Another option of doing the same is using the Nominatim geocoder and its reverse geocoding capability; it will essentially do the same internally, but give you a nicer output that includes an address hierarchy.

Trying to use vector tiles for this seems a bit error-prone.

permanent link

answered 07 Jul '16, 14:01

Frederik%20Ramm's gravatar image

Frederik Ramm ♦
82.5k927201273
accept rate: 23%

edited 07 Jul '16, 15:07

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:

×45
×25
×18
×8

question asked: 07 Jul '16, 13:22

question was seen: 3,897 times

last updated: 07 Jul '16, 15:07

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