schmitzm.geotools.grid
Class GridUtil

java.lang.Object
  extended by schmitzm.geotools.grid.GridUtil

public class GridUtil
extends Object

Diese Klasse stellt statische Funktionen fuer die Arbeit mit Rasterdaten zur Verfuegung.

Version:
1.01
Author:
Martin Schmitz (University of Bonn/Germany)

Field Summary
static Color[] DEFAULT_COLORS
          11 Default colors used by #createDiscreteStyle(GridCoverage2D, double, Color...) if no colors are given.
static String DEFAULT_RASTER_STYLE_NAME
          The default name for style created by createDefaultStyle();
static String DEFAULT_RASTER_STYLE_TITLE
           
static GridCoverageFactory GRID_FAC
           
static String UNNAMED_RASTER_STYLE_NAME
           
static String UNTITLED_RASTER_STYLE_TITLE
           
 
Constructor Summary
GridUtil()
           
 
Method Summary
static double convertRasterToReal(int cell, int rasterMin, double realMin, double cellSize)
          Converts a raster cell index to "real" world coordinates.
static int convertRealToRaster(double coord, double realMin, double realLength, int rasterMin, int rasterLength)
          Converts a real world coordinate to the row/column number of a raster.
static int[] convertRealToRaster(Envelope2D env, RenderedImage image, double[] geoCoord)
          Converts a geo reference to raster coordinates.
static int[] convertRealToRaster(Envelope2D env, RenderedImage image, double geoX, double geoY)
          Converts a geo reference to raster coordinates.
static int[] convertRealToRaster(GridCoverage2D gc, double[] geoCoord)
          Converts a geo reference to raster coordinates.
static int[] convertRealToRaster(GridCoverage2D gc, double geoX, double geoY)
          Converts a geo reference to raster coordinates.
static GridCoverage2D convertToGridCoverage2D(Object obj)
          Konvertiert ein Raster-Objekt in eine GridCoverage2D.
static GridCoverage2D copyGridCoverage(GridCoverage2D source)
          Kopiert ein GridCoverage2D komplett.
static GridCoverage2D copyGridCoverage(GridCoverage2D source, int minX, int minY)
          Kopiert ein GridCoverage2D komplett, dessen Raster-Koordinaten (obere-linke Ecke) transformiert wird.
static Style createDefaultStyle()
          Erzeugt einen Standard-Style fuer ein GridCoverage2D und setzt den default-Namen: GridUtil.DEFAULT_RASTER_STYLE_NAME Und eine title : GridUtil.DEFAULT_RASTER_STYLE_TITLE
static Style createDiscreteStyle(GridCoverage2D grid, double opacity, Integer digits, Color... colorPalette)
          Creates a discrete style for a GridCoverage2D.
static GridCoverage2D createGridCoverage(GridCoverage2D source, Envelope bboxEnv)
          Erzeugt ein GridCoverage2D aus einem anderen.
static Style createInterpolativeStyle(GridCoverage2D grid, double opacity, Color... colors)
          Creates an interpolative style for a GridCoverage2D.
static Style createStyle(ColorMap colorMap, double opacity)
          Erzeugt einen Standard-Style fuer ein GridCoverage2D
static WritableRaster createWritableRaster(Raster r)
          Erzeugt ein WritableRaster aus einem Raster.
static WritableRaster createWritableRaster(Raster r, int minX, int minY)
          Erzeugt ein WritableRaster aus einem Raster.
static GridStatistic determineStatistic(GridCoverage2D gc, int band)
          Liefert statistische Daten ueber ein Grid, ohne ein Histogram zu berechnen.
static GridStatistic determineStatistic(GridCoverage2D gc, int band, int histogramSteps)
          Liefert statistische Daten ueber ein Grid und erstellt ein Histogramm.
static GridStatistic determineStatistic(GridCoverage2D gc, int band, int histogramSteps, Integer histogrammDigits)
          Liefert statistische Daten ueber ein Grid und erstellt ein Histogramm
static GridZoneStatistic<Float> determineZoneStatistic(GridCoverage2D valueGC, GridCoverage2D zoneGC)
          Liefert statistische Daten ueber ein Grid, das in Zonen unterteilt ist.
static GridZoneStatistic<Float> determineZoneStatistic(GridCoverage2D valueGC, int valueBand, GridCoverage2D zoneGC, int zoneBand)
          Liefert statistische Daten ueber ein Grid, das in Zonen unterteilt ist.
static GridCoverage2D getOverlappingCells(GridCoverage2D gc, Geometry g, Number markValue)
          Marks all raster cells, which are intersected by a Geometry.
static WritableRaster getOverlappingCells(GridCoverage2D gc, Geometry g, Number markValue, WritableRaster result)
          Marks all raster cells, which are intersected by a Geometry.
static Set<Point> getOverlappingCells(GridCoverage2D gc, LineString ls, Set<Point> result)
          Determines the raster cells, which are intersected by a LineString.
static GridCoverage2D resampleGridCoverage(GridCoverage2D gc, GridSampleDimension sampleDim)
          Erzeugt ein neues GridCoverage2D mit neuer SampleDimension.
static GridCoverage2D resampleGridCoverage(GridCoverage2D gc, GridSampleDimension[] sampleDim)
          Erzeugt ein neues GridCoverage2D mit neuer SampleDimension.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GRID_FAC

public static final GridCoverageFactory GRID_FAC

DEFAULT_RASTER_STYLE_NAME

public static final String DEFAULT_RASTER_STYLE_NAME
The default name for style created by createDefaultStyle();

See Also:
Constant Field Values

DEFAULT_RASTER_STYLE_TITLE

public static final String DEFAULT_RASTER_STYLE_TITLE
See Also:
Constant Field Values

UNNAMED_RASTER_STYLE_NAME

public static final String UNNAMED_RASTER_STYLE_NAME
See Also:
Constant Field Values

UNTITLED_RASTER_STYLE_TITLE

public static final String UNTITLED_RASTER_STYLE_TITLE
See Also:
Constant Field Values

DEFAULT_COLORS

public static final Color[] DEFAULT_COLORS
11 Default colors used by #createDiscreteStyle(GridCoverage2D, double, Color...) if no colors are given.
  1. White
  2. Red
  3. Blue
  4. Yellow
  5. Green
  6. Gray
  7. Orange
  8. Pink
  9. Magenta
  10. Light gray
  11. Cyan
  12. Black

Constructor Detail

GridUtil

public GridUtil()
Method Detail

determineStatistic

public static GridStatistic determineStatistic(GridCoverage2D gc,
                                               int band,
                                               int histogramSteps,
                                               Integer histogrammDigits)
Liefert statistische Daten ueber ein Grid und erstellt ein Histogramm

Parameters:
gc - ein Raster
band - zu untersuchendes Band
histogramSteps - Schritte des Histogramms, -1 wenn alle Ausprägungen, 0 für ohne Histogramm
histogrammDigits - Anzahl an Nachkommastellen auf die die Histogramm-Klassen gerundet werden (negative Werte = Vorkommastellen; null = kein Runden). Nur relevant, wenn hishistogramSteps = -1

determineStatistic

public static GridStatistic determineStatistic(GridCoverage2D gc,
                                               int band,
                                               int histogramSteps)
Liefert statistische Daten ueber ein Grid und erstellt ein Histogramm. Die Histogramm-Klassen werden auf ganze Zahlen gerundet.

Parameters:
gc - ein Raster
band - zu untersuchendes Band
histogramSteps - Schritte des Histogramms, -1 wenn alle Ausprägungen, 0 für ohne Histogramm

determineStatistic

public static GridStatistic determineStatistic(GridCoverage2D gc,
                                               int band)
Liefert statistische Daten ueber ein Grid, ohne ein Histogram zu berechnen.

Parameters:
gc - ein Raster
band - zu untersuchendes Band

determineZoneStatistic

public static GridZoneStatistic<Float> determineZoneStatistic(GridCoverage2D valueGC,
                                                              GridCoverage2D zoneGC)
Liefert statistische Daten ueber ein Grid, das in Zonen unterteilt ist. Die Zonen werden durch einen Float-Wert identifiziert, damit auch NoData-Werte in einem Raster einer Zone (naemlich der Zone Float.NaN) zugewiesen werden koennen.

Parameters:
valueGC - Raster ueber das die Statistik erzeugt wird
zoneGC - Raster, das die Zonen bestimmt

determineZoneStatistic

public static GridZoneStatistic<Float> determineZoneStatistic(GridCoverage2D valueGC,
                                                              int valueBand,
                                                              GridCoverage2D zoneGC,
                                                              int zoneBand)
Liefert statistische Daten ueber ein Grid, das in Zonen unterteilt ist. Die Zonen werden durch einen Float-Wert identifiziert, damit auch NoData-Werte in einem Raster einer Zone (naemlich der Zone Float.NaN) zugewiesen werden koennen.

Parameters:
valueGC - Raster ueber das die Statistik erzeugt wird
valueBand - Band ueber das die Statistik erzeugt wird
zoneGC - Raster, das die Zonen bestimmt
zoneBand - Band, das die Zonen bestimmt

createDefaultStyle

public static Style createDefaultStyle()
Erzeugt einen Standard-Style fuer ein GridCoverage2D und setzt den default-Namen: GridUtil.DEFAULT_RASTER_STYLE_NAME Und eine title : GridUtil.DEFAULT_RASTER_STYLE_TITLE


createStyle

public static Style createStyle(ColorMap colorMap,
                                double opacity)
Erzeugt einen Standard-Style fuer ein GridCoverage2D

Parameters:
colorMap - Farb-Palette
opacity - Transparenz (1.0 = vollfarbig)
Returns:
ein Standard-Style ( StyleBuilder.createRasterSymbolizer()) falls keine ColorMap angegeben wird

createInterpolativeStyle

public static Style createInterpolativeStyle(GridCoverage2D grid,
                                             double opacity,
                                             Color... colors)
Creates an interpolative style for a GridCoverage2D. The given colors are interpolated from the minimum to the maximum raster value.

Parameters:
grid - the raster
opacity - opacity for the style
colors - colors to interpolate with (at least 2)

createDiscreteStyle

public static Style createDiscreteStyle(GridCoverage2D grid,
                                        double opacity,
                                        Integer digits,
                                        Color... colorPalette)
Creates a discrete style for a GridCoverage2D. For every value in the raster another color is choosen. If the raster contains more values than colors are given, all surplus values are mapped to the "last" color.

Parameters:
grid - the raster
opacity - opacity for the style
digits - number of digits the grid value classes (and legend) are rounded to (null means no round; >= 0 means digits after comma; < 0 means digits before comma)
colorPalette - colors for the values (the smallest value is mapped to index 0, the second smallest to index 1, ...); if no colors are specified DEFAULT_COLORS are used

copyGridCoverage

public static GridCoverage2D copyGridCoverage(GridCoverage2D source)
Kopiert ein GridCoverage2D komplett.

Parameters:
source - Quell-Raster

copyGridCoverage

public static GridCoverage2D copyGridCoverage(GridCoverage2D source,
                                              int minX,
                                              int minY)
Kopiert ein GridCoverage2D komplett, dessen Raster-Koordinaten (obere-linke Ecke) transformiert wird.

Parameters:
source - Quell-Raster
minX - neue Raster-Koordinate fuer die obere linke Ecke
minY - neue Raster-Koordinate fuer die obere linke Ecke

resampleGridCoverage

public static GridCoverage2D resampleGridCoverage(GridCoverage2D gc,
                                                  GridSampleDimension sampleDim)
Erzeugt ein neues GridCoverage2D mit neuer SampleDimension.

Parameters:
gc - Raster (mit nur einem Band)
sampleDim - neue SampleDimension
Returns:
eine neue GridCoverage2D-Instanz

resampleGridCoverage

public static GridCoverage2D resampleGridCoverage(GridCoverage2D gc,
                                                  GridSampleDimension[] sampleDim)
Erzeugt ein neues GridCoverage2D mit neuer SampleDimension.

Parameters:
gc - Raster
sampleDim - neue SampleDimension
Returns:
eine neue GridCoverage2D-Instanz

createGridCoverage

public static GridCoverage2D createGridCoverage(GridCoverage2D source,
                                                Envelope bboxEnv)
Erzeugt ein GridCoverage2D aus einem anderen. Das neue Raster hat maximal die Ausmasse des Quell-Rasters.

Parameters:
source - Quell-Raster
bboxEnv - Bounding-Box (beschreibt die den Ausschnitt des Quell-Rasters aus dem das neue Raster erzeugt wird)
Returns:
null falls sich das Quell-Raster und die Bounding-Box nicht ueberschneiden.

createWritableRaster

public static WritableRaster createWritableRaster(Raster r,
                                                  int minX,
                                                  int minY)
Erzeugt ein WritableRaster aus einem Raster.

Parameters:
r - Raster
minX - Start-Index in X-Richtung
minY - Start-Index in Y-Richtung

createWritableRaster

public static WritableRaster createWritableRaster(Raster r)
Erzeugt ein WritableRaster aus einem Raster.

Parameters:
r - Raster

convertToGridCoverage2D

public static GridCoverage2D convertToGridCoverage2D(Object obj)
Konvertiert ein Raster-Objekt in eine GridCoverage2D. Es werden folgende Objekt-Typen unterstuetzt:

Parameters:
obj - Object
Throws:
IllegalArgumentException - falls das Objekt nicht konvertiert werden kann

convertRealToRaster

public static int convertRealToRaster(double coord,
                                      double realMin,
                                      double realLength,
                                      int rasterMin,
                                      int rasterLength)
Converts a real world coordinate to the row/column number of a raster. If the coordinate value is exactly located on the border between two cells, the next greater raster cell is returned (except the raster border: the lower (=last) cell is returned).
This method can be applied on all dimensions (X or Y or ...), if the accordingly input parameter for the dimension are given.
Note: Because this method is independed from the dimension, it assumes that the "beginning" of the raster coordinates is located in the same corner like the lat/lon-refernce!!

Parameters:
coord - geographic reference (world coordinate), which is converted
realMin - minimal world coordinate of the raster
realLength - length of the raster in "world coordinates"
rasterMin - index of the first raster cell (normally 0)
rasterLength - size of the raster (in cells)
Throws:
UnsupportedOperationException - falls als rasterLength 0 uebergeben wird

convertRasterToReal

public static double convertRasterToReal(int cell,
                                         int rasterMin,
                                         double realMin,
                                         double cellSize)
Converts a raster cell index to "real" world coordinates. The coordinate of the cell center is returned.
This method can be applied on all dimensions (X or Y or ...), if the accordingly input parameter for the dimension are given.
Note: Because this method is independed from the dimension, it assumes that the "beginning" of the raster coordinates is located in the same corner like the lat/lon-refernce!!

Parameters:
cell - raster index, which is converted
rasterMin - minimal index of the raster
realMin - minimal world coordinate of the raster
cellSize - size of one cell in "world coordinates"

convertRealToRaster

public static int[] convertRealToRaster(GridCoverage2D gc,
                                        double geoX,
                                        double geoY)
Converts a geo reference to raster coordinates.

Parameters:
gc - source raster
geoX - Longitude to be converted
geoY - Latitude to be converted
Returns:
2-dimensional array with the X-index in element 0 and the Y-index in element 1

convertRealToRaster

public static int[] convertRealToRaster(Envelope2D env,
                                        RenderedImage image,
                                        double geoX,
                                        double geoY)
Converts a geo reference to raster coordinates.

Parameters:
env - geo reference of the raster
image - image of the raster
geoX - Longitude to be converted
geoY - Latitude to be converted
Returns:
2-dimensional array with the X-index in element 0 and the Y-index in element 1

convertRealToRaster

public static int[] convertRealToRaster(GridCoverage2D gc,
                                        double[] geoCoord)
Converts a geo reference to raster coordinates.

Parameters:
gc - source raster
geoCoord - geo reference (Longitude,Latitude) to be converted
Returns:
2-dimensional array with the X-index in element 0 and the Y-index in element 1

convertRealToRaster

public static int[] convertRealToRaster(Envelope2D env,
                                        RenderedImage image,
                                        double[] geoCoord)
Converts a geo reference to raster coordinates.

Parameters:
env - geo reference of the raster
image - image of the raster
geoCoord - geo reference (Longitude,Latitude) to be converted
Returns:
2-dimensional array with the X-index in element 0 and the Y-index in element 1

getOverlappingCells

public static Set<Point> getOverlappingCells(GridCoverage2D gc,
                                             LineString ls,
                                             Set<Point> result)
Determines the raster cells, which are intersected by a LineString.

Parameters:
gc - the raster
ls - LineString to check
result - Set the intersected cells are inserted in (can be null)
Returns:
an empty set if the LineString is located outside the raster

getOverlappingCells

public static WritableRaster getOverlappingCells(GridCoverage2D gc,
                                                 Geometry g,
                                                 Number markValue,
                                                 WritableRaster result)
Marks all raster cells, which are intersected by a Geometry.

Parameters:
gc - the raster
g - Geometry, which is checked for intersection
markValue - value the intersected cells are marked with
result - Raster, the intersected cells are marked in (can be null)

getOverlappingCells

public static GridCoverage2D getOverlappingCells(GridCoverage2D gc,
                                                 Geometry g,
                                                 Number markValue)
Marks all raster cells, which are intersected by a Geometry.

Parameters:
gc - the raster
g - Geometry, checked for intersection
markValue - value the intersected cells are marked with
Returns:
a NEW instance of GridCoverage2D!!