On 10/30/2012 03:31 AM, Phil Donovan wrote:
How does one dissolve and sum a field in GRASS? I guess one way would be to create a separate table of summed values and then join them back to the new dissolved layer? How would you create this table of summed values?


This problem can be split (no pun intended) into two parts. First, to group the values in one column and sum the values in another column could be done in a database. If your vector is in sqlite, then:
# lets assume: a vector named 'v',
# the dissolve column is called 'id' and the column to be summed is called 'val'
sqlite> CREATE TABLE v_sum AS SELECT id, SUM(val) AS sum_by_id FROM v GROUP BY id;

Now you have an additional sqlite table with the aggregated values of the sum column for each dissolve value. At this point you can actually just connect your vector to this table thru a second layer and you'll see the summed values for each id:

v.db.connect map=v driver=sqlite \
    database=$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite.db \
    table=v_sum layer=2
v.db.select v layer=2
# should show the summed values for each dissolve value

But we have not yet done any dissolve. The v.dissolve module will dissolve only polygons, and only those that share a common boundary. If that's the case you can run v.dissolve, then attach the result to the table created above:
v.dissolve in=v out=v_diss column=id
# check resulting cats:
v.category v_diss option=report
# Connect to the summed table
v.db.connect v_diss driver=sqlite database=$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite.db table=v_sum key=id

I think that should do it.

--
Micha
 
______________________________________
Example table:

Dissolve Column    |      Sum column
1                          |       0.5
1                          |       0.5
1                          |       0.5
2                          |       0.25
2                          |       0.25

into:

Diss C | Sum C
1         | 1.5
2         | 0.5

________________________________________

Cheers Phil.

This mail was received via Mail-SeCure System.


_______________________________________________
grass-user mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/grass-user

This mail was received via Mail-SeCure System.




-- 
Micha Silver
GIS Consultant, Arava Development Co.
http://www.surfaces.co.il
_______________________________________________
grass-user mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/grass-user

Reply via email to