@Override public void createIndividuals() { LOG.info("Loading population from raster file {}", sourceFilename); try { File rasterFile = new File(sourceFilename); // determine file format and CRS, then load raster AbstractGridFormat format = GridFormatFinder.findFormat(rasterFile); AbstractGridCoverage2DReader reader = format.getReader(rasterFile); GridCoverage2D coverage = reader.read(null); this.coverageCRS = coverage.getCoordinateReferenceSystem(); GridGeometry2D gridGeometry = coverage.getGridGeometry(); GridEnvelope2D gridEnvelope = gridGeometry.getGridRange2D(); gridGeometry.getGridToCRS(); // because we may want to produce an empty raster rather than loading one, alongside the coverage we // store the row/col dimensions and the referenced envelope in the original coordinate reference system. this.cols = gridEnvelope.width; this.rows = gridEnvelope.height; this.createIndividuals0(); } catch (Exception ex) { throw new IllegalStateException("Error loading population from raster file: ", ex); } LOG.info("Done loading raster from file."); }
(int) Math.round(padRange.getSpan(0)), (int) Math.round(padRange.getSpan(1))); GridEnvelope2D sourceRange = gg.getGridRange2D(); if (sourceRange.x == targetRange.x && sourceRange.y == targetRange.y
GridEnvelope2D range = requestedGridGeometry.getGridRange2D(); GridEnvelope2D expandedRange = new GridEnvelope2D( float width, height; if (requestedGridGeometry != null) { GridEnvelope2D range = requestedGridGeometry.getGridRange2D(); width = (float) range.getWidth(); height = (float) range.getHeight();
coverage.getGridGeometry().getGridRange2D(), coverage.getRenderedImage().getSampleModel()); if (actual > limit) {
final long pixelsNumber = computePixelsNumber(gc.getGridGeometry().getGridRange2D());
@Override public Set<? extends RasterLayout> getRasterElements( boolean overall, ProgressListener listener) throws IOException { Rectangle bounds = gridGeometry.getGridRange2D().getBounds(); return Collections.singleton(new RasterLayout(bounds)); } }
public void setRequestedGridGeometry(GridGeometry2D gridGeometry) { Utilities.ensureNonNull("girdGeometry", gridGeometry); requestedBBox = new ReferencedEnvelope((Envelope) gridGeometry.getEnvelope2D()); requestedRasterArea = gridGeometry.getGridRange2D().getBounds(); requestedGridGeometry = gridGeometry; requestedGridToWorld = (AffineTransform) gridGeometry.getGridToCRS2D(); }
public void setRequestedGridGeometry(GridGeometry2D gridGeometry) { Utilities.ensureNonNull("girdGeometry", gridGeometry); requestedBBox = new ReferencedEnvelope((Envelope) gridGeometry.getEnvelope2D()); requestedRasterArea = gridGeometry.getGridRange2D().getBounds(); requestedGridToWorld = (AffineTransform) gridGeometry.getGridToCRS2D(); }
@Override public GridEnvelope getOriginalGridRange(String coverageName) { coverageName = checkUnspecifiedCoverage(coverageName); try { final CoverageSource source = getGridCoverageSource(coverageName); VariableAdapter.UnidataSpatialDomain spatialDomain = (UnidataSpatialDomain) source.getSpatialDomain(); return spatialDomain.getGridGeometry().getGridRange2D(); } catch (IOException e) { throw new RuntimeException(e); } }
GridEnvelope2D gridEnv = grid.getGridRange2D(); GridGeometry2D gridI = sources[i].getGridGeometry(); Envelope2D envI = gridI.getEnvelope2D(); GridEnvelope2D gridEnvI = gridI.getGridRange2D(); double resValue = envI.width / gridEnvI.width;
GridEnvelope2D gridEnv = grid.getGridRange2D(); GridGeometry2D gridI = sources[i].getGridGeometry(); Envelope2D envI = gridI.getEnvelope2D(); GridEnvelope2D gridEnvI = gridI.getGridRange2D(); double resValue = envI.width / gridEnvI.width;
GridEnvelope2D gridRange = gridGeometry.getGridRange2D(); int height = gridRange.height; int width = gridRange.width;
/** * Transforms a point represented by a GridCoordinates2D object from grid to world coordinates. * The coordinates returned are those of the centre of the grid cell in which the point lies. * * <p>Users needing more control over the nature of the conversion (e.g. calculating cell corner * coordinates) can use the {@code MathsTransform} provided by {@linkplain * GridGeometry2D#getGridToCRS2D(PixelOrientation) } which is accessed via {@linkplain * #getGridGeometry()}. * * @param point The point in world coordinate system. * @return A new point in the grid coordinate system as a GridCoordinates2D object * @throws TransformException if the transformation failed. * @throws IllegalArgumentException if the point lies outside the coverage * @since 2.6 */ public final DirectPosition gridToWorld(final GridCoordinates2D point) throws TransformException { if (getGridRange2D().contains(point)) { Point2D trPoint = getGridToCRS2D().transform(point, null); return new DirectPosition2D( getCoordinateReferenceSystem2D(), trPoint.getX(), trPoint.getY()); } else { throw new IllegalArgumentException( Errors.format(ErrorKeys.POINT_OUTSIDE_COVERAGE_$1, point)); } }
@Override protected GridCoverage2D readCoverage( GridCoverage2DReader reader, Object readParams, GridGeometry2D readGG) throws IOException { Interpolation interpolation = getRenderingInterpolation(layer); GridCoverageReaderHelper helper; try { helper = new GridCoverageReaderHelper( reader, readGG.getGridRange2D(), ReferencedEnvelope.reference( readGG.getEnvelope2D()), interpolation); return helper.readCoverage((GeneralParameterValue[]) readParams); } catch (InvalidGridGeometryException | FactoryException e) { throw new IOException("Failure reading the coverage", e); } } };
/** * Transforms a rectangle represented by a GridEnvelope2D object from grid to world coordinates. * The bounds of the Envelope2D object returned correspond to the outer edges of the grid cells * within the input envelope. * * <p>Users needing more control over the nature of the conversion can use the {@code * MathsTransform} provided by {@linkplain GridGeometry2D#getGridToCRS2D(PixelOrientation) } * which is accessed via {@linkplain #getGridGeometry()}. * * @param gridEnv The rectangle of grid coordinates to convert * @return World coordinates of the rectangle as a new Envelope2D object * @throws TransformException if the transformation failed. * @throws IllegalArgumentException if the input rectangle lies outside the coverage * @since 2.6 */ public final Envelope2D gridToWorld(final GridEnvelope2D gridEnv) throws TransformException { MathTransform2D mt = getGridToCRS2D(); if (getGridRange2D().contains(gridEnv)) { GridCoordinates2D low = gridEnv.getLow(); Point2D trLow = mt.transform(new Point2D.Double(low.x - 0.5, low.y - 0.5), null); GridCoordinates2D high = gridEnv.getHigh(); Point2D trHigh = mt.transform(new Point2D.Double(high.x + 0.5, high.y + 0.5), null); return new Envelope2D( new DirectPosition2D(crs2D, trLow.getX(), trLow.getY()), new DirectPosition2D(crs2D, trHigh.getX(), trHigh.getY())); } else { throw new IllegalArgumentException( Errors.format(ErrorKeys.POINT_OUTSIDE_COVERAGE_$1, gridEnv)); } }
private GridGeometry2D applyReadGutter(GridGeometry2D gg) { MathTransform gridToCRS = gg.getGridToCRS(); GridEnvelope2D range = new GridEnvelope2D(gg.getGridRange2D()); applyReadGutter(range); CoordinateReferenceSystem crs = gg.getEnvelope2D().getCoordinateReferenceSystem(); GridGeometry2D result = new GridGeometry2D(range, PixelInCell.CELL_CORNER, gridToCRS, crs, null); return result; }
/** * This method is used for setting the final image layout. * * @param parameters * @param layout * @param bbox */ private void updateLayout( final BandMergeParams parameters, ImageLayout layout, Envelope2D bbox) { // Creation of a GridGeoemtry with the selected BBOX and the defined World2Grid // transformation GridGeometry2D gg2D = new GridGeometry2D(PixelInCell.CELL_CORNER, parameters.gridToCRS, bbox, null); // Selection of the GridEnvelope from the GridGeometry for using it as the new Layout GridEnvelope2D gridRange2D = gg2D.getGridRange2D(); layout.setMinX(gridRange2D.x); layout.setMinY(gridRange2D.y); layout.setWidth(gridRange2D.width); layout.setHeight(gridRange2D.height); }
public ReadResolutionCalculator( GridGeometry2D requestedGridGeometry, CoordinateReferenceSystem nativeCrs, double[] fullResolution) throws FactoryException { Utilities.ensureNonNull("gridGeometry", requestedGridGeometry); this.requestedBBox = new ReferencedEnvelope((Envelope) requestedGridGeometry.getEnvelope2D()); this.requestedRasterArea = requestedGridGeometry.getGridRange2D().getBounds(); this.requestedGridToWorld = (AffineTransform) requestedGridGeometry.getGridToCRS2D(); this.fullResolution = fullResolution; // the reader might not know (e.g., wms cascading reader) in this case we // pick the classic computation results, it's better than nothing if (fullResolution == null) { this.fullResolution = computeClassicResolution(); isFullResolutionInRequestedCRS = true; } CoordinateReferenceSystem requestedCRS = requestedGridGeometry.getCoordinateReferenceSystem(); if (!CRS.equalsIgnoreMetadata(nativeCrs, requestedCRS)) { this.destinationToSourceTransform = CRS.findMathTransform(requestedCRS, nativeCrs); } }
VariableAdapter.UnidataSpatialDomain spatialDomain = (UnidataSpatialDomain) source.getSpatialDomain(); GridEnvelope2D gridRange = spatialDomain.getGridGeometry().getGridRange2D(); RasterLayout rasterElement = spatialDomain.getRasterElements(false, null).iterator().next();
final GridGeometry2D gg = (GridGeometry2D) param.getValue(); requestedEnvelope = new GeneralEnvelope((Envelope) gg.getEnvelope2D()); dim = gg.getGridRange2D().getBounds(); continue;