2021. 9. 27. 23:34ㆍ개발/OSRM
OSRM 를 통해 경로 찾기를 만들고 싶다면, 앞서 소개했었던 OSRM http API를 사용하면 된다.
2021.09.15 - [개발/OSRM] - OSRM 이란
하지만, 커스텀이 필요한 경우나 다양한 처리가 필요한 경우 제한적이기 때문에 원하는 서비스 형태에 따라 바꾸기 위해서는 경로 찾기 서버를 따로 만들어 주는 것이 더 편리하다.
Product level 의 관점에서는 아래 내용을 참고해보면 좋다.
[running osrm in production?]
https://github.com/Project-OSRM/osrm-backend/issues/1768
OSRM 공식 홈페이지에 따르면 Docker를 이미지를 다운하여 빠르고 쉽게 osrm backend를 구축할 수 있다고 한다.
그러기 위해서는 Docker와 지도 데이터가 필요하다. (Docker는 각 PC 환경에 맞게 다운받으면 된다.)
1. 지도 데이터 다운
http://download.geofabrik.de/asia.html
위 사이트에서 south korea를 찾아 다운받는다.
또는 아래 CMD를 통해 다운받을 수 있다.
예시 : wget http://download.geofabrik.de/europe/germany/berlin-latest.osm.pbf
2. Docker 이미지 생성 및 전처리
Docker 공식홈페이지 원문
Pre-process the extract with the car profile and start a routing engine HTTP server on port 5000
docker run -t -v "${PWD}:/data" osrm/osrm-backend osrm-extract -p /opt/car.lua /data/berlin-latest.osm.pbf
The flag -v "${PWD}:/data" creates the directory /data inside the docker container and makes the current working directory "${PWD}" available there. The file /data/berlin-latest.osm.pbf inside the container is referring to "${PWD}/berlin-latest.osm.pbf" on the host.
docker run -t -v "${PWD}:/data" osrm/osrm-backend osrm-partition /data/berlin-latest.osrm
docker run -t -v "${PWD}:/data" osrm/osrm-backend osrm-customize /data/berlin-latest.osrm
Note that berlin-latest.osrm has a different file extension.
한국 지도데이터를 받은 경우 다운받은 경로에서 CMD를 켜고 아래와같이 입력해준다.
docker run -t -v "${PWD}:/data" osrm/osrm-backend osrm-extract -p /opt/car.lua /data/south-korea-latest.osm.pbf
위와같이 입력하게 되면, 다운받은 지도를 가지고 자동차 경로에 대해 extract 한다.
그리고 아래의 CMD 를 순서대로 입력해주면, 추출된 데이터를 가지고 전처리를 하게 된다.
docker run -t -v "${PWD}:/data" osrm/osrm-backend osrm-partition /data/south-korea-latest.osrm
docker run -t -v "${PWD}:/data" osrm/osrm-backend osrm-customize /data/south-korea-latest.osrm
> docker run -t -v "${PWD}:/data" osrm/osrm-backend osrm-partition /data/south-korea-latest.osrm
[info] Computing recursive bisection
[info] Loaded compressed node based graph: 2844508 edges, 5212080 nodes
[info] running partition: 128 1.2 0.25 10 1000 # max_cell_size balance boundary cuts small_component_size
[info] Found 4163913 SCC (1 large, 4163912 small)
[info] SCC run took: 0.377439s
[info] Full bisection done in 76.856s
[info] Loaded node based graph to edge based graph mapping
[info] Loaded edge based graph for mapping partition ids: 10697410 edges, 2659093 nodes
[info] Fixed 715 unconnected nodes
[info] Edge-based-graph annotation:
[info] level 1 #cells 12427 bit size 14
[info] level 2 #cells 994 bit size 10
[info] level 3 #cells 61 bit size 6
[info] level 4 #cells 3 bit size 2
[info] Renumbered data in 22.7533 seconds
[info] MultiLevelPartition constructed in 0.957075 seconds
[info] CellStorage constructed in 0.324042 seconds
[info] MLD data writing took 1.74367 seconds
[info] Cells statistics per level
[info] Level 1 #cells 12427 #boundary nodes 301282, sources: avg. 16, destinations: avg. 22, entries: 5914833 (47318664 bytes)
[info] Level 2 #cells 994 #boundary nodes 48675, sources: avg. 32, destinations: avg. 42, entries: 1647572 (13180576 bytes)
[info] Level 3 #cells 61 #boundary nodes 6414, sources: avg. 68, destinations: avg. 84, entries: 418894 (3351152 bytes)
[info] Level 4 #cells 3 #boundary nodes 715, sources: avg. 159, destinations: avg. 184, entries: 111726 (893808 bytes)
[info] Bisection took 108.836 seconds.
[info] RAM: peak bytes used: 855347200
> docker run -t -v "${PWD}:/data" osrm/osrm-backend osrm-customize /data/south-korea-latest.osrm
[info] Loaded edge based graph: 10697410 edges, 2659093 nodes
[info] Loading partition data took 5.95711 seconds
[info] Cells customization took 39.1571 seconds
[info] Cells statistics per level
[info] Level 1 #cells 12427 #boundary nodes 301282, sources: avg. 16, destinations: avg. 22, entries: 5914833 (47318664 bytes)
[info] Level 2 #cells 994 #boundary nodes 48675, sources: avg. 32, destinations: avg. 42, entries: 1647572 (13180576 bytes)
[info] Level 3 #cells 61 #boundary nodes 6414, sources: avg. 68, destinations: avg. 84, entries: 418894 (3351152 bytes)
[info] Level 4 #cells 3 #boundary nodes 715, sources: avg. 159, destinations: avg. 184, entries: 111726 (893808 bytes)
[info] Unreachable nodes statistics per level
[warn] Level 1 unreachable boundary nodes per cell: 0.00144846 sources, 0.00217269 destinations
[warn] Level 2 unreachable boundary nodes per cell: 0.00804829 sources, 0.0140845 destinations
[warn] Level 3 unreachable boundary nodes per cell: 0.0327869 sources, 0.147541 destinations
[warn] Level 4 unreachable boundary nodes per cell: 0.333333 sources, 3 destinations
[info] Unreachable nodes statistics per level
[warn] Level 1 unreachable boundary nodes per cell: 0.0112658 sources, 0.010622 destinations
[warn] Level 2 unreachable boundary nodes per cell: 0.0885312 sources, 0.0774648 destinations[warn] Level 3 unreachable boundary nodes per cell: 0.491803 sources, 0.606557 destinations
[warn] Level 4 unreachable boundary nodes per cell: 0.333333 sources, 3 destinations
[info] Unreachable nodes statistics per level
[warn] Level 1 unreachable boundary nodes per cell: 0.203669 sources, 0.141064 destinations
[warn] Level 2 unreachable boundary nodes per cell: 1.33199 sources, 0.875252 destinations
[warn] Level 3 unreachable boundary nodes per cell: 6.70492 sources, 4.34426 destinations
[warn] Level 4 unreachable boundary nodes per cell: 9.33333 sources, 8.33333 destinations
[info] Unreachable nodes statistics per level
[warn] Level 1 unreachable boundary nodes per cell: 0.013519 sources, 0.0226925 destinations
[warn] Level 2 unreachable boundary nodes per cell: 0.0674044 sources, 0.105634 destinations
[warn] Level 3 unreachable boundary nodes per cell: 0.409836 sources, 0.721311 destinations
[warn] Level 4 unreachable boundary nodes per cell: 0.666667 sources, 3.33333 destinations
[info] MLD customization writing took 4.63278 seconds
[info] Graph writing took 2.75069 seconds
[info] RAM: peak bytes used: 1171329024
3. Docker 서버 실행
docker run -t -i -p 5000:5000 -v "${PWD}:/data" osrm/osrm-backend osrm-routed --algorithm mld /data/south-korea-latest.osrm
위 CMD를 입력해주면 PORT 5000 으로 서버가 실행되게 된다.
실행이 되면 브라우저로 가서 아래 주소로 접속해 본 후 response가 제대로 온다면 성공~!
http://127.0.0.1:5000/route/v1/driving/127.092088,37.335339;127.085124,37.337822?steps=true
참고 사이트
https://yongj.in/utility/osrm-routing/
https://github.com/Project-OSRM/osrm-backend