[GRASS5] Re: [bug #3277] (grass) d.vect.thematic fails with DOUBLE

Maciek Sieczka werchowyna at epf.pl
Tue May 31 17:29:15 EDT 2005


From: "Daniel Calvelo Aros" <dcalvelo at minag.gob.pe>

> From: Maciek Sieczka <werchowyna at epf.pl>
> Sent: Tue, 31 May 2005 10:19:49 +0000 (UTC)
>
>> Hamish <hamish_nospam <at> yahoo.com> writes:
>> >
>> > # check column type
>> > COLTYPE="`v.info -c $GIS_OPT_map [...] | grep $GIS_OPT_column | [...]
>> >
>> > If you have a column PROD and another column with "PROD" in it, e.g.
>> > PROD2, the grep step will pick out both.
>> >
>> > Try using the regex start of line and end of line markers to refine the
>> > search:
>> >
>> > ... | grep ^"$GIS_OPT_column"$ | ...
>>
>> Your proposition didn't do it but after one hour of tough reading
>>
>> ^'[$GIS_OPT_column]'
>>
>> did. Though I still don't know how.
>
> It shouldn't have. That regexp should match a line containing any of the
> characters 'G','I',... or the end of line. Could you put a debugging line
> after COLTYPE=... like
>
> v.info -c $GIS_OPT_map [...] | grep $GIS_OPT_column | awk '{print
> "["$0"]"}'
>
> and post back the result of that?
>
> Daniel

Gentlemen

My first "solution" really shouldn't work like you said Daniel and worked
only in this particular case.

I think I understood the problem (for real this time) and resolved it.

I have two DOUBLE PRECISSION columns, one is called PROD, the other POPROD.

Hamish's solution ... | grep ^"$GIS_OPT_column"$ | ... couldn't handle that
due to "|" between the column type and column name printed by "v.info -c",
e.g. DOUBLE PRECISION|PROD.

In this situation we need either

... | grep "|"$GIS_OPT_column$ | ...

or

... | grep -w $GIS_OPT_column | ...

Both work. Which one is better? "grep -w" seems cleaner.

One thing more: there should be another error check for "no such column"
prior to "# check column type". Let me suggest:

---
# check if the column exists
COLCHECK="`v.info -c $GIS_OPT_map layer=1 2> /dev/null | grep -w
$GIS_OPT_column

if [ "$COLCHECK" = "$GIS_OPT_column" ]; then
    echo ""
else
    echo "ERROR: No such column \""$GIS_OPT_column"\""
    exit 1
fi
---

What do you think?

Cheers,
Maciek

P.S.
This lesson I enjoyed.




More information about the grass-dev mailing list