[GRASS-dev] displaying (slightly) broken raster maps in gis.m

Glynn Clements glynn at gclements.plus.com
Sat Jul 8 03:49:46 EDT 2006


Michael Barton wrote:

> > We noticed gis.m will not display a raster map if the cats/ file is
> > missing but d.rast will.
> > 
> > is this something to fix, or nothing to worry about?
> > 
> > (mapset was broken after bulk copy via FAT32 external hard drive problems)
> 
> Gis.m is just a wrapper for d.rast. So I'm not sure why one should display a
> map and the other one won't.

gis.m/raster.tcl seems to do a bit more than just run d.rast.

BTW, looking at that code, I note that the failure to treat commands
as lists appears to be a common problem within gis.m, e.g.:

    set cmd "d.rast map=$opt($id,1,map)"

    # overlay
    if { $opt($id,1,overlay) } { 
        append cmd " -o"
    }

[snip]

    # raster query
    if { $opt($id,1,rastquery) != "" } { 
        append cmd " {$querytype=$opt($id,1,rastquery)}"
    }
    
    # background color
    if { $opt($id,1,bkcolor) != "" } { 
        append cmd " bg=$opt($id,1,bkcolor)"
    }

Although this particular case should work (certainly, none of the
arguments can contain spaces, and I don't think that they can contain
braces), in general you should be using list operations, e.g.:

    set cmd [list d.rast map=$opt($id,1,map)]

    # overlay
    if { $opt($id,1,overlay) } { 
        lappend cmd -o
    }

[snip]

    # raster query
    if { $opt($id,1,rastquery) != "" } { 
        lappend cmd $querytype=$opt($id,1,rastquery)
    }
    
    # background color
    if { $opt($id,1,bkcolor) != "" } { 
        lappend cmd bg=$opt($id,1,bkcolor)
    }

Etc.

Whilst it is technically sufficient to use list operations only where
necessary, that requires you to actually consider whether or not they
are necessary. As most of the time they aren't necessary, overlooking
the few cases where they /are/ necessary (e.g. filenames, SQL "WHERE"
clauses etc) becomes almost inevitable.

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




More information about the grass-dev mailing list