You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello dear OSRM developers and users, I use 2 OSRM services: map match and nearest.
To pass OSM way ids and OSM way tags to my application, I encode them as a JSON string and then assign to the waypoint/tracepoint "name" members, as you can see in the 2 following files -
A set-way-name.lua file, which encodes way id and way tags into a JSON string:
local highway = way:get_value_by_key("highway")
local surface = way:get_value_by_key("surface")
-- create key-value strings
local id_kv = '"id":'..way:id()
local highway_kv = '"highway":'..(highway and '"'..highway..'"' or 'null')
local surface_kv = '"surface":'..(surface and '"'..surface..'"' or 'null')
-- replace the way name by a JSON string with way id and tags
local name = '{'..id_kv..','..highway_kv..','..surface_kv..'}'
and a customized Dockerfile, which downloads europe-latest.osm.pbf and injects the set-way-name.lua into the WayHandlers.names() function in the /profile/lib/way_handlers.lua file:
ARG OSRM_TAG
FROM ghcr.io/project-osrm/osrm-backend:$OSRM_TAG
EXPOSE 5000
# Add the user and 2 groups to be used for the securityContext in deployment YML file
RUN groupadd --gid 2000 group2 && groupadd --gid 3000 group3 && useradd --uid 1000 --groups group2,group3 user1
# Install ps, top, netstat, curl, wget, osmium, jq
RUN apt-get update && \
apt-get upgrade -y && \
apt install -y procps net-tools curl wget osmium-tool jq
# download OSM data files into /data folder
WORKDIR /data
COPY ./set-way-name.lua /data
RUN chown -R user1:group2 /data
# Replace the line in the WayHandlers.names() function by contents of set-way-name.lua
RUN sed -i.bak -e '/local name = way:get_value_by_key("name")/r set-way-name.lua' -e '//d' /opt/lib/way_handlers.lua
# drop root privileges
USER user1
# Download one or multiple OSM files
ARG DOWNLOAD_URLS
RUN wget --no-verbose $DOWNLOAD_URLS
# Print summaries of the downloaded OSM files
RUN for f in *.osm.pbf; do osmium fileinfo -e "$f"; done
# Merge one or multiple files into a new file map.osm.pbf
RUN osmium merge *.osm.pbf -o map.osm.pbf
# Remove all files except the map.osm.pbf
RUN find . -type f -name '*.osm.pbf' | grep -v 'map.osm.pbf' | xargs rm
RUN rm set-way-name.lua
# Extract the downloaded OSM file
RUN osrm-extract --profile /opt/car.lua map.osm.pbf
# Delete the downloaded OSM files
RUN rm *.osm.pbf
# Create .osrm.* files in the /data dir
RUN osrm-partition map.osrm
RUN osrm-customize map.osrm
# Allow osrm-routed accessing its files in /data
RUN chown -R user1:group2 .
# Change the generated files and the dir to be read-only
RUN chmod 400 ./*.osrm.*
RUN chmod 500 .
# Start the osrm-routed server at port 5000
CMD ["osrm-routed", "--algorithm", "mld", "--verbosity", "DEBUG", "--max-matching-size", "1000", "map.osrm"]
The Dockerfile can be built be the following command:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello dear OSRM developers and users, I use 2 OSRM services: map match and nearest.
To pass OSM way ids and OSM way tags to my application, I encode them as a JSON string and then assign to the waypoint/tracepoint "name" members, as you can see in the 2 following files -
A set-way-name.lua file, which encodes way id and way tags into a JSON string:
and a customized Dockerfile, which downloads europe-latest.osm.pbf and injects the set-way-name.lua into the
WayHandlers.names()
function in the /profile/lib/way_handlers.lua file:The Dockerfile can be built be the following command:
And then it can be tested by the following 2 wget commands:
Screenshot:
My question is: if I could define my own property on the
result
, instead of overwriting theresult.name
?Also any general advice is very welcome.
Best regards
Alex
Beta Was this translation helpful? Give feedback.
All reactions