Opened 6 years ago

Closed 4 years ago

Last modified 4 years ago

#2304 closed defect (fixed)

Problems with add category to all features workflow

Reported by: wenzeslaus Owned by: grass-dev@…
Priority: normal Milestone: 7.2.0
Component: Default Version: unspecified
Keywords: v.edit, v.category Cc:
CPU: Unspecified Platform: Unspecified

Description

This ticket contains several issues but they relates on to another and I encountered them doing one thing. My goal was to set a new category to all features in a vector map. I wanted all features to have the same category.

Prepare test data:

v.in.ascii input=- output=test separator=comma <<EOF
913240.0,250614.0
913250.0,250628.0
EOF

Check categories in tests data:

v.what map=test coordinates=913240.0,250614.0
East: 913240
North: 250614
------------------------------------------------------------------
Map: test 
Mapset: jr_contours
Type: Point
Id: 1
Layer: 1
Category: 1

Try to add category to all features (using example in G7:v.edit manual but leaving out polygon parameter for selection because we want all features):

v.edit map=test3 tool=catadd layer=2 cats=10

A warning is generated but it still builds the topology:

Selecting features...
0 of 2 features selected from vector map <test3@jr_sts_contours>
WARNING: No features selected, nothing to edit
Building topology for vector map <test3@jr_sts_contours>...
Registering primitives...
2 primitives registered
2 vertices registered
Building areas...
 100%
0 areas built
0 isles built
Attaching islands...
Attaching centroids...
 100%
Number of nodes: 0
Number of primitives: 2
Number of points: 2
Number of lines: 0
Number of boundaries: 0
Number of centroids: 0
Number of areas: 0
Number of isles: 0
v.edit complete.

For more complex map (a lot of lines) I got in this step:

Selecting features...
0 of 56 features selected from vector map <contours_level_12@jr_contours>
WARNING: No features selected, nothing to edit
Building topology for vector map <contours_level_120@jr_contours>...
Registering primitives...
v.edit: spindex_rw.c:1364: rtree_get_node: Assertion
`t->nb[level][which].n.level == level' failed.

However, something went wrong and spatial index is broken:

v.what map=test coordinates=913240.0,250614.0
ERROR: Unable to open spatial index file for vector map
       <test@jr_contours>

Building topology helps:

v.build map=test
Building topology for vector map <test@jr_contours>...
Registering primitives...
2 primitives registered
2 vertices registered
Building areas...
 100%
0 areas built
0 isles built
Attaching islands...
Attaching centroids...
 100%
Number of nodes: 0
Number of primitives: 2
Number of points: 2
Number of lines: 0
Number of boundaries: 0
Number of centroids: 0
Number of areas: 0
Number of isles: 0

Now we see that nothing changed in the map which was expected because no features were selected:

v.what map=test coordinates=913240.0,250614.0
East: 913240
North: 250614
------------------------------------------------------------------
Map: test 
Mapset: jr_contours
Type: Point
Id: 1
Layer: 1
Category: 1

Since no features were selected last time, let's try to reverse selection using -r flag. Note also that parameters layer and cats are in section Selection in GUI but we will use them as input here.

v.edit -r map=test tool=catadd layer=2 cats=10 

This selects all features which is what we want:

Selecting features...
2 of 2 features selected from vector map <test@jr_contours>
2 features modified
Building topology for vector map <test@jr_contours>...
Registering primitives...
2 primitives registered
2 vertices registered
Building areas...
 100%
0 areas built
0 isles built
Attaching islands...
Attaching centroids...
 100%
Number of nodes: 0
Number of primitives: 2
Number of points: 2
Number of lines: 0
Number of boundaries: 0
Number of centroids: 0
Number of areas: 0
Number of isles: 0
v.edit complete.

Result is OK, there is a layer 2 and our feature has category 10.

v.what map=test coordinates=913240.0,250614.0
East: 913240
North: 250614
------------------------------------------------------------------
Map: test
Mapset: jr_contours
Type: Point
Id: 1
Layer: 1
Category: 1
Layer: 2
Category: 10

Check categories of all features using G7:r.category. Note that the parameter which was called tool in G7:v.edit is called option in G7:r.category:

v.category input=test option=report
Layer: 1
type       count        min        max
point          2          1          2
...
all            2          1          2
Layer: 2
type       count        min        max
point          2         10         10
...
all            2         10         10
v.category complete. 0 features modified.

Although G7:v.edit worked with categories, G7:v.category might be better. For start, let's try example from manual (using the same testing data as in previous case):

v.category input=test_5 output=test_5_step option=add step=5
Processing features...
Copying attribute table(s)...
Building topology for vector map <test_5_step@jr_contours>...
Registering primitives...
2 primitives registered
2 vertices registered
Building areas...
 100%
0 areas built
0 isles built
Attaching islands...
Attaching centroids...
 100%
Number of nodes: 0
Number of primitives: 2
Number of points: 2
Number of lines: 0
Number of boundaries: 0
Number of centroids: 0
Number of areas: 0
Number of isles: 0
v.category complete. 0 features modified.

0 features modified and report tells us that output contains categories from 1 to 2:

v.category input=test_5_step option=report
Layer: 1
type       count        min        max
point          2          1          2
line           0          0          0
boundary       0          0          0
centroid       0          0          0
area           0          0          0
face           0          0          0
kernel         0          0          0
all            2          1          2
v.category complete. 0 features modified.

What we actually want is to add a new category, same for all features:

v.category input=test_5 output=test_5_cat option=add cat=20
Processing features...
Copying attribute table(s)...
Building topology for vector map <test_5_cat@jr_contours>...
Registering primitives...
2 primitives registered
2 vertices registered
Building areas...
 100%
0 areas built
0 isles built
Attaching islands...
Attaching centroids...
 100%
Number of nodes: 0
Number of primitives: 2
Number of points: 2
Number of lines: 0
Number of boundaries: 0
Number of centroids: 0
Number of areas: 0
Number of isles: 0
v.category complete. 0 features modified.

0 features modified, and we still have category range 1-2:

v.category input=test_5_cat option=report
Layer: 1
type       count        min        max
point          2          1          2
line           0          0          0
boundary       0          0          0
centroid       0          0          0
area           0          0          0
face           0          0          0
kernel         0          0          0
all            2          1          2
v.category complete. 0 features modified.

Since I'm actually patching multiple maps, I hoped that a note about v.category option=sum in G7:v.patch manual will help me:

v.category input=test_5 output=test_5_sum option=sum cat=30
Processing features...
Copying attribute table(s)...
Building topology for vector map <test_5_sum@jr_sts_contours>...
Registering primitives...
2 primitives registered
2 vertices registered
Building areas...
 100%
0 areas built
0 isles built
Attaching islands...
Attaching centroids...
 100%
Number of nodes: 0
Number of primitives: 2
Number of points: 2
Number of lines: 0
Number of boundaries: 0
Number of centroids: 0
Number of areas: 0
Number of isles: 0
v.category complete. 2 features modified.

This is doing something, features were modified but it is of course (according to G7:v.category manual) not what I want. It is sum is adding a value to a current category.

v.category input=test_5_sum option=report
Layer: 1
type       count        min        max
point          2         31         32
line           0          0          0
boundary       0          0          0
centroid       0          0          0
area           0          0          0
face           0          0          0
kernel         0          0          0
all            2         31         32
v.category complete. 0 features modified.

Summary:

  • it is not clear how to select all features in v.edit
  • some parameters/options in v.edit have guisection Selection but they can be used also as an input
  • v.edit builds topology when there is nothing to edit
  • v.edit breaks the topology/spatial index when the selection of features was empty, ends with assert sometimes
  • there is a space after map name in v.what output
  • v.category has a parameter/option option while v.edit has a parameter tool
  • v.category builds topology when there was no change
  • v.category does nothing for option=step and option=add using option=sum under the same conditions gives a result if there is something else to add, it is not in the example in manual
  • v.category says 0 features modified. when it finished report or print but it seems redundant I wouldn't expect something else when using report or print and not providing output
  • if you will try to explore it using GUI query tool, you will see that it shows only one layer and one category (it seems that underlying vector_what(map="...", coord=...) and v.what works)

We might create separate tickets from these but now I'm not sure what are my mistakes, what is wrong documentation and how critical the bugs are are or if they are just feature request.

Change History (8)

comment:1 Changed 6 years ago by wenzeslaus

I would say that the underlying issue is still present but since topology is not build v.edit anymore thanks to r60392, the issue with broken spatial index when no features were selected is gone. My GRASS was not fresh enough when filling the ticket.

v.in.ascii input=- output=test separator=comma <<EOF
913240.0,250614.0
913250.0,250628.0
EOF
v.edit map=test tool=catadd layer=2 cats=10
Selecting features...
0 of 2 features selected from vector map <test_6@jr_sts_contours>
WARNING: No features selected, nothing to edit
v.edit complete.
v.what map=test coordinates=913240.0,250614.0

This was Unable to open spatial index file for vector map before r60392.

East: 913240
North: 250614
------------------------------------------------------------------
Map: test
Mapset: jr_contours
Type: Point
Id: 1
Layer: 1
Category: 1
v.category input=test option=report
Layer: 1
type       count        min        max
point          2          1          2
...
all            2          1          2
v.category complete. 0 features modified.

The trick with -r flag still works.

comment:2 Changed 6 years ago by mlennert

This sound more like a usage (and partly documentation) problem to me.

The v.edit man page clearly says:

catadd: Set new categories to selected vector features for defined layer

i.e. you have to select the features you want to add cats to using any of the selection options v.edit offers (id, bbox, coords, polygon, ...). If you don't select anything, no feature will be touched. For example, you can just use v.info -g to get the bbox. Obviously, your -r trick does work, but v.edit works as expected.

v.category option=add only adds category values to features which do not have category values in the chosen layer. The man page does not seem to mention this, so this should probably be added using something like this:

Index: main.c
===================================================================
--- main.c	(révision 60228)
+++ main.c	(copie de travail)
@@ -112,7 +112,7 @@
 	       "report;%s;"
 	       "print;%s;"
 	       "layers;%s",
-	       _("add a new category"),
+	       _("add a new category to features without category"),
 	       _("delete category (cat=-1 to delete all categories of given layer)"),
 	       _("change layer number (e.g. layer=3,1 changes layer 3 to layer 1)"),
 	       _("add the value specified by cat option to the current category value"),

Except for this small documentation issue, I would suggest closing this bug as invalid.

Moritz

comment:3 Changed 6 years ago by wenzeslaus

Yes, from a big part it is a documentation issue because it not clear how to do it and I would say that it is quite basic functionality if you consider patching several maps together.

I would say that v.category's option=add should say

add a category to features without category

because the new is strange when there is no old. Maybe missing category would be good too. If this is what it is doing, I can commit it later.

Where do you get data with layer but no category anyway?

Summary update:

  • it is not clear how to select all features in v.edit
    • there is the -r trick but it is not clear if it it supported
    • it is possible to get bbox and pass it (comment:2), this seems inconvenient to me
    • perhaps -a (Select all) flag to explicitly select all would be good
  • some parameters/options in v.edit have guisection Selection but they can be used also as an input
  • v.edit builds topology when there is nothing to edit
    • seems to be fixed by recent r60392
  • v.edit breaks the topology/spatial index when the selection of features was empty, ends with assert sometimes
    • whatever it was, it is hidden/disabled by r60392
  • there is a space after map name in v.what output
  • v.category has a parameter/option option while v.edit has a parameter tool
  • v.category builds topology when there was no change
  • v.category does nothing for option=step and option=add; using option=sum under the same conditions gives a result if there is something else to add, it is not in the example in manual
    • the issue with option=add is just unclear documentation
  • v.category says 0 features modified. when it finished report or print but it seems redundant I wouldn't expect something else when using report or print and not providing output
  • if you will try to explore it using GUI query tool, you will see that it shows only one layer and one category (it seems that underlying vector_what(map="...", coord=...) and v.what works)
    • this needs separate ticket

comment:4 Changed 6 years ago by mlennert

I find this a much too long list of items which are a mix of many different things (unclear documentation for the most part), that I think this bug should be closed and you should open separate tickets for those items you really feel are bugs/enhancement requests.

I've patched the v.category doc according to your suggestion (r60432/3 and r60435/7).

I agree that a "select all" option in v.edit might be helpful.

Moritz

comment:5 in reply to:  3 ; Changed 6 years ago by wenzeslaus

Since it was unclear to me what are the actual problems and how complicated they are, I was not able to fill separate tickets. I'm for closing this ticket as soon as every issue listed here is individually addressed, e.g. by reporting new ticket or by declaring it as not an issue.

Summary update follows.

Reported separately:

  • it is not clear how to select all features in v.edit
    • there is the -r trick but it is not clear if it it supported
    • it is possible to get bbox and pass it (comment:2), this seems inconvenient to me
    • perhaps -a (Select all) flag to explicitly select all would be good
    • feature request #2309

Resolved:

  • v.edit builds topology when there is nothing to edit
    • seems to be fixed by recent r60392
  • v.edit breaks the topology/spatial index when the selection of features was empty, ends with assert sometimes
    • whatever it was, it is hidden/disabled by r60392
  • v.category does nothing for option=add; using option=sum under the same conditions gives a result if there is something else to add, it is not in the example in manual
    • the issue with option=add is just unclear documentation
    • fixed by r60432 and others

Unresolved:

  • some parameters/options in v.edit have guisection Selection but they can be used also as an input
  • there is a space after map name in v.what output
  • v.category has a parameter/option option while v.edit has a parameter tool
  • v.category builds topology when there was no change
  • v.category does nothing for option=step; using option=sum under the same conditions gives a result if there is something else to add, it is not in the example in manual
  • v.category says 0 features modified. when it finished report or print but it seems redundant I wouldn't expect something else when using report or print and not providing output
  • in GUI query tool, you will see that it shows only one layer and one category
    • now I see that layers are there but they are represented as separate maps which is not what I would expect since (layers are "inside" the map); I missed that before because I was querying more than one map and I considered the other (folded) row as one of the other maps
    • this needs separate ticket
    • underlying vector_what(map="...", coord=...) and v.what works but maybe the output is hard to work with (applies especially to vector_what function)

comment:6 in reply to:  5 ; Changed 4 years ago by mlennert

Replying to wenzeslaus:

Unresolved:

  • v.category has a parameter/option option while v.edit has a parameter tool

The two modules do different things and I don't really see it as a problem that the parameters have different names.

  • v.category builds topology when there was no change

v.category only does this when there is an output map and for any new map topology has to be built, so again, I don't see this as a problem.

  • v.category does nothing for option=step; using option=sum under the same conditions gives a result if there is something else to add, it is not in the example in manual

There is no option=step. step is a separate parameter which allows to change the default step of 1 when v.category creates new cat values.

  • v.category says 0 features modified. when it finished report or print but it seems redundant I wouldn't expect something else when using report or print and not providing output

I cannot reproduce this.

  • in GUI query tool, you will see that it shows only one layer and one category
    • now I see that layers are there but they are represented as separate maps which is not what I would expect since (layers are "inside" the map); I missed that before because I was querying more than one map and I considered the other (folded) row as one of the other maps
    • this needs separate ticket

IMHO this behavior is debatable, but definitely not a bug.

I again suggest closing this bug, as there is no actual bug report in here.

comment:7 in reply to:  6 Changed 4 years ago by wenzeslaus

Resolution: fixed
Status: newclosed

Replying to mlennert:

I again suggest closing this bug, as there is no actual bug report in here.

OK, significant amount of reported things was either fixed or resolved somehow. But some of the unresolved issues would be good to keep in mind, for example module option called option, and I guess I may hit the remaining ones once I will work with vector categories again if they are still there. I've tried to run some of the commands from the original report and the problems with v.edit are still fixed (comment:5), so that's fine.

comment:8 Changed 4 years ago by neteler

Milestone: 7.1.07.2.0

Milestone renamed

Note: See TracTickets for help on using tickets.