惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
GRAHAM CLULEY
T
Tenable Blog
Know Your Adversary
Know Your Adversary
C
CXSECURITY Database RSS Feed - CXSecurity.com
P
Privacy International News Feed
S
Security Affairs
NISL@THU
NISL@THU
O
OpenAI News
Attack and Defense Labs
Attack and Defense Labs
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Hacker News: Ask HN
Hacker News: Ask HN
Webroot Blog
Webroot Blog
Schneier on Security
Schneier on Security
S
SegmentFault 最新的问题
S
Schneier on Security
G
Google Developers Blog
V
V2EX
C
Check Point Blog
U
Unit 42
Google DeepMind News
Google DeepMind News
T
Threatpost
阮一峰的网络日志
阮一峰的网络日志
T
The Exploit Database - CXSecurity.com
Recent Announcements
Recent Announcements
M
MIT News - Artificial intelligence
S
Secure Thoughts
博客园 - 司徒正美
Recorded Future
Recorded Future
P
Proofpoint News Feed
Spread Privacy
Spread Privacy
K
Kaspersky official blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
AI
AI
博客园 - 聂微东
N
News and Events Feed by Topic
SecWiki News
SecWiki News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
Vulnerabilities – Threatpost
P
Palo Alto Networks Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Engineering at Meta
Engineering at Meta
Recent Commits to openclaw:main
Recent Commits to openclaw:main
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
酷 壳 – CoolShell
酷 壳 – CoolShell
WordPress大学
WordPress大学
The Hacker News
The Hacker News
The Last Watchdog
The Last Watchdog
Project Zero
Project Zero
W
WeLiveSecurity
博客园 - Franky

herrkaefer

"Vibe planning \u003e vibe coding" "Anything to Markdown" "Built anocus: anonymous commenting for static sites" "日记与小说 -- AI 续写小说欣赏" "Any-podcast: from newsletters to a podcast" "Made MicPipe: a simple voice input tool using ChatGPT dictation" "关于 Tools 和 Skills 的一点感想" "Realtime monitoring of ComEd hourly price" "Introducing SwiftEdgeTTS" "Thoughts on the philosophy of building AI-native apps" "jelly鼻屎" "等饭的人" "Use home assistant to motivate my kid to brush teeth" "Migrated Blog to Hugo and Cloudflare Pages" "Easy Aspen monitoring for Chicago parents" "Introducing HabitBuilder: A simple Telegram bot for habit tracking" "鼓捣" "Open folder or file with Sublime Text from Finder toolbar" "Python dev workflow on macOS" "Create new text file from Finder toolbar" "Uno reinvented for 3-year-old kids" "Uno变身儿童数字游戏" "自动转发Twitter到微博" "Handle annoying operations of objects in Realm DB" "Move Jekyll blog to Ubuntu VPS" "Introducing Mole" "Note taking without note taking app" "Deploy Python web application on Ubuntu server" "Setup Shadowsocks / VPN on Ubuntu Server" "Linode Notes - Basic Setup" "CLASS Style Adapted for Embedded Systems" "psycopgr Tutorial" "PostgreSQL Notes" "阿城三王" "这一年,这一把日子" "另一面的发现——读《坟》" "定理" "封面与腰封" "Google book下载" "lulu最新写真出炉" "The Big Bang Theory第三季" "自拍婚纱照1" "日全食" "期待动画片" "《麦兜响当当》动画电影主题曲" "转:饶毅--“杂志拜物教”:何时发Cell Nature Science 论文害你" "转:饶毅--提醒年轻人:何时SCI害你?" "西安" "3d打印机" "Dropbox" "刷牙" "贴几张照片" "6156167" "永久和凤凰" "老板的想法" "春" "原来奥巴马也是个朗读者" "应邀发Freeware List 2.0" "史上最能睡的淘宝老板" "至少出名的效果是达到了" "错怪了msn" "独立游戏节2009" "114" "馒头" "Crayon Physics Deluxe" "2008,2009" "盖章记" "小虎队附身许巍" "怎么给word文档加索引:排序问题" "怎么给word文档加索引Q\u0026amp;A" "怎么给Word文档加索引" "教我如何不疯掉" "二则" "P" "哦!报告" "蓝天" "萧翰" "lm" "故宫印象" "转:美国历任总统像" "time can kill itself" "嗯" "建议,只是建议哦" "奥地利行记3" "奥地利行记2" "奥地利行记1" "叶子" "GayBoy" "天使教你扔frisbie" "门徒因何面容愁?" "手机教堂" "丝竹管弦之盛" "残奥" "争座位" "秋意浅" "总理府" "流觞曲水" "映带左右引以为" "咚咚咚 续" "茂林修竹又有"
"pgRouting Notes"
"herrkaefer" · 2016-08-30 · via herrkaefer

Install PostGIS and pgRouting

On Mac

The following will install pgRouting and its dependencies including PostGIS, and PostgreSQL if not installed:

On Linux

(to add)

Install osm2pgrouting

osm2pgrouting is for importing OSM data into PostgreSQL database, and creating routable topology.

It is said that osm2pgrouting has limitation:

> Can’t process “large” files, continents, big countries, or very large states.

For large files, we can use osm2po.

Install via homebrew (Mac)




brew install osm2pgrouting

Note that a mapconfig.xml file is at: /usr/local/Cellar/osm2pgrouting/[version]/share/osm2pgrouting/mapconfig.xml

Manually install the lastest version

(The following notes are based on version 2.1. Now with homebrew you can already install the latest version.)

  1. Download code from repo

  2. Modify CMakeLists.txt to install app to /usr/local/bin and other files to /usr/local/share

  • line 5 —> set (SHARE_DIR “/usr/local/share/osm2pgrouting”)

  • line 36 —> RUNTIME DESTINATION “/usr/local/bin”

  1. Add the following headers to src/way.h (otherwise there will be errors)



#include



#include



#include
  1. Build and install



cmake -H. -Bbuild



cd build/



make



make install

Workflow

Prepare database

Create new database if needed:

For each database that postgis and pgrouting are used, we should install corresponding extensions:




psql routing -c "create extension postgis"



psql routing -c "create extension pgrouting"

For test of installation:




psql routing -c "SELECT postgis_full_version()"



psql routing -c "SELECT pgr_version()"

Import OpenStreetMap data

OSM map data can be downloaded in many places. We are interested in the OSM XML format.

To import map data to database:




osm2pgrouting --file beijing_china.osm \



--conf /usr/local/Cellar/osm2pgrouting/[version]/share/osm2pgrouting/mapconfig.xml \



--dbname routing \



--username [username] \



--clean

If you are adding data, do not use flag --clean.

We could browse the tables with psql or pgAdmin.

Notes for tables

Two main tables:

  • ways: stores the edges

  • ways_vertices_pgr: stores the end nodes of edges

Meanings of ways columns length, length_m, cost, reverse_cost, cost_s, reverse_cost_s. According to post here:

  • length is length of the segment in degree units

  • cost and reverse_cost is the length in degree units. (include the negative values for wrong way)

  • length_m is in meters (there is no cost_m or reverse_cost_m)

  • cost_s and reverse_cost_s is in time: seconds units (using the maxspeed value that is in km/hr transforming it to meters/second and using the length_m)

Do routings in SQL

Now we can calculate routes with pgRouting. For example, to calculate one-to-one shortest path:




SELECT * FROM pgr_dijkstra(



'SELECT gid as id, source, target, cost, reverse_cost FROM ways',



100, 200,



TRUE



);

pgRouting Manuals

Do routings in Python

I bet that You don’t want to write SQLs. Good news here if you like writing Python! I wrote a psycopgr Python module to encapsulate database connection (via psycopg2) and pgRouting callings. Here is a tutorial.