This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

How to find the neighbouring nodes of a particular node

0

I have imported the osm file into postgresql. The tables I have are planet_osm_ndes,planet_osm_ways, planet_osm_point. planet_osm_roads etc. But no table contains the information of neighbouring nodes of a node. I tried connecting to the database using java and tried finding the neighbours, but the code runs for hrs and still no output. Is there a easy way to do it

asked 12 Feb '18, 03:21

batraj's gravatar image

batraj
11112
accept rate: 0%

edited 12 Feb '18, 03:22


One Answer:

1

The osm2pgsql database schema is optimised for drawing maps; for this use case, neighbouring nodes are uninteresting. If you have used the --slim flag on osm2pgsql (which you apparently have since you mention planet_osm_nodes), you can look at the "nodes" array of ways in planet_osm_ways (step 1: find out which ways contain your node of interest, step 2: find out where in the node list your node occurs, step 3: find the nodes before and after, if applicable). However, it sounds as if your use case might warrant a different kind of database import that gives you easier access to the node/way connections, for example check out the "ApiDB" import offered by Osmosis.

answered 12 Feb '18, 09:54

Frederik%20Ramm's gravatar image

Frederik Ramm ♦
82.5k927201273
accept rate: 23%

Source code available on GitHub .