[GRASS5] v.in.ascii updates

Hamish hamish_nospam at yahoo.com
Sun Mar 20 01:26:06 EST 2005


> > I'm looking to do some v.in.ascii updates, I thought
> > I'd trawl for comments first.. most deal with format=point mode.
..
> > Debatable updates:
..
> 
> Also if can puts an indicative for the format to
> import the values "columns='variable double f8.2' "
> for when it be used with other instruction put excatly
> the format that was reading; p.e. "d.vect -c file
> display=attr attrcol=variable"


[problem: 'd.vect display=attr attrcol=double' displays .000000 after
every number cluttering the entire screen]


Sorry, can't do that as it is an output rather than an input filter.

The computer just knows how to store text strings and numbers of the
integer and floating point variety. There is some control how the
numbers are stored (eg single/double length, signed/unsigned) but you
don't get to choose how many decimal places are stored in the data file.

You could possibly import your formatted numbers as a text string. [I
don't know if it will let you force varchar type though (in the past it
did not).] But this is wasteful.


The place to do formatting is in the output module, i.e. d.vect.
See 'd.site.labels precision=' in GRASS 5.4 for an example of this in
action.

I had a look at adding this sort of option to GRASS 6's d.vect some time
ago; I ran into trouble as d.vect just gets a text string with
db_convert_column_value_to_string(column, &valstr);

So no chance to reformat in d.vect.


You could change lib/db/dbmi_base/valuefmt.c

db_convert_value_to_string()
[...]
        case DB_C_TYPE_DOUBLE:
            sprintf (buf, "%lf",db_get_value_double(value));

"%lf" to "%g", but I worry this will break other things?
Maybe it is ok, I don't know. Radim would have to answer that.

This works for the d.vect case and the results look good!



man sprintf [%g]:

g,G    
The  double  argument  is  converted  in style f or e (or F or E for G
conversions). The precision specifies the number of significant digits.
If the precision  is  missing,  6 digits  are given; if the precision is
zero, it is treated as 1. Style e is used if the exponent from its
conversion is less than -4 or greater than or equal to the precision.
Trailing zeros are removed from the fractional part of the result; a
decimal point appears only if it is followed by at least one digit.




Developers note:

db_convert_Cstring_to_value()

was missing return type. I've added type 'int', but there seem to be
many other db_() fn's missing type. Is this intended or just MIA?




Hamish




More information about the grass-dev mailing list