org.jaitools.media.jai.zonalstats
Class ZonalStats

java.lang.Object
  extended by org.jaitools.media.jai.zonalstats.ZonalStats

public class ZonalStats
extends Object

Holds the results of the ZonalStats operator. An instance of this class is stored as a property of the destination image.

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();
     }
 }

 

Since:
1.0
Version:
$Id$
Author:
Michael Bedward, Daniele Romagnoli, GeoSolutions S.A.S.
See Also:
Result, ZonalStatsDescriptor

Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getZones

public SortedSet<Integer> getZones()
Get the integer IDs read from the zone image. If a zone image was not used all results are treated as being in zone 0.

Note that statistics will not necessarily have been calculated for all zones.

Returns:
the sorted zone IDs

band

public ZonalStats band(int b)
Get the subset of results for the given band. See the example of chaining this method in the class docs.

Parameters:
b - band index
Returns:
a new ZonalStats object containing results for the band (data are shared with the source object rather than copied)

zone

public ZonalStats zone(int z)
Get the subset of results for the given zone. See the example of chaining this method in the class docs.

Parameters:
z - zone ID
Returns:
a new ZonalStats object containing results for the zone (data are shared with the source object rather than copied)

statistic

public ZonalStats statistic(Statistic s)
Get the subset of results for the given Statistic. See the example of chaining this method in the class docs.

Parameters:
s - the statistic
Returns:
a new ZonalStats object containing results for the statistic (data are shared with the source object rather than copied)

ranges

public ZonalStats ranges(List<Range> ranges)
Get the subset of results for the given Ranges.

Parameters:
ranges - the Ranges
Returns:
a new ZonalStats object containing results for the ranges (data are shared with the source object rather than copied)

results

public List<Result> results()
Returns the list of Result objects.

Returns:
the results
See Also:
Result


Copyright © 2009-2013. All Rights Reserved.