public class ZonalStats extends Object
The result for each combination of data image band, zone image integer zone (if
provided) and requested statistic is stored as a Result object.
The most basic usage is to iterate through the results as follows...
RenderedOp op = JAI.create("zonalstats", myParamBlock);
ZonalStats allStats = (ZonalStats) op.getProperty(ZonalStatsDescriptor.ZONAL_STATS_PROPERTY);
for (Result r : allStats.results()) {
System.out.prinln(r);
}
Alternatively, the attributes of Result objects can be retrieved selectively...
ZonalStats allStats = ...
for (Result r : allStats.results()) {
if (r.getStatistic() == Statistic.MEAN) {
System.out.printf("%4d %4d %8.4f\n",
r.getImageBand(), r.getZone(), r.getValue());
}
}
For most uses it may be easier to use the chaining methods provided by ZonalStats
to select the subset of results required...
ZonalStats allStats = ...
// Get results for a given band
int bandIndex = ...
List bandResults = allStats.band(bandIndex).results();
// Get Statistic.MEAN values for the specified band and zone
List subsetResults = allStats.band(b).zone(z).statistic(Statistic.MEAN).results();
// Impress your friends with pretty printing !
Statistic[] statistics = {
Statistic.MIN,
Statistic.MAX,
Statistic.MEDIAN,
Statistic.APPROX_MEDIAN,
Statistic.SDEV
};
System.out.println(" exact approx");
System.out.println(" band zone min max median median sdev");
System.out.println("-----------------------------------------------------------");
for (int b : allStats.getImageBands()) {
for (int z : zs.getZones()) {
System.out.printf(" %4d %4d", b, z);
ZonalStats subset = zs.band(b).zone(z);
for (Statistic s : statistics) {
System.out.printf(" %8.4f", zoneSubset.statistic(s).results().get(0).getValue());
}
System.out.println();
}
}
Result,
ZonalStatsDescriptor| Modifier and Type | Method and Description |
|---|---|
ZonalStats |
band(int b)
Get the subset of results for the given band.
|
SortedSet<Integer> |
getZones()
Get the integer IDs read from the zone image.
|
ZonalStats |
ranges(List<Range> ranges)
Get the subset of results for the given
Ranges. |
List<Result> |
results()
Returns the list of
Result objects. |
ZonalStats |
statistic(Statistic s)
Get the subset of results for the given
Statistic. |
ZonalStats |
zone(int z)
Get the subset of results for the given zone.
|
public SortedSet<Integer> getZones()
Note that statistics will not necessarily have been calculated for all zones.
public ZonalStats band(int b)
b - band indexZonalStats object containing results for the band
(data are shared with the source object rather than copied)public ZonalStats zone(int z)
z - zone IDZonalStats object containing results for the zone
(data are shared with the source object rather than copied)public ZonalStats statistic(Statistic s)
Statistic.
See the example of chaining this method in the class docs.s - the statisticZonalStats object containing results for the statistic
(data are shared with the source object rather than copied)public ZonalStats ranges(List<Range> ranges)
Ranges.ranges - the RangesZonalStats object containing results for the ranges
(data are shared with the source object rather than copied)Copyright © 2009–2018. All rights reserved.