I have a road network in a PostGis database (db_routing). In another database (db_environment), I have some spatial features of the surrounding environment (trees as points and water bodies as polygons for example).

I would like to assign costs to my road segments depending on the surrounding environment. I envisage two possibilities:

  • through a raster: I can create a raster and each cell will have a cost depending on the features from db_environment it contains (trees density and presence or no of water for example). Then, I would have to give a cost to the road segments depending on the raster cells they intersect.

  • through a vector layer: I could run a proximity analysis around each of my road segments, by creating a buffer around it and looking at the features from db_environment contained in this buffer.

It seems to me that it would be easier to create a raster (by using simple mathematical additions to take the different cost into account, instead of performing spatial clips with a vector).

Do you have ideas on this, or examples of similar projects ?

Thanks in advance

Some thoughts on the pros and cons of each method:

  • Raster

    • Advantages: Easy to add incrementally more and more cost factors by using simple mathematical operations
    • Disadvantages: Complex to choose the right pixel size, and to find a proper way to transfer this data to the road network vector
  • Vector

    • Advantages: Efficient to perform proximity analysis
    • Disadvantages: Bad representation for continuous data
  • Something like : update r set cost = count(t.the_geom) FROM roads r, trees as t WHERE ST_Contains(ST_buffer(r.the_geom) , t.the_geom) , i dont see whats hard on that. Ofcourse you can create raster too , but if you use pgRouring you still have to use vectors to route , so st_intersect changes to some raster operation Apr 11, 2013 at 13:32
  • I agree with you, the queries are not the problem as they will not be too complex in any way. My question concerns more the good practices in proximity analysis
    – FredB
    Apr 11, 2013 at 13:39

1 Answer 1


I went finally for a mix of raster and vector, using a vector grid, that has several advantages :

  • One column per cost factor, to be able to combine these factors in different combinations later
  • I can keep the grid unchanged and only update the road network : the environnement in a city doesn't change often
  • Easy to transfer the costs from the grid to the road network by simply running intersection analysis

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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