[GRASSLIST:138] How to report length totals for all lines matching specific ID

I have a vector of a coastline; the coast is segmented into different
coastal types, according to unique IDs:

CAT Class_ID CLASS SEG_LENGTH
1 5 Rock Cliff 56.789000
2 7 Barrier Beach 13.450000
....

I successfully popluated the SEG_LENGTH column with the length of each
segment using v.to.db:

v.to.db Coastal_Classes option=length type=line units=m

Now I want to report total lengths of each CLASS (i.e., total length of all
"Rock Cliff" segments, etc.)

Any ideas?

~ Eric.

On 3/15/06, David Finlayson <david.p.finlayson@gmail.com> wrote:

If you are using a database for your attributes can't you just run an
SQL query? Something along the lines of:

select first(CLASS) sum(SEG_LENGTH) from <table_name> group by CLASS;

On 3/15/06, Patton, Eric <epatton@nrcan.gc.ca> wrote:
> I have a vector of a coastline; the coast is segmented into different
> coastal types, according to unique IDs:
>
> CAT Class_ID CLASS SEG_LENGTH
> 1 5 Rock Cliff 56.789000
> 2 7 Barrier Beach 13.450000
> ....
>
>
> I successfully popluated the SEG_LENGTH column with the length of each
> segment using v.to.db:
>
> v.to.db Coastal_Classes option=length type=line units=m
>
> Now I want to report total lengths of each CLASS (i.e., total length of all
> "Rock Cliff" segments, etc.)
>
> Any ideas?
>
> ~ Eric.
>
>

--
David Finlayson

--
David Finlayson

In GRASS that would be something like this (note the comma I forgot in
last post):

echo "select first(CLASS), sum(SEG_LENGTH) from <table_name> group by
CLASS" | db.select

You pipe the query to your database through db.select. Alternatively,
if you are using a database like sqlite you can do the query right in
the database.

On 3/15/06, David Finlayson <david.p.finlayson@gmail.com> wrote:

On 3/15/06, David Finlayson <david.p.finlayson@gmail.com> wrote:
> If you are using a database for your attributes can't you just run an
> SQL query? Something along the lines of:
>
> select first(CLASS) sum(SEG_LENGTH) from <table_name> group by CLASS;
>
>
>
> On 3/15/06, Patton, Eric <epatton@nrcan.gc.ca> wrote:
> > I have a vector of a coastline; the coast is segmented into different
> > coastal types, according to unique IDs:
> >
> > CAT Class_ID CLASS SEG_LENGTH
> > 1 5 Rock Cliff 56.789000
> > 2 7 Barrier Beach 13.450000
> > ....
> >
> >
> > I successfully popluated the SEG_LENGTH column with the length of each
> > segment using v.to.db:
> >
> > v.to.db Coastal_Classes option=length type=line units=m
> >
> > Now I want to report total lengths of each CLASS (i.e., total length of all
> > "Rock Cliff" segments, etc.)
> >
> > Any ideas?
> >
> > ~ Eric.
> >
> >
>
>
> --
> David Finlayson
>

--
David Finlayson

--
David Finlayson

I have a vector of a coastline; the coast is segmented into different
coastal types, according to unique IDs:

CAT Class_ID CLASS SEG_LENGTH
1 5 Rock Cliff 56.789000
2 7 Barrier Beach 13.450000
....

I successfully popluated the SEG_LENGTH column with the length of each
segment using v.to.db:

v.to.db Coastal_Classes option=length type=line units=m

Now I want to report total lengths of each CLASS (i.e., total length
of all "Rock Cliff" segments, etc.)

Any ideas?

maybe not the most efficient way, but:

v.extract out=rock_cliff where="CLASS = 'Rock Cliff'"
v.out.ascii.db rock_cliff column=SEG_LENGTH #from the wiki add-ons page

then add up in spreadsheet, matlab/octave, awk loop, etc.
Don't know of a UNIX command to do sums, but I'm sure there is one?
bc?

Note coastline length is a fractal problem and answers are only useful
when compared against the same dataset, e.g. as a percentage of the
whole. Even then trusting it is a bit dubious (same digitizer at the
same level of fatigue, etc).

see-
http://mathworld.wolfram.com/CoastlineParadox.html
http://www.vanderbilt.edu/AnS/psychology/cogsci/chaos/workshop/Fractals.html
http://en.wikipedia.org/wiki/How_Long_Is_the_Coast_of_Britain%3F_Statistical_Self-Similarity_and_Fractional_Dimension

Hamish

Another way is by using v.report (or Rdbi.PgSQL package) and R.

v.report map=Coastal_Classes option=length > coastal.classes
R # start R
cc <- read.table("coastal.classes",sep="|")
?tapply
tapply(cc$SEG_LENGTH,cc$CLASS,sum) # voila

You may also import the PostgreSQL table directly into R via the Rdbi.PgSQL
package. See http://grass.itc.it/statsgrass/r_and_dbms.html written by Markus
Neteler.

Miha

--- Hamish <hamish_nospam@yahoo.com> wrote:

> I have a vector of a coastline; the coast is segmented into different
> coastal types, according to unique IDs:
>
> CAT Class_ID CLASS SEG_LENGTH
> 1 5 Rock Cliff 56.789000
> 2 7 Barrier Beach 13.450000
> ....
>
>
> I successfully popluated the SEG_LENGTH column with the length of each
> segment using v.to.db:
>
> v.to.db Coastal_Classes option=length type=line units=m
>
> Now I want to report total lengths of each CLASS (i.e., total length
> of all "Rock Cliff" segments, etc.)
>
> Any ideas?

maybe not the most efficient way, but:

v.extract out=rock_cliff where="CLASS = 'Rock Cliff'"
v.out.ascii.db rock_cliff column=SEG_LENGTH #from the wiki add-ons page

then add up in spreadsheet, matlab/octave, awk loop, etc.
Don't know of a UNIX command to do sums, but I'm sure there is one?
bc?

Note coastline length is a fractal problem and answers are only useful
when compared against the same dataset, e.g. as a percentage of the
whole. Even then trusting it is a bit dubious (same digitizer at the
same level of fatigue, etc).

see-
http://mathworld.wolfram.com/CoastlineParadox.html
http://www.vanderbilt.edu/AnS/psychology/cogsci/chaos/workshop/Fractals.html

http://en.wikipedia.org/wiki/How_Long_Is_the_Coast_of_Britain%3F_Statistical_Self-Similarity_and_Fractional_Dimension

Hamish

___________________________________________________________
To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com