Chien-Hao Huang
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # OSRM Python API 使用說明 OSRM (Open Street Routing Machine) 是一個開源的地圖搜尋引擎,資料來源係基於 OpenStreetMap。OSRM 的底層使用 C++ 開發,並且官方提供 HTTP 接口,可供開發人員進行串接。本篇文章為筆者自行編寫的 [OSRM Python API](https://github.com/chhuang17/osrm_api) 使用說明,此 API 即是利用官方提供之 HTTP 接口,利用 Python 的 ```requests``` 套件爬取並解析 json 資料。 ## 兩點之間求取旅行資訊 ### 旅行距離 當您有任意兩點的經緯度座標時,您可以呼叫 ```distance()``` 函式,取得兩點間之旅行距離。兩點間的旅行距離是 OSRM 官方利用演算法求解得出,此處不詳述。必須注意的是,__座標填入必須先填入經度,再填入緯度__,即 __(經度, 緯度)__。 ```python distance = osrm.distance(orign, destn, unit='m', steps='false') ``` #### 輸入引數 (Input Arguments) |引數名稱|說明|資料型態| |:--|:--|:--| |```orign```|起點經緯度座標。|```list```, ```tuple```, or array-like| |```destn```|迄點經緯度座標。|```list```, ```tuple```, or array-like| |```unit```|度量單位,預設為 ```'m'```。|```str```| |```steps```|是否回傳詳細資料,預設為 ```'false'```。|```str```| #### 輸出 (Output) 兩點間旅行距離,資料型態為 ```float```。若 ```steps='true'```, ### 旅行時間 當您有任意兩點的經緯度座標時,您可以呼叫 ```travTime()``` 函式,取得兩點間之旅行時間。必須注意的是,__官方提供的旅行時間並不會因為在不同的時間 call API 有所變化__,另外,__座標也是必須先填入經度,再填入緯度__,即 __(經度, 緯度)__。 ```python travelTime = osrm.travTime(orign, destn, unit='m', steps='false') ``` #### 輸入引數 (Input Arguments) |引數名稱|說明|資料型態| |:--|:--|:--| |```orign```|起點經緯度座標。|```list```, ```tuple```, or array-like| |```destn```|迄點經緯度座標。|```list```, ```tuple```, or array-like| |```unit```|度量單位,預設為 ```'m'```。|```str```| |```steps```|是否顯示詳細資料,預設為 ```'false'```。|```str```| #### 輸出 (Output) 兩點間旅行距離,資料型態為 ```float```。若 ```steps='true'```, *** ## 多點之間求取旅行資訊 在很多使用情境下,您可能需要一次求取數個點彼此之間的旅行資訊。此外,若短時間內連續向 OSRM 官方提供的 HTTP 接口發送請求,官方會阻擋並間隔約 5 秒鐘的時間,才會回傳您需要的資訊。考量到程式運行效率,因此在實作上,大多時候會一次求取數個點的旅行資訊。 ### O-D 矩陣 O-D 為 Origin-Destination 的縮寫,即起點-迄點的意思,是運輸學領域和地理學領域常見名詞。當您有任意 $N$ 個點的經緯度座標時,您可以呼叫 ```odMatrix()``` 函式,取得一 O-D 矩陣。 ```python matrix = osrm.odMatrix( nodeList, get='distance', sources=None, distUnit='m', timeUnit='second' ) ``` #### 輸入引數 (Input Arguments) |引數名稱|說明|資料型態| |:--|:--|:--| |```nodeList```|$N$ 個點的經緯度座標。|```list```| |```get```|欲取得之資訊,預設為 ```'distance'```。|```str```| |```sources```|原點,預設為 ```None```。|```NoneType``` or ```int```| |```distUnit```|距離度量單位,預設為 ```'m'```。|```str```| |```timeUnit```|時間度量單位,預設為 ```'second'```。|```str```| #### 輸出 (Output) $N \times N$ 的方陣,資料型態為 ```np.array```。 ### 旅行距離序列 若您手邊有 $N$ 個點的經緯度座標,且您想知道 $1 \rightarrow 2 \rightarrow 3 \rightarrow \cdots \rightarrow N$ 依序之旅行距離,您可以呼叫 ```distSeq()``` 函式,取得您需要的資訊。 ```python distSeqList = osrm.distSeq( nodeList=None, matrix=None, sources=None, distUnit='m' ) ``` #### 輸入引數 (Input Arguments) |引數名稱|說明|資料型態| |:--|:--|:--| |```nodeList```|$N$ 個點的經緯度座標,預設為 ```None```,與 ```matrix``` 擇一輸入。|```NoneType``` or ```list```| |```matrix```|欲取得之資訊,預設為 ```None```,與 ```nodeList``` 擇一輸入。|```NoneType``` or ```list```| |```sources```|原點,預設為 ```None```。|```NoneType``` or ```int```| |```distUnit```|距離度量單位,預設為 ```'m'```。|```str```| #### 輸出 (Output) 點到點依序之旅行距離,資料型態為 ```list```,長度為 $N-1$。 ### 旅行時間序列 若您手邊有 $N$ 個點的經緯度座標,且您想知道 $1 \rightarrow 2 \rightarrow 3 \rightarrow \cdots \rightarrow N$ 依序之旅行時間,您可以呼叫 ```travTimeSeq()``` 函式,取得您需要的資訊。 ```python travTimeSeqList = osrm.travTimeSeq( nodeList=None, matrix=None, sources=None, timeUnit='second' ) ``` #### 輸入引數 (Input Arguments) |引數名稱|說明|資料型態| |:--|:--|:--| |```nodeList```|$N$ 個點的經緯度座標,預設為 ```None```,與 ```matrix``` 擇一輸入。|```NoneType``` or ```list```| |```matrix```|欲取得之資訊,預設為 ```None```,與 ```nodeList``` 擇一輸入。|```NoneType``` or ```list```| |```sources```|原點,預設為 ```None```。|```NoneType``` or ```int```| |```timeUnit```|距離度量單位,預設為 ```'second'```。|```str```| #### 輸出 (Output) 點到點依序之旅行時間,資料型態為 ```list```,長度為 $N-1$。

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully