[GRASS-user] Re: Add DB entries to vector line (after v.split)

Date: Tue, 25 Oct 2011 12:37:36 -0700 (PDT)
From: wittich <vwittich@gmail.com>
Subject: [GRASS-user] Re: Add DB entries to vector line (after
v.split)
To: grass-user@lists.osgeo.org
Message-ID: <1319571456756-6930154.post@n2.nabble.com>
Content-Type: text/plain; charset=us-ascii

v.info lines_split

±---------------------------------------------------------------------------+
| Layer: lines_split
| Map format: native

|----------------------------------------------------------------------------
| Type of Map: vector (level: 2)
| Number of points: 0 Number of areas: 0
| Number of lines: 598 Number of islands: 0
| Number of boundaries: 0 Number of faces: 0
| Number of centroids: 0 Number of kernels: 0
|
| Map is 3D: No
| Number of dblinks: 1
|
| Digitization threshold: 0
| Comments:

±---------------------------------------------------------------------------+

v.category in=lines_split opt=report
Layer/table: 1/lines_split
type count min max
point 0 0 0
line 598 1 3
boundary 0 0 0
centroid 0 0 0
area 0 0 0
all 598 1 3

Vector map looks normal.

Maybe try to run one more time:
v.category in=lines_split out=lines_split_nocats type=line opt=del
v.category in=lines_split_nocats out=lines_split_newcats type=line opt=add
??

Interestingly 4 years later and using V.split in grass7 and I'm still having
the same problem....

tried the v.category solution and the cats were never deleted. My system
will also not install the v.to.equidist add on. Export and import as shape
worked though. Sure is odd that this ins't possible using v.split

--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Add-DB-entries-to-vector-line-after-v-split-tp3885510p5204496.html
Sent from the Grass - Users mailing list archive at Nabble.com.

On 06/05/15 22:12, knussear wrote:

Interestingly 4 years later and using V.split in grass7 and I'm still having
the same problem....

tried the v.category solution and the cats were never deleted.

Are you sure ? In the original thread, the check for success was wrong [1]: v.db.select checks the attached attribute table (which v.split does not modify), not the categories present in the features.

Here's a working example using a simple vector map with three lines:

v.split test_line out=line_test_split length=5000

v.category line_test_split op=report
Layer/table: 1/line_test_split
type count min max
point 0 0 0
line 46 2 4
boundary 0 0 0
centroid 0 0 0
area 0 0 0
face 0 0 0
kernel 0 0 0
all 46 2 4

Now, two options:

1) You want to keep the category values of the original lines, but also add individual category values for the new segements. Here GRASS's layer paradigm comes in handy, allowing you to create a second layer of information:

#create second information layer containing new individual category values for the segments
v.category line_test_split out=line_test_split_w_lay2 layer=2 op=add

v.category line_test_split_w_lay2 op=report
Layer/table: 1/line_test_split_w_lay2
type count min max
point 0 0 0
line 46 2 4
boundary 0 0 0
centroid 0 0 0
area 0 0 0
face 0 0 0
kernel 0 0 0
all 46 2 4
Layer/table: 2/line_test_split_w_lay2_2
type count min max
point 0 0 0
line 46 1 46
boundary 0 0 0
centroid 0 0 0
area 0 0 0
face 0 0 0
kernel 0 0 0
all 46 1 46

Now you can add a new attribute table to the second layer:

v.db.addtable line_test_split_w_lay2 layer=2

If you want to integrate the old categories (or anything else from the original attribute table) into the attribute table of the new segments:

v.db.addcolumn line_test_split_w_lay2 col="old_cat int" layer=2
v.to.db line_test_split_w_lay2 layer=2 query_layer=1 op=query query_col=cat col=old_cat

v.db.select line_test_split_w_lay2 layer=2
cat|old_cat
1|2
2|2
3|2
4|2
5|2
6|2
7|2
8|2
9|2
10|2
11|2
12|2
13|2
14|2
15|2
16|2
17|3
18|3
19|3
20|3
21|3
etc...

2) You just need the segments with individual category values, but not the old line categories, nor the old attribute table:

#delete old cats, don't keep old attribute table to avoid confusion
v.category -t line_test_split op=del cat=-1 out=line_test_split_wo_cats

#add new cats
v.category line_test_split_wo_cats out=line_test_split_w_new_cats op=add

#now, if necessary create new attribute table prefilled with cat values
v.db.addtable line_test_split_w_new_cats

My system
will also not install the v.to.equidist add on.

Which version of GRASS are you using. The addon was developed for GRASS 6.

It is a simple shell script which you can download from [2], but I haven't checked if it will run as-is in GRASS 7

Moritz

[1] http://lists.osgeo.org/pipermail/grass-user/2011-October/062318.html
[2] https://raw.githubusercontent.com/amuriy/GRASS-scripts/master/v.to.equidist

Thanks very much, that is all working well. I did try the addon you mention, but using grass7 it wont install in either linux or mac os

I’m having some trouble with the final layer though when trying to sample a raster…

Using this command

v.what.rast map=TSELinesSplit500_w_lay2@PERMANENT type=centroid raster=a250m_ATI@MojaveCovariates_250m column=RC1

WARNING: No record for category 0 in table <TSELinesSplit500_w_lay2>

Any idea why I have no category 0?

Ken

(attachments)

compose-unknown-contact.jpg

<v.to.equidist> addon doesn’t work under GRASS 7 (only 6.4.*). But I still have plans to rewrite it in Python :slight_smile: You could also try the addon <v.fixed.segmentpoints>, it works similary.

(attachments)

compose-unknown-contact.jpg

···

2015-05-08 20:10 GMT+03:00 Ken Nussear <knussear@mac.com>:

Thanks very much, that is all working well. I did try the addon you mention, but using grass7 it wont install in either linux or mac os

I’m having some trouble with the final layer though when trying to sample a raster…

Using this command

v.what.rast map=TSELinesSplit500_w_lay2@PERMANENT type=centroid raster=a250m_ATI@MojaveCovariates_250m column=RC1

WARNING: No record for category 0 in table <TSELinesSplit500_w_lay2>

Any idea why I have no category 0?

Ken

Moritz Lennert
May 7, 2015 at 2:54 AM

On 06/05/15 22:12, knussear wrote:

Interestingly 4 years later and using V.split in grass7 and I’m still having
the same problem…

tried the v.category solution and the cats were never deleted.

Are you sure ? In the original thread, the check for success was wrong [1]: v.db.select checks the attached attribute table (which v.split does not modify), not the categories present in the features.

Here’s a working example using a simple vector map with three lines:

v.split test_line out=line_test_split length=5000

v.category line_test_split op=report
Layer/table: 1/line_test_split
type count min max
point 0 0 0
line 46 2 4
boundary 0 0 0
centroid 0 0 0
area 0 0 0
face 0 0 0
kernel 0 0 0
all 46 2 4

Now, two options:

  1. You want to keep the category values of the original lines, but also add individual category values for the new segements. Here GRASS’s layer paradigm comes in handy, allowing you to create a second layer of information:

#create second information layer containing new individual category values for the segments
v.category line_test_split out=line_test_split_w_lay2 layer=2 op=add

v.category line_test_split_w_lay2 op=report
Layer/table: 1/line_test_split_w_lay2
type count min max
point 0 0 0
line 46 2 4
boundary 0 0 0
centroid 0 0 0
area 0 0 0
face 0 0 0
kernel 0 0 0
all 46 2 4
Layer/table: 2/line_test_split_w_lay2_2
type count min max
point 0 0 0
line 46 1 46
boundary 0 0 0
centroid 0 0 0
area 0 0 0
face 0 0 0
kernel 0 0 0
all 46 1 46

Now you can add a new attribute table to the second layer:

v.db.addtable line_test_split_w_lay2 layer=2

If you want to integrate the old categories (or anything else from the original attribute table) into the attribute table of the new segments:

v.db.addcolumn line_test_split_w_lay2 col=“old_cat int” layer=2
v.to.db line_test_split_w_lay2 layer=2 query_layer=1 op=query query_col=cat col=old_cat

v.db.select line_test_split_w_lay2 layer=2
cat|old_cat
1|2
2|2
3|2
4|2
5|2
6|2
7|2
8|2
9|2
10|2
11|2
12|2
13|2
14|2
15|2
16|2
17|3
18|3
19|3
20|3
21|3
etc…

  1. You just need the segments with individual category values, but not the old line categories, nor the old attribute table:

#delete old cats, don’t keep old attribute table to avoid confusion
v.category -t line_test_split op=del cat=-1 out=line_test_split_wo_cats

#add new cats
v.category line_test_split_wo_cats out=line_test_split_w_new_cats op=add

#now, if necessary create new attribute table prefilled with cat values
v.db.addtable line_test_split_w_new_cats

My system
will also not install the v.to.equidist add on.

Which version of GRASS are you using. The addon was developed for GRASS 6.

It is a simple shell script which you can download from [2], but I haven’t checked if it will run as-is in GRASS 7

Moritz

[1] http://lists.osgeo.org/pipermail/grass-user/2011-October/062318.html
[2] https://raw.githubusercontent.com/amuriy/GRASS-scripts/master/v.to.equidist


grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

On 08/05/15 19:10, Ken Nussear wrote:

Thanks very much, that is all working well. I did try the addon you
mention, but using grass7 it wont install in either linux or mac os

It's just a shell script, so you might be able to just download it and run it in a GRASS GIS session, unless the script uses specific grass6 features.

I'm having some trouble with the final layer though when trying to
sample a raster....

Using this command

v.what.rast map=TSELinesSplit500_w_lay2@PERMANENT type=centroid
raster=a250m_ATI@MojaveCovariates_250m column=RC1

WARNING: No record for category 0 in table <TSELinesSplit500_w_lay2>

Any idea why I have no category 0?

This actually sounds like you have a feature with category 0 (which AFAIK shouldn't happen, unless you ask for it explicitely), but that there is no entry for this feature in the attribute table.

You could run v.to.db op=cat to create entries in the table for any features that don't have one yet.

Moritz