Setting custom attribute value from external source like an API/JSON/DB? #443
-
Does the current process Lua script allow retrieving "external" data from sources like an API (http request), a JSON file or similar? Something like
No Lua guy, but I assume JSON or http requests require the use of additional modules that aren't loaded by the current script process? Is there any default/on-board Lua functionality that could be used to load external data by the process script? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
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 Another option I find useful on occasion is to preprocess the .pbf to set arbitrary tags on each way: https://github.com/systemed/tagmangle is a little C++ utility I wrote for this. |
Beta Was this translation helpful? Give feedback.
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:
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:/…