[GRASSLIST:8965] sqlite and v.rast.stats problem

I am trying to calculate statistics for a raster DEM (PSDEM2005) using
the features in a vector coverage (blocksall). The vector contains a
series of blocks, each with a unique cat. I have stored the attribute
table in an sqlite3 database and according to v.db.connect it is
linked (I can also query and display attributes in this table using
d.vect):

GRASS 6.1.cvs (WASPN_NAD83):~ > v.db.connect -p blocksall
Vector map <blocksall> is connected by:
layer <1> table <blocksall> in database
</data/grass/WASPN_NAD83/hood/sqlite.db> through driver <sqlite> with
key <cat>

However, when I run v.rast.stats. I get an error asking me to run v.db.addtable:

GRASS 6.1.cvs (WASPN_NAD83):~ > v.rast.stats -c vector=blocksall
raster=psdem2005 colprefix=elev30ft
List of categories found: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
42 43 44 45 46 47 48 ... <clipped> ...
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647
648 649
ERROR: Cannot continue (use v.db.addtable first).

I expected that v.rast.stats would have calculated statistics and
created columns in the sqlite database. This has worked using dbf
tables for me in the past. I am forgetting something here?

Thanks,

David
--
David Finlayson
Marine Geology & Geophysics
School of Oceanography
Box 357940
University of Washington
Seattle, WA 98195-7940
USA

Office: Marine Sciences Building, Room 112
Phone: (206) 616-9407
Web: http://students.washington.edu/dfinlays

David,

sorry, a test was not written correctly. I have fixed that.
Now it works also for DB drivers other than dbf.

Please fetch from 6.1-CVS:

http://freegis.org/cgi-bin/viewcvs.cgi/grass6/scripts/v.rast.stats/

or from next weekend's snapshot. The minimum change is

- echo "ERROR: Cannot continue (use v.db.addtable first)."
- exit 1
+ # in case a table is missing, we'll trap a crash later...
+ DBFDRIVER=0

Thanks for notifying,

Markus

On Wed, Nov 09, 2005 at 04:33:23PM -0800, David Finlayson wrote:

I am trying to calculate statistics for a raster DEM (PSDEM2005) using
the features in a vector coverage (blocksall). The vector contains a
series of blocks, each with a unique cat. I have stored the attribute
table in an sqlite3 database and according to v.db.connect it is
linked (I can also query and display attributes in this table using
d.vect):

GRASS 6.1.cvs (WASPN_NAD83):~ > v.db.connect -p blocksall
Vector map <blocksall> is connected by:
layer <1> table <blocksall> in database
</data/grass/WASPN_NAD83/hood/sqlite.db> through driver <sqlite> with
key <cat>

However, when I run v.rast.stats. I get an error asking me to run v.db.addtable:

GRASS 6.1.cvs (WASPN_NAD83):~ > v.rast.stats -c vector=blocksall
raster=psdem2005 colprefix=elev30ft
List of categories found: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
42 43 44 45 46 47 48 ... <clipped> ...
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647
648 649
ERROR: Cannot continue (use v.db.addtable first).

I expected that v.rast.stats would have calculated statistics and
created columns in the sqlite database. This has worked using dbf
tables for me in the past. I am forgetting something here?

Thanks,

David
--
David Finlayson
Marine Geology & Geophysics
School of Oceanography
Box 357940
University of Washington
Seattle, WA 98195-7940
USA

Office: Marine Sciences Building, Room 112
Phone: (206) 616-9407
Web: http://students.washington.edu/dfinlays

--
Markus Neteler <neteler itc it> http://mpa.itc.it
ITC-irst - Centro per la Ricerca Scientifica e Tecnologica
MPBA - Predictive Models for Biol. & Environ. Data Analysis
Via Sommarive, 18 - 38050 Povo (Trento), Italy

It didn't work...but it did!

The script tries to add the missing column, gets an error and fails in
the third check (ERROR: Cannot continue). However, the error is not
true. It DID successfully add the column to the database. I commented
out the final exit 1 line and the script completed without problems.
Maybe sqlite3 is not working properly with v.info or v.db.addcol and
returning an error code when it should not?

The problem is somewhere in here (from v.rast.stats):

v.info -c $VECTOR 2> /dev/null | sed 's+^+|+g' |sed 's+$+|+g' | grep
"|$CURRCOLUMN|" > /dev/null
if [ $? -eq 0 ] ; then
   echo "$column $CURRCOLUMN already present, updating statistic
values in table"
   if [ $GIS_FLAG_c -ne 1 ] ; then
      echo "ERROR: Cannot continue (or use -c flag)."
      exit 1
   fi
else
   v.db.addcol map=$VECTOR columns="$CURRCOLUMN double"
   if [ $? -eq 0 ] ; then
     echo "ERROR: Cannot continue."
     exit 1
   fi
fi
done

The second problem is that this is horribly inefficient for my
statistics problem. I have a huge DEM with lots of small blocks that I
am generating statistics for. It takes several minutes for each
calculation because the whole map is used for each call to r.univar.
Is it possible to clip the null areas from the map region to speed up
the calculation from r.univar?

David

On 11/10/05, Markus Neteler <neteler@itc.it> wrote:

David,

sorry, a test was not written correctly. I have fixed that.
Now it works also for DB drivers other than dbf.

Please fetch from 6.1-CVS:

http://freegis.org/cgi-bin/viewcvs.cgi/grass6/scripts/v.rast.stats/

or from next weekend's snapshot. The minimum change is

- echo "ERROR: Cannot continue (use v.db.addtable first)."
- exit 1
+ # in case a table is missing, we'll trap a crash later...
+ DBFDRIVER=0

Thanks for notifying,

Markus

On Wed, Nov 09, 2005 at 04:33:23PM -0800, David Finlayson wrote:
> I am trying to calculate statistics for a raster DEM (PSDEM2005) using
> the features in a vector coverage (blocksall). The vector contains a
> series of blocks, each with a unique cat. I have stored the attribute
> table in an sqlite3 database and according to v.db.connect it is
> linked (I can also query and display attributes in this table using
> d.vect):
>
> GRASS 6.1.cvs (WASPN_NAD83):~ > v.db.connect -p blocksall
> Vector map <blocksall> is connected by:
> layer <1> table <blocksall> in database
> </data/grass/WASPN_NAD83/hood/sqlite.db> through driver <sqlite> with
> key <cat>
>
> However, when I run v.rast.stats. I get an error asking me to run v.db.addtable:
>
> GRASS 6.1.cvs (WASPN_NAD83):~ > v.rast.stats -c vector=blocksall
> raster=psdem2005 colprefix=elev30ft
> List of categories found: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
> 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
> 42 43 44 45 46 47 48 ... <clipped> ...
> 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
> 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647
> 648 649
> ERROR: Cannot continue (use v.db.addtable first).
>
> I expected that v.rast.stats would have calculated statistics and
> created columns in the sqlite database. This has worked using dbf
> tables for me in the past. I am forgetting something here?
>
> Thanks,
>
> David
> --
> David Finlayson
> Marine Geology & Geophysics
> School of Oceanography
> Box 357940
> University of Washington
> Seattle, WA 98195-7940
> USA
>
> Office: Marine Sciences Building, Room 112
> Phone: (206) 616-9407
> Web: http://students.washington.edu/dfinlays
>

--
Markus Neteler <neteler itc it> http://mpa.itc.it
ITC-irst - Centro per la Ricerca Scientifica e Tecnologica
MPBA - Predictive Models for Biol. & Environ. Data Analysis
Via Sommarive, 18 - 38050 Povo (Trento), Italy

--
David Finlayson
Marine Geology & Geophysics
School of Oceanography
Box 357940
University of Washington
Seattle, WA 98195-7940
USA

Office: Marine Sciences Building, Room 112
Phone: (206) 616-9407
Web: http://students.washington.edu/dfinlays

The second problem is that this is horribly inefficient for my
statistics problem. I have a huge DEM with lots of small blocks that I
am generating statistics for. It takes several minutes for each
calculation because the whole map is used for each call to r.univar.
Is it possible to clip the null areas from the map region to speed up
the calculation from r.univar?

Yes, save the region with g.region, extract the small block to a new map
with r.mapcalc, 'g.region zoom=' to the extent of the new data in
r.mapcalc, run r.univar, then restore the old region. Maybe about the
same processing time?

maybe [reclass and] use r.stats instead on the full map?

Hamish