Skip to content

Setting custom attribute value from external source like an API/JSON/DB? #443

Answered by systemed
larsschwarz asked this question in Q&A
Discussion options

You must be logged in to vote

Lua itself is fairly bare-bones but you should be able to find some libraries to do this. In a similar situation (my OSRM fork) I need to read GeoJSON from Lua. First of all I have a simple bit of code to read a local file:

function Utils.read_file(fn)
	local f = assert(io.open(fn, "rb"))
	local content = f:read("*all")
	f:close()
	return content
end

I then use LunaJSON to parse the file. It's just three files that you can install manually, you don't have to use the Luarocks package manager.

I then put that in init_function so that the parsed JSON file is available to each thread.

Another option I find useful on occasion is to preprocess the .pbf to set arbitrary tags on each way: https:/…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@larsschwarz
Comment options

Answer selected by larsschwarz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants