[GRASS-user] aggregate a field across features and then display
related charts and histograms
Moritz Lennert
mlennert at club.worldonline.be
Tue Jan 29 18:04:58 EST 2008
On 27/01/08 18:35, David Epstein wrote:
> Hello,
>
>
> I have looked over a lot of documentation but am still having trouble
> with this task. I hope somebody on the list can point me in the right
> direction!
>
> I have a table of land parcels as polygon features in a postGIS
> database. I have another table of regions in the same postGIS database.
> There are between 20 and 50 parcels to a region. I can access the data
> without a problem (thanks to some helpful people!)
>
> I want to create several maps that aggregate/summarize the parcel data
> and display them as pie-charts and histograms at the centroid of each
> region. For example:
This is most easily solved within PostgreSQL, supposing that in your
parcel table you have a column which gives the region each parcel
belongs to. As Michael already mentioned the actually mapping can be
done with d.vect.chart. However this means that you need a table
structure such as RegionID, Variable1, Variable2, Variable3, where
RegionID is the category value linking to your vector map polygons and
Variable* are your size / owner classes.
>
> 1. HISTOGRAM of the size of all parcels in the region. The data for this
> is stored in a single field for each parcel. I just need to understand
> how to identify the field, send it to the histogram, and display it at
> the centroid of the region layer.
>
> 2. PIE-CHART where each slice represents the total area owned by a
> particular class of owner. This is more complicated. EACH parcel has an
> area column for each of 7 classes of owners. So, I believe I need to
> keep separate tallies and send them all to a pie-chart function--but I
> am not sure how...
- add a two new columns to your ParcelTable: Size_Class and Owner_Class
(directly in PostgreSQL or with v.db.addcol)
- populate these columns (directly in PostgreSQL or with v.db.addcol,
using the where clause, e.g. 'column=Size_Class value=2 where="size>200
and size<500"
- create a view with something like this (untested)
SELECT
RegionID,
,count(CASE Size_Class
WHEN '1' THEN 1
END) AS SizeClass1
,count(CASE Size_Class
WHEN '2' THEN 1
END) AS SizeClass2
, etc...
FROM
ParcelTable, RegionTable
WHERE ParcelTable.RegionID=RegionTable.RegionID
GROUP BY
RegionID
- Link your map to this view with v.db.connect -o
- Use d.vect.chart to create pie / bar charts.
> Finally, is the best way to actually KEEP all this data to add new
> columns to the region table with SQL?
You can also create a view.
Moritz
More information about the grass-user
mailing list