/*
* Geotools 2 - OpenSource mapping toolkit
* (C) 2003, Geotools Project Management Committee (PMC)
* (C) 2001, Institut de Recherche pour le Développement
*
* This library 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 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.geotools.resources;
// J2SE dependencies
import java.awt.image.RenderedImage;
import org.geotools.ct.MathTransform;
import org.geotools.ct.MathTransform1D;
import org.geotools.cv.SampleDimension;
import org.geotools.gc.GridCoverage;
import org.geotools.gc.GridGeometry;
import org.geotools.gc.GridRange;
import org.geotools.gc.InvalidGridGeometryException;
import org.geotools.pt.Envelope;
/**
* A set of utilities methods for the Grid Coverage package. Those methods are not really
* rigorous; must of them should be seen as temporary implementations.
*
* @source $URL$
* @version $Id$
* @author Martin Desruisseaux
*
* @deprecated Replaced by {@link org.geotools.resources.image.CoverageUtilities}.
*/
public final class LegacyGCSUtilities {
/**
* Do not allows instantiation of this class.
*/
private LegacyGCSUtilities() {
}
///////////////////////////////////////////////////////////////////
//////// ////////
//////// GridGeometry / GridRange / Envelope ////////
//////// ////////
///////////////////////////////////////////////////////////////////
/**
* Returns true
if the specified geometry has a valid grid range.
*/
public static boolean hasGridRange(final GridGeometry geometry) {
if (geometry != null) try {
geometry.getGridRange();
return true;
} catch (InvalidGridGeometryException exception) {
// Ignore.
}
return false;
}
/**
* Returns true
if the specified geometry
* has a valid "grid to coordinate system" transform.
*/
public static boolean hasTransform(final GridGeometry geometry) {
if (geometry != null) try {
geometry.getGridToCoordinateSystem();
return true;
} catch (InvalidGridGeometryException exception) {
// Ignore.
}
return false;
}
/**
* Cast the specified grid range into an envelope. This is sometime used before to transform
* the envelope using {@link CTSUtilities#transform(MathTransform, Envelope)}.
*/
public static Envelope toEnvelope(final GridRange gridRange) {
final int dimension = gridRange.getDimension();
final double[] lower = new double[dimension];
final double[] upper = new double[dimension];
for (int i=0; i
* Note about conversion of floating point values to integers:
* In previous versions, we used {@link Math#floor} and {@link Math#ceil} in order to
* make sure that the grid range encompass all the envelope (something similar to what
* Java2D does when casting {@link java.awt.geom.Rectangle2D} to
* {@link java.awt.Rectangle}). But it had the undesirable effect of changing image width.
* For example the range [-0.25 99.75]
were changed to [-1 100]
,
* which is not what the {@link javax.media.jai.operator.AffineDescriptor Affine} operation
* expects for instance. Rounding to nearest integer produces better results. Note that the
* rounding mode do not alter the significiance of the "Resample" operation, since this
* operation will respect the "grid to coordinate system" transform no matter what the
* grid range is.
*/
public static GridRange toGridRange(final Envelope envelope) {
final int dimension = envelope.getDimension();
final int[] lower = new int[dimension];
final int[] upper = new int[dimension];
for (int i=0; itrue if at least one of the specified sample dimensions has a
* {@linkplain SampleDimension#getSampleToGeophysics sample to geophysics} transform
* which is not the identity transform.
*/
public static boolean hasTransform(final SampleDimension[] sampleDimensions) {
for (int i=sampleDimensions.length; --i>=0;) {
MathTransform1D tr = sampleDimensions[i].geophysics(false).getSampleToGeophysics();
if (tr!=null && !tr.isIdentity()) {
return true;
}
}
return false;
}
/**
* Returns true
if the specified grid coverage or any of its source
* uses the following image.
*/
public static boolean uses(final GridCoverage coverage, final RenderedImage image) {
if (coverage != null) {
if (coverage.getRenderedImage() == image) {
return true;
}
final GridCoverage[] sources = coverage.getSources();
if (sources != null) {
for (int i=0; i