/******************************************************************************* * Copyright (c) 2009 Martin O. J. Schmitz. * * This file is part of the SCHMITZM library - a collection of utility * classes based on Java 1.6, focusing (not only) on Java Swing * and the Geotools library. * * The SCHMITZM project is hosted at: * http://wald.intevation.org/projects/schmitzm/ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License (license.txt) * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * or try this link: http://www.gnu.org/licenses/lgpl.html * * Contributors: * Martin O. J. Schmitz - initial API and implementation * Stefan A. Tzeggai - additional utility classes ******************************************************************************/ package de.appl.util; import java.awt.image.DataBuffer; import java.io.Serializable; import org.geotools.referencing.crs.DefaultGeographicCRS; import org.opengis.referencing.crs.CoordinateReferenceSystem; import de.schmitzm.geotools.data.WritableGrid; /** * Simple immutable class that encapsulates raster metadata, especially the * MetaData of a {@link WritableGrid}. Just a constructor and getters on the * fields. * *
* * @see WritableGrid for details on the variable description * * @author Dominik Appl */ public final class RasterMetaData implements Serializable { int width = 0; int height = 0; int minX = 0; int minY = 0; double realWidth = 0; double realHeight = 0; int dataType = DataBuffer.TYPE_UNDEFINED; double x = 0.0; double y = 0.0; CoordinateReferenceSystem crs = null; /** * @return Returns the CRS of the raster */ public final CoordinateReferenceSystem getCoordinateReferenceSystem() { return crs; } /** * @return Returns the height in cells */ public final int getHeight() { return height; } /** * @return Returns the width in cells. */ public final int getWidth() { return width; } /** * @return Returns the dataType. */ public final int getDataType() { return dataType; } /** * @return Returns minX (used to indicate a start index) * @see WritableGrid#getMinX() */ public final int getMinX() { return minX; } /** * @return Returns the minY ((used to indicate a start index) * @see WritableGrid#getMinY() */ public final int getMinY() { return minY; } /** * @return Returns the realHeight. */ public final double getRealHeight() { return realHeight; } /** * @return Returns the realWidth. */ public final double getRealWidth() { return realWidth; } /** * @return Returns the (geographic) x-coordinate */ public final double getX() { return x; } /** * @return Returns the (geographic) y-coordinate */ public final double getY() { return y; } /** * @param dataType * the datatype * @param gridWidth * the width of the grid (in cells) * @param gridHeight * the height of the grid (in cells) * @param minX * the minX (used to indicate a start index) * @param minY * the minY (used to indicate a start index) * @param realWidth * the real width * @param realHeight * the real height * @param x * the (geographic) x-coordinate * @param y * the (geographic) y-coordinate * @param crs * the {@link CoordinateReferenceSystem}. Use null for DefaultCRS * (WGS84) * * @see WritableGrid */ public RasterMetaData(int dataType, int gridWidth, int gridHeight, int minX, int minY, double x, double y, double realWidth, double realHeight, CoordinateReferenceSystem crs) { this.width = gridWidth; this.height = gridHeight; this.minX = minX; this.minY = minY; this.realWidth = realWidth; this.realHeight = realHeight; this.dataType = dataType; this.x = x; this.y = y; this.crs = (crs == null) ? DefaultGeographicCRS.WGS84 : crs; } /** * Constructs a RasterMetaData Object. The values of the real height/ width * are calculated out of the cellsize. The cells are assumed to be squares. * * @param dataType * the datatype * @param gridWidth * the width of the grid (in cells) * @param gridHeight * the height of the grid (in cells) * @param minX * the minX (used to indicate a start index) * @param minY * the minY (used to indicate a start index) * @param x * the (geographic) x-coordinate * @param y * the (geographic) y-coordinate * @param cellSize * the real size of one cell * @param crs * the {@link CoordinateReferenceSystem}, use null for default * CRS (WGS84) */ public RasterMetaData(int dataType, int gridWidth, int gridHeight, int minX, int minY, double x, double y, double cellSize, CoordinateReferenceSystem crs) { this(dataType, gridWidth, gridHeight, minX, minY, x, y, gridWidth * cellSize, gridHeight * cellSize, crs); } /** * Constructs a RasterMetaDataObject out of the given Grid * * @param w * the source grid */ public RasterMetaData(WritableGrid w) { super(); this.width = w.getWidth(); this.height = w.getHeight(); this.minX = w.getMinX(); this.minY = w.getMinY(); this.realWidth = w.getRealWidth(); this.realHeight = w.getRealHeight(); this.dataType = w.getSampleType(); this.x = w.getX(); this.y = w.getY(); this.crs = w.getCoordinateReferenceSystem(); } /** * needed for serialization */ private RasterMetaData() { this(0, 0, 0, 0, 0, 0, 0, 0, 0, null); } /** * @return the real width of a raster cell */ public final double getCellWidth() { return getRealWidth() / getWidth(); } /** * Checks if the given RasterMetaData object has the same values. * * @param rasterMeta * must be a RasterMetaDataObject! Else ClassCastException will * be thrown. * @return true, if all values are the same * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object rasterMeta) { RasterMetaData r = (RasterMetaData) rasterMeta; return (this.width == r.getWidth() && this.height == r.getHeight() && this.minX == r.getMinX() && this.minY == r.getMinY() && this.realWidth == r.getRealWidth() && this.realHeight == r.getRealHeight() && this.dataType == r.getDataType() && this.x == r.getX() && this.y == r .getY()); } /** * @return the real height of a raster cell */ public final double getCellHeight() { return getRealHeight() / getHeight(); } @Override public final String toString() { return "MetaData: type:" + dataType + " wc:" + width + "hc:" + height + " minX:" + minX + " minY:" + minY + " x:" + x + " y:" + y + " rw:" + realWidth + " rh:" + realHeight; } }