[GRASS-dev] [GRASS GIS] #2304: Problems with add category to all features workflow

GRASS GIS trac at osgeo.org
Wed May 21 10:26:21 PDT 2014


#2304: Problems with add category to all features workflow
--------------------------------+-------------------------------------------
 Reporter:  wenzeslaus          |       Owner:  grass-dev@…              
     Type:  defect              |      Status:  new                      
 Priority:  normal              |   Milestone:  7.1.0                    
Component:  Default             |     Version:  unspecified              
 Keywords:  v.edit, v.category  |    Platform:  Unspecified              
      Cpu:  Unspecified         |  
--------------------------------+-------------------------------------------
 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 at jr_sts_contours>
 WARNING: No features selected, nothing to edit
 Building topology for vector map <test3 at 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 at jr_contours>
 WARNING: No features selected, nothing to edit
 Building topology for vector map <contours_level_120 at 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 at jr_contours>
 }}}

 Building topology helps:
 {{{
 v.build map=test
 }}}
 {{{
 Building topology for vector map <test at 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 at jr_contours>
 2 features modified
 Building topology for vector map <test at 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 at 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 at 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 at 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.''

-- 
Ticket URL: <http://trac.osgeo.org/grass/ticket/2304>
GRASS GIS <http://grass.osgeo.org>



More information about the grass-dev mailing list