Advertisements

Creating Catchment Areas with pgRouting and QGIS

Based on the network created in my last post, I’ll now describe how to calculate the catchment area of a network node.

We need both network and node table. The cost attribute in my network table is called traveltime. (I used different speed values based on road category to calculate traveltime for road segments.) The result will be a new table containing all nodes and an additional cost attribute. And this is the query that calculates the catchment area around node #5657:

create table catchment_5657 as
select 
    id,
    the_geom,
    (select sum(cost) from (
	   SELECT * FROM shortest_path('
	   SELECT gid AS id,
		  start_id::int4 AS source,
		  end_id::int4 AS target,
		  traveltime::float8 AS cost
	   FROM network',
	   5657,
	   id,
	   false,
	   false)) as foo ) as cost
from node

Then, I loaded the point table into QGIS and calculated a TIN based on the cost attribute. With “Contour” from GdalTools, you can visualize equal-cost areas even better:

Catchment area around node #5657 with contour lines

Between contour lines, there is a difference of 10 minutes travel time.

If you are looking for a faster way to calculate small catchment areas (relative to the network size), check “Catchment Areas with pgRouting driving_distance().

Advertisements
13 comments
  1. Taro said:

    Thank you for your excellent guidance of pgRouting on QGIS!!!

    Now, I have a question.
    >Then, I loaded the point table into QGIS and calculated a TIN based on the cost attribute.
    In this post, you converted point table data to raster layer by calculating a TIN.
    Did you use any core plugin embedded in QGIS or calculated with 3rd party plugins such as GRASS plugin?
    Although I manipulate point table data as you guided, I couldn’t convert point table to raster layer with Interpolation plugin. In addtion I tried it with GRASS tool (v.in.ogr.qgis) ;however, there were full of errors… :-(

    Please tell me detail information how did you convert data.

    Taro

    • underdark said:

      Hi Taro,

      The TIN was created using “Interpolation Plugin”. It’s a core plugin that offers TIN and IDW interpolation.

      • Taro said:

        Thank you for your prompt response!!!

        I wonder why I couldn’t convert point table to raster layer…
        When I tried it with “Interpolation Plugin” on QGIS 1.6, the parameters were set as follow

        [Input]
        vector layer: catchment_XXXX
        interpolation attribution: cost(length from point XXXX)
        [Output]
        interpolation method: TIN
        number of columns: 1000
        number of rows: 1000
        output file: ~/gisdata/catchmentTIN

        And my catchment_XXXX table has 3 fields: id, the_geom and cost.

        If there are some mistakes or insufficiet settings you found, please point out them.

        Taro

      • underdark said:

        Did you press “Add” to add the cost attribute to the list of interpolation attributes?

        Did you set the extent (xmin, xmax, ymin, ymax)?

  2. Taro said:

    Thnk you for your advices :-)

    In my case, there were no problems with setting parameters: I added the cost attribute to the list of interpolation attributes and set the extent using the “Set to current extent” button.

    However, when I have just tried to convert same data(point table) to raster layer a little while ago, “Interpolation Plugin” worked well with the same parameters !!! It’s not known exactly why…
    And a new problem comes: after importing interpolation layer made with “Interpolation Plugin”, QGIS does not display colored interpolation layer…
    Incidentally, QGIS displays contour lines made with “Contour” from GdalTools to visualize equal-cost areas as you posted.

    There may have been problems with installation of QGIS or OS(Ubuntu 10.04)…

    • underdark said:

      You have to style the interpolated raster layer by hand. You can use color map to specify a suitable gradient for your use case.

  3. Taro said:

    Thank you for your reply@
    It go well with OSGeo Live DVD (^^

  4. col said:

    Hi, thank you for the tutorial.
    I went through “A Beginner’s Guide to pgRouting” and “Catchment Areas with pgRouting driving_distance()” without problems.

    In the above tutorial, I’m getting a problem with these request as I do not manage to calculate the distance of node #5657 for instance with all the other node symbolised by the “id,” if I understand correctly.
    I’m getting an error message “Target vertex was not found.”
    If I’m using a node number instead of id, the request is working.

    Any idea of the problem origin would be welcome.

    Thanks

      • col said:

        Yes I do, I’ll try again everything form scratch. I could have made a mistake somewhere.

        Thanks.

      • col said:

        Now it’s working, do not know exactly why, I thing that my cost field didn’t had flaot 8 datatype.

        Best regards.

%d bloggers like this: