[GRASS-dev] [GRASS GIS] #3357: v.rast.stats: add support for -d flag (densified lines)
GRASS GIS
trac at osgeo.org
Mon Jul 24 06:42:45 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 mmetz):
Replying to [comment:6 lucadelu]:
> Not able to replace the previous diff... here your are the working one
>
>
> {{{
> Index: scripts/v.rast.stats/v.rast.stats.py
> ===================================================================
> --- scripts/v.rast.stats/v.rast.stats.py (revision 71311)
> +++ scripts/v.rast.stats/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 grass.pygrass.vector import VectorTopo
> + inmap = VectorTopo(vector)
> + inmap.open('r')
> + nlines = inmap.num_primitive_of('line')
> }}}
don't forget to close inmap.
simpler alternative
{{{
nlines = grass.vector_info_topo(vector)['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"))
>
> }}}
>
> Now working on testsuite and later, if it works, I will commit the
changes
--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3357#comment:7>
GRASS GIS <https://grass.osgeo.org>
More information about the grass-dev
mailing list