[GRASS-user] Unique IDs for network segments

Hi all,

I built a GRASS7 network using v.net:

First, I used the ‘connect’ option to snap some points to my network (using the -s flag)
Second, I used that first network and also added all nodes with the ‘nodes’ option to get a final network.

With the ‘report’ option of v.net I can report all edges with their start and end end points. However, these edges of the final network are based on the initial category values of the input vector. How can I get the network split into single lines with unique IDs between each node of the final network. In other words I want a report of v.net that contains only unique edge categories? I’d like to write the output of v.net into a new table and assign lengths to each edge.

For example, at the moment, a line with cat=300 is confined by a start node cat=1 and an end node cat=2. For that case v.net reports:
300 1 2

If I connect a new node with cat=3 along that line and calculate v.net, it reports:
300 1 3

300 3 2

Any ideas/suggestions? Maybe I need to ‘break’ the network lines at each node before running v.net?

/Johannes

Hi Moritz,

The two-step v.category approach (del + add) and an additional v.to.db() was the
right way. Now I have the problem that there are 3 categories reported for
one single line that got split into to (1 old cat + 2 new cats). The old category is still
associated with attributes but the two new rows are empty. How can
I get an attribute table that contains only rows for the new cats with the attribute information
of the old category?

Here a working example (in the NC location) for illustrating my problem:

Import test line to GRASS GIS

echo “ORGANIZATION: GRASS Development Team
DIGIT DATE: 03/12/2015
DIGIT NAME: -
MAP NAME: test_lines
MAP DATE: 2015
MAP SCALE: 10000
OTHER INFO: test lines
ZONE: 0
MAP THRESH: 0.500000
VERTI:
L 3 1
641045.70521951 218398.66077254
641049.6221644 218261.56770124
641026.12049504 218155.8101891
1 5” | v.in.ascii --o format=standard input=- output=test_lines

Add attribute table to imported line

v.db.addtable map=test_lines

Add some attributes to table including the original cat as attribute

v.db.addcolumn map=test_lines@fidimo_test columns=“col1 INT, old_cat INT”
v.db.update map=test_lines@fidimo_test column=col1 value=42
v.db.update map=test_lines@fidimo_test column=old_cat query_column=cat

Import Point

echo “100|641045.940579|218320.669742” | v.in.ascii --o input=- output=mypoints x=2 y=3 cat=1

Create network

v.net -s --overwrite input=test_lines
points=mypoints output=test_net operation=connect threshold=25

Remove existing cats

v.category --overwrite input=test_net type=line cat=-1 output=test_net_nocat option=del

Add new cats

v.category --overwrite input=test_net_nocat type=line output=test_net_newcat option=add
v.to.db map=test_net_newcat type=line option=cat columns=cat

···

On Wed, Dec 2, 2015 at 4:55 PM, Moritz Lennert <mlennert@club.worldonline.be> wrote:

On 02/12/15 15:40, Johannes Radinger wrote:

Hi all,

I built a GRASS7 network using v.net <http://v.net>:

First, I used the ‘connect’ option to snap some points to my network
(using the -s flag)
Second, I used that first network and also added all nodes with the
‘nodes’ option to get a final network.

With the ‘report’ option of v.net <http://v.net> I can report all edges
with their start and end end points. However, these edges of the final
network are based on the initial category values of the input vector.
How can I get the network split into single lines with unique IDs
between each node of the final network. In other words I want a report
of v.net <http://v.net> that contains only unique edge categories? I’d
like to write the output of v.net <http://v.net> into a new table and
assign lengths to each edge.

For example, at the moment, a line with cat=300 is confined by a start
node cat=1 and an end node cat=2. For that case v.net <http://v.net>
reports:
300 1 2

If I connect a new node with cat=3 along that line and calculate v.net
<http://v.net>, it reports:
300 1 3
300 3 2

Any ideas/suggestions? Maybe I need to ‘break’ the network lines at each
node before running v.net <http://v.net>?

How about v.category op=delete type=line followed by v.category op=add type=line ?

Moritz

On 03/12/15 14:19, Johannes Radinger wrote:

Hi Moritz,

The two-step v.category approach (del + add) and an additional v.to.db()
  was the
right way. Now I have the problem that there are 3 categories reported for
one single line that got split into to (1 old cat + 2 new cats). The old
category is still
associated with attributes but the two new rows are empty. How can
I get an attribute table that contains only rows for the new cats with
the attribute information
of the old category?

[...]

# Remove existing cats
v.category --overwrite input=test_net type=line cat=-1
output=test_net_nocat option=del

[...]

# Add new cats
v.category --overwrite input=test_net_nocat type=line
output=test_net_newcat option=add
v.to.db map=test_net_newcat type=line option=cat columns=cat
#############

Instead of removing the existing cats, add new cats in a new layer and transfer the info into that layer's attribute table:

v.category --overwrite input=test_net type=line output=test_net_newcat option=add layer=3
v.db.addtable test_new_newcat layer=3
v.db.addcolumn test_net_newcat lay=3 col="col1 int, old_cat int"
v.to.db test_net_newcat layer=3 op=query col=col1 query_layer=1 query_colum=col1
v.to.db test_net_newcat layer=3 op=query col=old_cat query_layer=1 query_colum=cat

Just make sure to set arc_layer=3 in the network analysis modules.

If you really want to have arcs in layer 1, you can use v.category op=transfer, but you will also have to change table connections of the layers with v.db.connect.

Moritz

Moritz,
thank you! Your proposed approach solved my problem!

···

On Thu, Dec 3, 2015 at 3:04 PM, Moritz Lennert <mlennert@club.worldonline.be> wrote:

On 03/12/15 14:19, Johannes Radinger wrote:

Hi Moritz,

The two-step v.category approach (del + add) and an additional v.to.db()
was the
right way. Now I have the problem that there are 3 categories reported for
one single line that got split into to (1 old cat + 2 new cats). The old
category is still
associated with attributes but the two new rows are empty. How can
I get an attribute table that contains only rows for the new cats with
the attribute information
of the old category?

[…]

Remove existing cats

v.category --overwrite input=test_net type=line cat=-1
output=test_net_nocat option=del

[…]

Add new cats

v.category --overwrite input=test_net_nocat type=line
output=test_net_newcat option=add
v.to.db map=test_net_newcat type=line option=cat columns=cat
#############

Instead of removing the existing cats, add new cats in a new layer and transfer the info into that layer’s attribute table:

v.category --overwrite input=test_net type=line output=test_net_newcat option=add layer=3
v.db.addtable test_new_newcat layer=3
v.db.addcolumn test_net_newcat lay=3 col=“col1 int, old_cat int”
v.to.db test_net_newcat layer=3 op=query col=col1 query_layer=1 query_colum=col1
v.to.db test_net_newcat layer=3 op=query col=old_cat query_layer=1 query_colum=cat

Just make sure to set arc_layer=3 in the network analysis modules.

If you really want to have arcs in layer 1, you can use v.category op=transfer, but you will also have to change table connections of the layers with v.db.connect.

Moritz