[GRASS-dev] [GRASS GIS] #3357: v.rast.stats: add support for -d flag (densified lines)

GRASS GIS trac at osgeo.org
Mon Jul 24 02:22:05 PDT 2017


#3357: v.rast.stats: add support for -d flag (densified lines)
--------------------------+-------------------------------------
  Reporter:  veroandreo   |      Owner:  grass-dev@…
      Type:  enhancement  |     Status:  new
  Priority:  normal       |  Milestone:  7.2.2
 Component:  Vector       |    Version:  svn-trunk
Resolution:               |   Keywords:  v.rast.stats, v.to.rast
       CPU:  Unspecified  |   Platform:  Unspecified
--------------------------+-------------------------------------

Comment (by veroandreo):

 Removing previous patch and applying the second one, I get the following:

 {{{
 v.rast.stats myrailroads raster=elevation column_prefix=elev
 method=average -d
 Preprocessing input data...
 Traceback (most recent call last):
   File "/home/veroandreo/software/grass7_trunk/dist.x86_64-pc-linux-
 gnu/scripts/v.rast.stats", line 312, in <module>
     main()
   File "/home/veroandreo/software/grass7_trunk/dist.x86_64-pc-linux-
 gnu/scripts/v.rast.stats", line 139, in main
     from pygrass.vector import VectorTopo
 ImportError: No module named pygrass.vector
 WARNING: No data base element files found
 }}}

 Here the output of svn diff

 {{{
 [veroandreo at utwks62764 v.rast.stats]$ svn diff
 Index: v.rast.stats.py
 ===================================================================
 --- v.rast.stats.py     (revision 71311)
 +++ v.rast.stats.py     (working copy)
 @@ -31,6 +31,11 @@
  #% key: c
  #% description: Continue if upload column(s) already exist
  #%end
 +#%flag
 +#% key: d
 +#% label: Create densified lines (default: thin lines)
 +#% description: All cells touched by the line will be set, not only those
 on the render path
 +#%end
  #%option G_OPT_V_MAP
  #%end
  #%option G_OPT_V_FIELD
 @@ -131,8 +136,17 @@

      grass.message(_("Preprocessing input data..."))
      try:
 -        grass.run_command('v.to.rast', input=vector, layer=layer,
 output=rastertmp,
 -                          use='cat', quiet=True)
 +        from pygrass.vector import VectorTopo
 +        inmap = VectorTopo(vector)
 +        inmap.open('r')
 +        nlines = inmap.num_primitive_of('lines')
 +        # Create densified lines rather than thin lines
 +        if flags['d'] and nlines > 0:
 +            grass.run_command('v.to.rast', input=vector, layer=layer,
 output=rastertmp,
 +                              use='cat', flags='d', quiet=True)
 +        else:
 +            grass.run_command('v.to.rast', input=vector, layer=layer,
 output=rastertmp,
 +                              use='cat', quiet=True)
      except CalledModuleError:
          grass.fatal(_("An error occurred while converting vector to
 raster"))
 }}}

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3357#comment:5>
GRASS GIS <https://grass.osgeo.org>



More information about the grass-dev mailing list