Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Recently I was doing some research on how to assign nodes (as POINT type geometry) to existing edges of a topology network and store them in a different table. Call it nodes table.

I have all the edges, they have source and target fields among some other fields as well. My main idea is, that say, I want to input a location - POINT(lat, lng) - into my routing app. Then what I want my app to do is to find the point closest to my given location in the nodes table in order to start the routing process.

In my research, I examined the functions ST_StartPoint() and ST_EndPoint() as possible functions that could come handy while implementing this. Ideally, I would loop thru the edges and get and record both the start- and the endpoints of each, but that raises another issue of having multiple identical points in the nodes table.

Am I on the right track of implementing this right or could you advise a better solution? Any feedbacks or ideas are welcome!

Thanks in advance


p.s.: The proximity search feature is fine, I can do that. The only issue is the node generation.

share|improve this question
up vote 3 down vote accepted

All information you need is already in your road network table if it contains source, target and geometry information. With this information you can for example create a VIEW that contains all nodes with point geometry:

CREATE VIEW nodes_from_ways AS 
    SELECT source AS node, ST_StartPoint(the_geom) FROM ways 
    SELECT target AS node, ST_EndPoint(the_geom) FROM ways;

With UNION you combine source and target and only unique node ID's should remain.

Does this work for you?

share|improve this answer
Thanks for your help dkastl. I pretty much figured out the solution from underdark's blog entry:… and your answer was helpful too. Thanks =) – Tamas May 20 '12 at 9:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.