/** * Constructs a new two-dimensional grid geometry. A math transform will be computed * automatically with an inverted <var>y</var> axis (i.e. {@code gridRange} and * {@code userRange} are assumed to have <var>y</var> axis in opposite direction). * * @param gridRange The valid coordinate range of a grid coverage. * Increasing <var>x</var> values goes right and * increasing <var>y</var> values goes <strong>down</strong>. * @param userRange The corresponding coordinate range in user coordinate. * Increasing <var>x</var> values goes right and * increasing <var>y</var> values goes <strong>up</strong>. * This rectangle must contains entirely all pixels, i.e. * the rectangle's upper left corner must coincide with * the upper left corner of the first pixel and the rectangle's * lower right corner must coincide with the lower right corner * of the last pixel. */ public GridGeometry2D(final Rectangle gridRange, final Rectangle2D userRange) { this(new GeneralGridRange(gridRange), getMathTransform(gridRange, userRange), (CoordinateReferenceSystem) null); }
/** * Constructs one-dimensional grid range. * * @param lower The minimal inclusive value. * @param upper The maximal exclusive value. */ public GeneralGridRange(final int lower, final int upper) { index = new int[] {lower, upper}; checkCoherence(); }
/** * Returns a {@link Rectangle} with the same bounds as this {@code GeneralGridRange}. * This is a convenience method for interoperability with Java2D. * * @throws IllegalStateException if this grid range is not two-dimensional. */ public Rectangle toRectangle() throws IllegalStateException { if (index.length == 4) { return new Rectangle(index[0], index[1], index[2]-index[0], index[3]-index[1]); } else { throw new IllegalStateException(Errors.format(ErrorKeys.NOT_TWO_DIMENSIONAL_$1, new Integer(getDimension()))); } }
.toRectangle(), finalGridRange); GeneralGridRange newRange = new GeneralGridRange( new GeneralEnvelope(finalGridRange)); if (newRange.equals(sourceGridRange) && isSimpleTransform) return sourceCoverage; double minX = newRange.getLower(xAxis); double minY = newRange.getLower(yAxis); double width = newRange.getLength(xAxis); double height = newRange.getLength(yAxis); assert width > 0; assert height > 0; .toRectangle(), bounds); final GeneralGridRange newRange2 = new GeneralGridRange( new GeneralEnvelope(bounds)); if (newRange2.equals(sourceGridRange) && isSimpleTransform) return sourceCoverage; assert newRange2.getLength(xAxis)>0; assert newRange2.getLength(yAxis)>0; layout.setMinX(newRange2.getLower(xAxis)); layout.setWidth( newRange2.getLength(xAxis) ); layout.setMinY(newRange2.getLower(yAxis)); layout.setHeight( newRange2.getLength(yAxis)); operatioName = "Mosaic";
int hrHeight = reader.getHeight(0); final Rectangle actualDim = new Rectangle(0, 0, hrWidth, hrHeight); originalGridRange = new GeneralGridRange(actualDim); overViewResolutions = new double[numOverviews][2]; for (int i = 0; i < numOverviews; i++) { overViewResolutions[i][0] = (highestRes[0]*this.originalGridRange.getLength(0))/reader.getWidth(i+1); overViewResolutions[i][1] = (highestRes[1]*this.originalGridRange.getLength(1))/reader.getHeight(i+1);
/** * Returns a new grid range that encompass only some dimensions of this grid range. * This method copy this grid range's index into a new grid range, beginning at * dimension {@code lower} and extending to dimension {@code upper-1}. * Thus the dimension of the subgrid range is {@code upper-lower}. * * @param lower The first dimension to copy, inclusive. * @param upper The last dimension to copy, exclusive. * @return The subgrid range. * @throws IndexOutOfBoundsException if an index is out of bounds. */ public GeneralGridRange getSubGridRange(final int lower, final int upper) { final int curDim = index.length/2; final int newDim = upper-lower; if (lower<0 || lower>curDim) { throw new IndexOutOfBoundsException(Errors.format(ErrorKeys.ILLEGAL_ARGUMENT_$2, "lower", new Integer(lower))); } if (newDim<0 || upper>curDim) { throw new IndexOutOfBoundsException(Errors.format(ErrorKeys.ILLEGAL_ARGUMENT_$2, "upper", new Integer(upper))); } final GeneralGridRange gridRange = new GeneralGridRange(newDim); System.arraycopy(index, lower, gridRange.index, 0, newDim); System.arraycopy(index, lower+curDim, gridRange.index, newDim, newDim); return gridRange; }
/** * Constructs two-dimensional range defined by a {@link Rectangle}. */ public GeneralGridRange(final Rectangle rect) { index = new int[] { rect.x, rect.y, rect.x+rect.width, rect.y+rect.height }; checkCoherence(); }
/** * Constructor for a {@link SubsampleAveragedCoverage}. * * @param image * @param sourceCoverage * @param actionTaken */ private SubsampleAveragedCoverage(PlanarImage image, GridCoverage2D sourceCoverage, int actionTaken) { super(sourceCoverage.getName(), image, new GridGeometry2D( new GeneralGridRange(image), sourceCoverage.getEnvelope()), (GridSampleDimension[]) (actionTaken == 1 ? null : sourceCoverage.getSampleDimensions().clone()), new GridCoverage[] { sourceCoverage }, sourceCoverage .getProperties()); }
/** * Constructs two-dimensional range defined by a {@link Raster}. */ public GeneralGridRange(final Raster raster) { final int x = raster.getMinX(); final int y = raster.getMinY(); index = new int[] { x, y, x+raster.getWidth(), y+raster.getHeight() }; checkCoherence(); }
final int hrHeight = Integer.parseInt(attributes.getNamedItem("nRows") .getNodeValue()); originalGridRange = new GeneralGridRange(new Rectangle(0, 0, hrWidth, hrHeight)); final boolean pixelIsArea = attributes.getNamedItem("rasterSpaceType")
/** * Constructs a new grid range. * * @param lower The valid minimum inclusive grid coordinate. * The array contains a minimum value for each * dimension of the grid coverage. The lowest * valid grid coordinate is zero. * @param upper The valid maximum exclusive grid coordinate. * The array contains a maximum value for each * dimension of the grid coverage. * * @see #getLowers * @see #getUppers */ public GeneralGridRange(final int[] lower, final int[] upper) { if (lower.length != upper.length) { throw new IllegalArgumentException(Errors.format(ErrorKeys.MISMATCHED_DIMENSION_$2, new Integer(lower.length), new Integer(upper.length))); } index = new int[lower.length + upper.length]; System.arraycopy(lower, 0, index, 0, lower.length); System.arraycopy(upper, 0, index, lower.length, upper.length); checkCoherence(); }
/** * Creates a filtered subsampled image for the specified source coverage. * * @todo The {@link GridGeometry2D} calculation in this method is wrong!! The calculation * should <strong>always</strong> be performed on {@link MathTransform}, never on * a grid range - envelope pair when the math transform is available. */ FilteredSubsampledGridCoverage2D(PlanarImage image, GridCoverage2D sourceCoverage, int actionTaken) { super(sourceCoverage.getName(), image, new GridGeometry2D( new GeneralGridRange(image), sourceCoverage.getEnvelope()), (GridSampleDimension[]) (actionTaken==1 ? null : sourceCoverage .getSampleDimensions().clone()), new GridCoverage[] { sourceCoverage }, sourceCoverage .getProperties()); }
/** * Constructs multi-dimensional range defined by a {@link RenderedImage}. * * @param image The image. * @param dimension Number of dimensions for this grid range. * Dimensions over 2 will be set to the [0..1] range. */ GeneralGridRange(final RenderedImage image, final int dimension) { index = new int[dimension*2]; final int x = image.getMinX(); final int y = image.getMinY(); index[0] = x; index[1] = y; index[dimension+0] = x+image.getWidth(); index[dimension+1] = y+image.getHeight(); Arrays.fill(index, dimension+2, index.length, 1); checkCoherence(); }
/** * Creates a scaled coverage as requested. * * @param image * is the source image to use for building this * {@link GridCoverage2D}. * @param sourceCoverage * is the coverage that was used as the source for this * operation. * @param actionTaken * is the action we took when preparing ths source image for the * scale operation. */ private ScaledGridCoverage2D(PlanarImage image, GridCoverage2D sourceCoverage, int actionTaken) { super(sourceCoverage.getName(), image, new GridGeometry2D( new GeneralGridRange(image), sourceCoverage.getEnvelope()), (GridSampleDimension[]) (actionTaken == 1 ? null : sourceCoverage.getSampleDimensions().clone()), new GridCoverage[] { sourceCoverage }, sourceCoverage .getProperties()); } }
/** * Constructs a grid coverage from the specified {@linkplain RenderedImage image} and * "{@linkplain GridGeometry2D#getGridToCoordinateSystem grid to CRS}" transform. * * @param name The grid coverage name. * @param image The image. * @param crs The coordinate reference system. This specifies the CRS used when * accessing a grid coverage with the {@code evaluate} methods. The * number of dimensions must matches the number of target dimensions * of {@code gridToCRS}. * @param gridToCRS The math transform from grid to coordinate reference system. * @param bands Sample dimension for each image band, or {@code null} for default sample * dimensions. If non-null, then this array's length must matches the number * of bands in the {@code image}. * @param sources The sources for this grid coverage, or {@code null} if none. * @param properties The set of properties for this coverage, or {@code null} if there is none. */ public GridCoverage2D create(final CharSequence name, final RenderedImage image, final CoordinateReferenceSystem crs, final MathTransform gridToCRS, final GridSampleDimension[] bands, final GridCoverage[] sources, final Map properties) { final GridGeometry2D gm = new GridGeometry2D(new GeneralGridRange(image, crs.getCoordinateSystem().getDimension()), gridToCRS, crs); return create(name, image, gm, bands, sources, properties); }
/** * Gets resolution information about the coverage itself. * * @param reader * an {@link ImageReader} to use for getting the resolution * information. * @throws IOException * @throws TransformException */ private void getResolutionInfo(ImageReader reader) throws IOException, TransformException { // // // // get the dimension of the hr image and build the model as well as // computing the resolution // // final Rectangle actualDim = new Rectangle(0, 0, reader.getWidth(0), reader.getHeight(0)); originalGridRange = new GeneralGridRange(actualDim); // /// // // setting the higher resolution avalaible for this coverage // // /// highestRes = getResolution(originalEnvelope, actualDim, crs); }
originalGridRange = new GeneralGridRange(new Rectangle(0, 0, header .getNCols(), header.getNRows())); stats = new GT30Stats(this.statsURL);