Add SQL index in .mbtiles generated #822
-
Currently, I'm using .mbtiles as my tiles source (for display purpose) but also as a database to be queried by the User to easily identify features I'm using basic SQL query such as
but then I need to decode the tile_data, extracts the feature, and check if the feature properties (for instance I'm a beginner in SQL but I've read online that if a specific data was "indexed" (for instance The question is : does Tilemaker (or any 3rd party libary) allows for post-processing to perform such tasks ? And, is it the best way to fill my requirement ? Thanks in advance for your feedback Ben |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Unfortunately this won't work. An .mbtiles is just a collection of binary vector tiles in an SQLite container. SQLite doesn't understand the vector tiles themselves - they're just arbitrary binary blobs as far as it knows - so it can't index their contents. Traditionally if you wanted to do this, you would take the opposite approach to tilemaker: feed all your data into a Postgres database using osm2pgsql, then create vector tiles on the fly with Martin, Tilekiln or similar. You then have a full queryable SQL database in Postgres. But the vector tile pipeline then becomes very different to the tilemaker way of doing things. One approach you could potentially look at is outputting text files from Lua, one per thread, containing the objects you want to "index". Open a text file in init_function (with a randomly suffixed name, because you'll have 16 of them or however many threads you have running). Whenever your Lua script in way_function or node_function encounters something you want to index, write this out to the file, together with its lat/lon. Then close the file in exit_function. Your app can then read all these text files in and find the location of features. |
Beta Was this translation helpful? Give feedback.
Mine's in Swift or Kotlin so not directly comparable, but areas for optimisation might be (a) just using one layer, (b) making sure everything in that layer is a single point (so you don't have to reconstruct complex geometries), (c) writing your own simple vector tile geometry reader so you avoid the GeoJSON step.