NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

Here are the things I have done till now

  1. I created a DB in PostgreSQL with PostGIS and HSTORE extension enabled.
  2. I used the osm2pgsql command-line tool to load the DB on to the PostgreSQL localhost server.
  3. In the command line I used --hstore flag and default.style file which came along with osm2pgsql package.

So, I have a DB with 5 tables i.e. planet_osm_point, planet_osm_line, planet_osm_polygon, planet_osm_roads, and spatial_ref_sys.

I have identified the node of interest via following SQL queries. For 1st node, SELECT * FROM planet_osm_point WHERE name = 'bits pilani' and for second SELECT * FORM ppanet_osm_polygon WHERE tags::text like = '%Shamshabad Airport%'

The final aim of the project is to output the best possible route between these two nodes using an algorithm on a graph of nodes.

I want to know how to find the neighbouring nodes(4 or 5) of a node such that they are all connected via some highway, roads, street etc. How to query the DB for this? Please help.

asked 08 Apr '20, 11:20

Ayush%20Porwal's gravatar image

Ayush Porwal
16113
accept rate: 0%


osm2pgsql is designed for importing data for rendering, not for routing. It's a "lossy" import that doesn't preserve the topology required for routing. (Strictly speaking you could do this if you've imported in slim mode, but it's not the intention.)

For routing, you need to use an importer/pre-processor that will create a routable graph from the OSM data. Routing engines such as OSRM and Graphhopper will do this as part of their preparation process. If you want to write your own routing engine, but are looking for something that will create a graph for you, https://github.com/Tristramg/osm4routing2 is probably the easiest tool to use.

(If you're determined to do it in Postgres, check out https://pgrouting.org/docs/tools/osm2pgrouting.html .)

permanent link

answered 08 Apr '20, 12:26

Richard's gravatar image

Richard ♦
30.9k44279412
accept rate: 18%

edited 08 Apr '20, 12:27

Hi Richard

It looks like osm4routing tool will work for me. Can you please let me know how to convert .osm file to .pbf file and what is the command line to use in osm4routing to finally get the .csv file?

Edit: used osmconvert to convert .osm file to .pbf file via command osmconvert map.osm --out-pbf -o=map_01.pbf. I still need help with using osm4routing tool.

(08 Apr '20, 15:34) Ayush Porwal

osm4routing path_to_your.osm.pbf

This will then output edges.csv and nodes.csv in the same directory. The .csv files have a header row, see the osm4routing2 source code if you want to know more.

(08 Apr '20, 16:20) Richard ♦
1

Ayush, this site is "help with OpenStreetMap" not "do people's homework for them". I'm guessing you've been given this assignment so that you understand how a path-finding algorithm works. If I were to tell you how to do it, you'd not learn anything. Just google A* algorithm, there are countless sites that explain it.

(09 Apr '20, 11:07) Richard ♦

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×710
×263
×165
×134
×67

question asked: 08 Apr '20, 11:20

question was seen: 2,150 times

last updated: 09 Apr '20, 11:07

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum