[GRASS-dev] future after d.frame?

Glynn Clements glynn at gclements.plus.com
Wed Oct 8 09:05:06 EDT 2008


Yann Chemin wrote:

> attached is a composition that should be dumped as
> image file at each new temporal increment,
> in order to become an animation eventually.
> As d.frame is gone in GRASS 7,
> I'd like to know if anyone has an idea on how to make
> this happen within the new environmental conditions?

For d.rast.leg (scripts/d.rast.leg/d.rast.leg.py in 7.0), I used the
following function as a drop-in replacement for the d.frame command:

def make_frame(f, b, t, l, r):
    (ft, fb, fl, fr) = f

    t /= 100.0
    b /= 100.0
    l /= 100.0
    r /= 100.0

    rt = fb + t * (ft - fb)
    rb = fb + b * (ft - fb)
    rl = fl + l * (fr - fl)
    rr = fl + r * (fr - fl)
    s = '%f,%f,%f,%f' % (rt, rb, rl, rr)
    os.environ['GRASS_FRAME'] = s

This converts the coordinates used by d.frame (percentages, with the
origin at the lower left) to the coordinates used by the GRASS_FRAME
variable (display units, typically pixels (raster) or points
(PostScript etc), with the origin at the upper left).

The first argument, "f", is the parent frame, which was obtained with:

    s = grass.read_command('d.info', flags = 'f')
    f = tuple([float(x) for x in s.split()[1:5]])

This allows the output to nest inside an existing frame rather than
forcibly resetting to "full screen" (the notion of "resetting" doesn't
fit well with EPS or SVG).

Also, to compose multiple d.* commands into a single image when using
immediate rendering, you need to set GRASS_PNG_READ=TRUE. Otherwise,
each d.* command will erase the image (raster formats, e.g. PNG) or
truncate the file (vector formats, e.g. PS/PDF/SVG).

One feature which the display architecture currently lacks is the
ability to create multiple frames (in the sense of animation) from a
single command. Actually, you can almost do this with the PostScript
driver; call R_erase() between each frame, and manually change the
ERASE function in the output to use showpage instead of erasepage.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-dev mailing list