[GRASS-user] Update categories/attribute table after v.clean with option break

Markus Metz markus.metz.giswork at gmail.com
Wed Sep 7 12:27:14 PDT 2016


On Wed, Sep 7, 2016 at 10:06 AM, Johannes Radinger
<johannesradinger at gmail.com> wrote:
> Hi,
>
> I have a vector line map (river network) which I want to clean and break the
> lines at intersections. Therefore, I use the tool v.clean with the option
> break. This of course increases the number of vector lines as several lines
> got broken into two or more separate lines. Now there is a attribute table
> linked to the original map. I want to update this attribute table by
> inserting a new column that contains a new unique ID (cat) for each line but
> still keeps the old cat in another column (E.g. old_cat). Thus the attribute
> table should also increase in number of rows (=number of lines).
>
> Now, most likely the tool to use now is v.category to get a column of new
> unique categories (in another table/layer?) and the use probably a join
> statement to get back the information from the original table (with doubled
> entries for those lines that got broken during v.clean).
>
> What I tried so far:
>
> #########################
> # Cleaning vector and breaking lines
> v.clean -c --overwrite input=river_network_modified
> output=river_network_modified_clean tool=break,snap,rmline threshold=0,50,0
>
> # Check cats
> v.category input=river_network_modified_clean option=report layer=-1
> # type       count        min        max
> # line       16592          1      16448
>
> # Update cats
> v.category -t --overwrite input=river_network_modified_clean type=line
> output=river_network_modified_clean2 option=del

v.category option=del deletes the selected category value for the
selected layer and selected geometry types. By default, categories
with value 1 in layer 1 are deleted for all points, lines, centroids,
and faces. This is probably not what you want.

Instead, you could try to add new categories to a new layer, e.g. with

v.category option=add layer=2 cat=1 step=1 type=line

Now add a new table to layer 2
v.db.addtable layer=2 columns="cat_lyr1 integer"

Load category values (or any other attributes) from layer 1 to layer 2 with
v.to.db layer=2 column=cat_lyr1 query_layer=1 query_column=cat

Now you have unique new categories in layer 2 and the old categories
still existing in layer 1 are also in the field cat_lyr1 of layer 2.

HTH,

Markus M

> v.category -t --overwrite input=river_network_modified_clean2 type=line
> output=river_network_modified_clean3 option=add
>
> # Check cats
> v.category input=river_network_modified_clean2 option=report layer=-1
> # Layer: 1
> # type       count        min        max
> # line       16591          2      16448
>
> # Check cats
> v.category input=river_network_modified_clean3 option=report layer=-1
> # Layer: 1
> # type       count        min        max
> # line       16592          1      16448
> ########################
>
> However, I expected the max values of the latest (updated) vector to be
> 16592 to have really unique values for all 16592 lines (from 1 to 16592)?
> But the output shows the same information as the initial input map? Probably
> I am still mixing up things with categories/layers... and maybe someone has
> a quick hint how to get an updated attribute table for a map that has been
> processed using v.clean and where lines were broken.
>
> /johannes
>
>
>
>
> _______________________________________________
> grass-user mailing list
> grass-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-user


More information about the grass-user mailing list