Closed wboykinm closed 6 years ago
Oh wow, that looks nice!
The bit of tilemaker that maps OSM keys into MVT fields is the config.lua
file. (The vector_layers
part of the JSON config is a slightly confusing Mapbox addition which documents what the client will find in the tiles, but it doesn't actually change anything. tilemaker can now generate that automatically.)
So you'd need to make config.lua
take the OSM data and write it into the vector tiles. You should be able to do this by editing https://github.com/systemed/tilemaker/blob/master/process.lua#L43, and adding a couple of new lines:
local metres = to_number(way:Find("height")) or 5
way:AttributeNumeric("height", metres)
That takes the height tag from OSM; converts it to a number; falls back to a default height of 5 if there's no height tag; and writes it to the vector tile as the "height" attribute.
There's doubtless lots more you could do in terms of parsing the weird and wonderful values that are no doubt in the height tag, but that should do for a start. Lua's really well-suited to doing this sort of OSM tag-mangling (it's used for the same purpose in OSRM and osm2pgsql).
@systemed That's a marvelous explanation, and makes this super-extensible. Thanks so much!
I am however running into what appears to be a coalesce failure, and my troglodytic searching around the lua docs is not turning up an answer.
Given:
if building~="" then
local metres = (to_number(way:Find("height"))) or 5
way:AttributeNumeric("height",metres)
way:Layer("building", true)
end
Any idea what's causing this?
libc++abi.dylib: terminating with uncaught exception of type kaguya::LuaRuntimeError: process.lua:44: attempt to call global 'to_number' (a nil value)
It seems to happen no matter where I put the metres
declaration. For reference I'm using a geofabrik extract.
Gah! Mea culpa. Should be tonumber
(no underscore).
@systemed That did the trick!
Thanks again!
Where you place exacty this:
I'm interested in pulling building height data into MVTs generated with tilemaker. Using the "default" config file, I edited this line to read
{ "id": "building", "description": "building", "fields": { "height": "Integer" }}
I'm interested in pulling building height data into MVTs generated with tilemaker. Using the "default" config file, I edited this line to read
{ "id": "building", "description": "building", "fields": { "height": "Integer" }}
Tilemaker then runs smoothly and produces outputs that render in Mapbox GL when given static properties:
Unfortunately, when I try to use the height info for dynamic styling, I get this error:
Expected value to be of type number, but found null instead.
It appears that my adjustment to the config file above is producing
NULL
s. What is the proper way to pass usable building height data (or indeed any data from osm properties) through to generated MVTs?