Crosstab Stores

When things get a little bit complicated in your report generation, you may need to use a CrosstabStore. For example, what if you need to report on average harvest age? The actual average harvest age is not present in the block table, however, it does contain treatment age and area harvested for each polygon. As long as the values you are looking for can be calculated from values in another Patchworks table, then the CrosstabStore can be used. This class creates a pivot table-like summary of data from a parent store (usually the block table). One common example is to create a report of average values. In order to get the average harvest age we need to sum the harvest age of each polygon, and then divide by the total area harvested. The actual syntax to create a CrosstabStore called "avgharvestage", looks like this:

CrosstabStore avgharvestage = new CrosstabStore(blockData,                   1
                                                "CURRENTTREATMENT ne ''",    2
                                                 Horizon.periodList);        3
     avgharvestage.addValue("AgeArea", "TREATMENTAGE*MANAGEDAREA");          4
     avgharvestage.addValue("Area", "MANAGEDAREA");                          5


"blockData" - the AttributeStore parent; the CrosstabStore will be calculated from the block table.


"CURRENTTREATMENT ne ''" - the reselect expression used. Only treated stands will be included from the block table. If "true", then all records would be selected.


Horizon.periodList - the periods to be included, in this case the entire planning horizon.


The first column added to the CrosstabStore will be "AgeArea", calculated as TREATMENTAGE multiplied by MANAGEDAREA .


The second column added to theCrosstabStore will be "Area ", which is the MANAGEDAREA column in the block table.

These two columns can now be used in any other Patchworks report. If you want to have a look at this crosstab table, you can display the table by typing: "avgharvestage.getSnapshot(false).showCube(true);" in the Patchworks console. The table will appear in a table viewer, you can use the scroll bar to view the different periods. Use a TableQuery report to output the full table (see the section called “Table Query Report”).