div id="container">

Shortest path with road cuts

In the previous exercise the paths have been computed using all the streets available. Suppose there are road works in Raleigh city and and you want to find the shortest path using only the open streets. You can close some streets in one or both driving ways.
This can be done assigning a cost to the streets using one column of the attribute table: closed streets have a cost of -1.

You are going to add two new columns to the attribute table: one containing the cost of moving forward ( in the same sense of the line direction) and the other with the cost of moving backwards. In each column is copied the length of the street and then you are going to manually close some writing the value -1.

First you have to check that each line has a different category, in order to avoid to add the same length to different sections of the network:

> v.category in=network op=report

the above command outputs

Layer/table: 1/network
type count min max
point 0 0 0
line 8827 1 8819
boundary 0 0 0
centroid 0 0 0
area 0 0 0
all 8827 1 8819
Layer/table: 2/firestations_central
type count min max
point 4 21 52
line 0 0 0
boundary 0 0 0
centroid 0 0 0
area 0 0 0
all 4 21 52

The streets are 8827 for 8819 categories on layer 1: 8 streets have duplicated category. In order to fix it you need to add a new layer, layer 3, with new categories in the map network_cat3:

> v.category --overwrite --verbose input=network output=network_cat3 type=line layer=3 cat=1

Now the command

> v.category in=network_cat3 op=report

gives this output

Layer/table: 1/network_cat3_1
type count min max
point 0 0 0
line 8827 1 8819
boundary 0 0 0
centroid 0 0 0
area 0 0 0
all 8827 1 8819
Layer: 3
type count min max
point 0 0 0
line 8827 1 8827
boundary 0 0 0
centroid 0 0 0
area 0 0 0
all 8827 1 8827
Layer/table: 2/network_cat3_2
type count min max
point 4 21 52
line 0 0 0
boundary 0 0 0
centroid 0 0 0
area 0 0 0
all 4 21 52

You have to link again the tables to this new map. Layer 1 is linked to street table:

> v.db.connect -o --verbose map=network_cat3@user1 table=network layer=1

Create firestations_central again because of a bug in v.net erases it:

> v.select --overwrite --verbose ainput=firestations atype=point binput=region_central btype=area output=firestations_central

Layer 2 is linked to fire stations map:

> v.db.connect -o --verbose map=network_cat3@user1 table=firestations_central layer=2

You can then add a table to the layer 3, that will be by default named network_cat3_3, with two columns called lungh_a for forward costs and lungh_i for backwards moving costs.

> v.db.addtable --verbose map=network_cat3@user1 layer=3 columns="cat integer, lungh_a double, lungh_i double"

You write the lenght into the table assuming for now that forward cost=backward ost=street lenght. On layer 3 every street has a different category, so every column contains the appropriate length:

> v.to.db --verbose map=network_cat3 type=line,boundary layer=3 qlayer=3 option=length columns=lungh_a

> v.to.db --verbose map=network_cat3 type=line,boundary layer=3 qlayer=3 option=length columns=lungh_i

Let's calculate again the shortest path as in the previous example, but this time the costs are read from the table. Result is saved in the new map path_21_26_db:

> echo "2 21 26"|v.net.path --overwrite input=network_cat3@user1 output=path_21_26_db alayer=3 afcolumn=lungh_a abcolumn=lungh_i


Shortest path between Trailwood Drive and Oberlin Road fire stations - costs from table.

The result is the same, because the costs are always the lengths.

Now you are going to close to traffic the first portion of the road between Trailwood Drive (cat 21) and Oberlin Road (cat 26). Query the map with the mouse to find the category of the road to be closed on map network_cat3 layer 3: it is 6658.

See details for this road on layer 1:

> echo "select a_CARTONAM from network where cat=6658"|db.select

a_CARTONAM
NEW BERN AVE

on layer 3

> echo "select * from network_cat3_3 where cat=6658"|db.select

cat|lungh_a|lungh_i
6658|1237.159234|1237.159234

Let's close New Bern Avenue (street 6658) giving to it a cost of -1. Forward:

> echo "UPDATE network_cat3_3 SET lungh_a=-1 WHERE cat=6658" | db.execute

Backward

> echo "UPDATE network_cat3_3 SET lungh_i=-1 WHERE cat=6658" | db.execute

Check that New Bern Avenue is now closed on layer 3:

> echo "select * from network_cat3_3 where cat=6658"|db.select

cat|lungh_a|lungh_i
6658|-1|-1

Repeat the previous shortest path search under changed condition and save it to map path_21_26_db_no_new_bern_ave,:

> echo "2 21 26"|v.net.path --overwrite input=network_cat3@user1 output=path_21_26_db_no_new_bern_ave alayer=3 afcolumn=lungh_a abcolumn=lungh_i


Shortest path between Trailwood Drive and Oberlin Road - New Bern Avenue (green) closed

The shortest path has changed, see the green path avoiding New Bern Avenue.

Before going to the next step, reset the travelling costs forward:

> v.to.db --verbose map=network_cat3 type=line,boundary layer=3 qlayer=3 option=length columns=lungh_a

and backwards

> v.to.db --verbose map=network_cat3 type=line,boundary layer=3 qlayer=3 option=length columns=lungh_i