On 29/11/18 08:55, Ken Mankoff wrote:
Hi GRASS list,
How do I find out the length of each segment after running v.split?
I have this code:
v.split -f input=v output=v_split units=meters length=100 --o
I'd like to know the length. Presumably they are 100 m, but the last segment of each line in 'v' must be less than or equal to that.
I tried this:
v.db.addcolumn map=v_split column="length double precision"
v.to.db map=v_split type=line option=length columns=length units=meters
When I display with 'd.vect' and click, I see both 'v' and 'v_split'. When I click on a segment I see the total length of 'v' and the 100 m (or 42.214 for the end segment) of 'v_split'. But I don't see it when I query it at the command line with:
db.select sql='select * from v_split'
In this case, it only reports the original few segments from 'v', not the many 100s of segments from 'v_split'. It appears both vectors are linked to the same table.
Still (sometimes) trying to figure out the GRASS DB and layers connected to tables...
v.split does not change the layer, nor the category information, nor the attribute table links of the original file. It just splits each line in segments and attributes the same category to all segments of the same original line. As the attribute table is linked to the features with their category as key, all segments originating from the same original line are linked to the same line in the original attribute table which is just copied to the new map.
When you run v.to.db on this, it will add length information for each segment in its respective attribute line, but since all the segments of the same original line share the same attribute table line, it only gets updated once.
If you want the length of each segment, you will have to attribute different category values to all of them. The best is to this on a separate layer, using v.category
v.category v_split op=add layer=2 output=v_split_2
then you can run your above commands on that layer:
v.db.addcolumn map=v_split_2 column="length double precision layer=2
v.to.db map=v_split_2 type=line option=length columns=length units=meters layer=2
This info should probably somehow go into the man page of v.split.
Moritz