public static HashMap<String, Double> getRegionParamsFromGridCoverage( GridCoverage2D gridCoverage) { HashMap<String, Double> envelopeParams = new HashMap<String, Double>(); Envelope envelope = gridCoverage.getEnvelope(); DirectPosition lowerCorner = envelope.getLowerCorner(); double[] westSouth = lowerCorner.getCoordinate(); DirectPosition upperCorner = envelope.getUpperCorner(); double[] eastNorth = upperCorner.getCoordinate(); GridGeometry2D gridGeometry = gridCoverage.getGridGeometry(); GridEnvelope2D gridRange = gridGeometry.getGridRange2D(); int height = gridRange.height; int width = gridRange.width; AffineTransform gridToCRS = (AffineTransform) gridGeometry.getGridToCRS(); double xRes = XAffineTransform.getScaleX0(gridToCRS); double yRes = XAffineTransform.getScaleY0(gridToCRS); envelopeParams.put(NORTH, eastNorth[1]); envelopeParams.put(SOUTH, westSouth[1]); envelopeParams.put(WEST, westSouth[0]); envelopeParams.put(EAST, eastNorth[0]); envelopeParams.put(XRES, xRes); envelopeParams.put(YRES, yRes); envelopeParams.put(ROWS, (double) height); envelopeParams.put(COLS, (double) width); return envelopeParams; }
/** Returns {@code true} if this direct position is equals to the given object. */ @Override public boolean equals(final Object object) { if (object instanceof DirectPosition) { final DirectPosition other = (DirectPosition) object; if (other.getCoordinateReferenceSystem() == null) { return Arrays.equals(ordinates, other.getCoordinate()); } } return false; }
private void storeResult( double[] interpolatedValues, HashMap<Integer, Coordinate> interpolatedCoordinatesMap) throws MismatchedDimensionException, Exception { WritableRandomIter outIter = RandomIterFactory.createWritable(outWR, null); Set<Integer> pointsToInterpolateIdSett = interpolatedCoordinatesMap.keySet(); Iterator<Integer> idIterator = pointsToInterpolateIdSett.iterator(); int c = 0; MathTransform transf = inInterpolationGrid.getCRSToGrid2D(); final DirectPosition gridPoint = new DirectPosition2D(); while (idIterator.hasNext()) { int id = idIterator.next(); Coordinate coordinate = (Coordinate) interpolatedCoordinatesMap.get(id); DirectPosition point = new DirectPosition2D( inInterpolationGrid.getCoordinateReferenceSystem(), coordinate.x, coordinate.y); transf.transform(point, gridPoint); double[] gridCoord = gridPoint.getCoordinate(); int x = (int) gridCoord[0]; int y = (int) gridCoord[1]; outIter.setSample(x, y, 0, checkResultValue(interpolatedValues[c])); c++; } RegionMap regionMap = CoverageUtilities.gridGeometry2RegionParamsMap(inInterpolationGrid); outGrid = CoverageUtilities.buildCoverage( "gridded", outWR, regionMap, inInterpolationGrid.getCoordinateReferenceSystem()); }