private GridCoverage2D retainBands( List<Integer> bandIndices, GridCoverage2D coverage, Hints hints) { final ParameterValueGroup param = PROCESSOR.getOperation("SelectSampleDimension").getParameters(); param.parameter("Source").setValue(coverage); final int[] sampleDimensionArray = ArrayUtils.toPrimitive(bandIndices.toArray(new Integer[bandIndices.size()])); param.parameter("SampleDimensions").setValue(sampleDimensionArray); coverage = (GridCoverage2D) PROCESSOR.doOperation(param, hints); return coverage; }
ParameterValueGroup readParameters = format.getReadParameters(); List<GeneralParameterDescriptor> descriptors = readParameters.getDescriptor().descriptors(); String pdCode = pv.getDescriptor().getName().getCode(); if ("FILTER".equals(pdCode) || "Filter".equals(pdCode)) { replacedOriginalFilter = true; ParameterValue pvalue = (ParameterValue) pv; Filter originalFilter = (Filter) pvalue.getValue(); if (originalFilter == null || Filter.INCLUDE.equals(originalFilter)) { pvalue.setValue(readFilter); } else { Filter combined = Predicates.and(originalFilter, readFilter); pvalue.setValue(combined); JTS.toGeometry((Envelope) new ReferencedEnvelope(grid.getEnvelope2D())); if (coverageBounds.intersects(rasterFilter)) { final ParameterValueGroup param = cropParams.clone(); param.parameter("source").setValue(grid); param.parameter("ROI").setValue(rasterFilter); grid = (GridCoverage2D) coverageCropFactory.doOperation(param, null); } else {
public void write(OutputStream outStream) { try { long t0 = System.currentTimeMillis(); GeoTiffWriteParams wp = new GeoTiffWriteParams(); wp.setCompressionMode(GeoTiffWriteParams.MODE_EXPLICIT); wp.setCompressionType("LZW"); ParameterValueGroup params = new GeoTiffFormat().getWriteParameters(); params.parameter(AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName().toString()).setValue(wp); new GeoTiffWriter(outStream).write(coverage, (GeneralParameterValue[]) params.values().toArray(new GeneralParameterValue[1])); //new GeoTiffWriter(outStream).write(coverage, null); //wasn't this line writing twice and trashing compressed version? long t1 = System.currentTimeMillis(); LOG.debug("wrote geotiff in {}msec", t1-t0); } catch (Exception e) { LOG.error("exception while preparing geotiff : {}", e.getMessage()); throw new WebApplicationException(e); } } };
ParameterValueGroup params = mapProjection.getParameterValues(); double latitudeOfCenter = params.parameter( LambertAzimuthalEqualArea.Provider.LATITUDE_OF_CENTRE .getName() .getCode()) .doubleValue(); double longitudeOfCenter = params.parameter( LambertAzimuthalEqualArea.Provider.LONGITUDE_OF_CENTRE .getName() .getCode()) .doubleValue();
writeBand = CoverageUtilities.getVisibleBand(gc.getRenderedImage()); if ((writeBands == null || writeBands.length == 0 || writeBands.length > 1) && (writeBand < 0 || writeBand > gc.getNumSampleDimensions())) throw new IllegalArgumentException( "You need to supply a valid index for deciding which band to write."); final CoordinateReferenceSystem crs = gc.getCoordinateReferenceSystem2D(); (ParameterValueGroup) processor .getOperation("SelectSampleDimension") .getParameters() .clone(); param.parameter("source").setValue(gc); param.parameter("SampleDimensions").setValue(new int[] {visibleBand}); gc = (GridCoverage2D) ((SelectSampleDimension) processor.getOperation("SelectSampleDimension")) .doOperation(param, null);
if (ggParameter.isPresent()) { ParameterValue value = (ParameterValue) ggParameter.get(); requestedGridGeometry = (GridGeometry2D) value.getValue(); ReferencedEnvelope requestedEnvelope = ReferencedEnvelope.reference(requestedGridGeometry.getEnvelope()); requestedGridGeometry.getGridToCRS(), requestedGridGeometry.getCoordinateReferenceSystem()); value.setValue(expandedGG); + coverageName + ", result has envelope " + coverage.getEnvelope2D()); final ParameterValueGroup param = PROCESSOR.getOperation(operationName).getParameters(); if (!handler.isHomogeneousCoverages()) { param.parameter("transform_choice").setValue("index"); param.parameter("coverage_idx").setValue(transformationChoice); param.parameter("sources").setValue(coverages); localHints.put( JAI.KEY_COLOR_MODEL_FACTORY, result = (GridCoverage2D) PROCESSOR.doOperation(param, localHints); } else {
return; // No need to reproject. crs2D = primarySource.getCoordinateReferenceSystem2D(); } else try { } catch (TransformException exception) { throw new CannotReprojectException("Unsupported CRS: " + crs2D.getName().getCode()); gridToCrs2D = primarySource.getGridGeometry().getGridToCRS2D(); final CoverageProcessor processor = CoverageProcessor.getInstance(hints); for (int i = 0; i < sources.length; i++) { if (sources[i] == null) { final GridGeometry2D geometry = source.getGridGeometry(); final CoordinateReferenceSystem srcCrs2D = source.getCoordinateReferenceSystem2D(); final CoordinateReferenceSystem sourceCRS = source.getCoordinateReferenceSystem(); "Unsupported CRS: " + sourceCRS.getName().getCode()); final ParameterValueGroup param = processor.getOperation("Resample").getParameters(); param.parameter("Source").setValue(source); param.parameter("GridGeometry").setValue(targetGeom); param.parameter("CoordinateReferenceSystem").setValue(targetCRS); sources[i] = (GridCoverage2D) processor.doOperation(param);
new AffineTransform( (AffineTransform) ((GridGeometry2D) dataCoverage.getGridGeometry()) .getGridToCRS2D(PixelOrientation.UPPER_LEFT)); final MathTransform w2gTransform; new ReferencedEnvelope(dataCoverage.getEnvelope2D()); ReferencedEnvelope geometryEnvelope = new ReferencedEnvelope( geometry.getEnvelopeInternal(), dataCoverage.getCoordinateReferenceSystem()); if (!coverageEnvelope.intersects((Envelope) geometryEnvelope)) { ParameterValueGroup param = PROCESSOR.getOperation("CoverageCrop").getParameters(); param.parameter("Source").setValue(dataCoverage); param.parameter("Envelope").setValue(new GeneralEnvelope(geometryEnvelope)); cropped = (GridCoverage2D) PROCESSOR.doOperation(param);
(AffineTransform) ((GridGeometry2D) gc.getGridGeometry()).getGridToCRS2D(); final double dx = XAffineTransform.getScaleX0(gridToWorld); final double dy = XAffineTransform.getScaleY0(gridToWorld); final RenderedImage image = gc.getRenderedImage(); int Nx = image.getWidth(); int Ny = image.getHeight(); final Envelope oldEnv = gc.getEnvelope2D(); final double W = oldEnv.getSpan(0); final double H = oldEnv.getSpan(1); (ParameterValueGroup) processor.getOperation("Resample").getParameters().clone(); param.parameter("source").setValue(gc); param.parameter("CoordinateReferenceSystem").setValue(gc.getCoordinateReferenceSystem2D()); param.parameter("GridGeometry").setValue(newGridGeometry); param.parameter("InterpolationType") .setValue(Interpolation.getInstance(Interpolation.INTERP_NEAREST)); return (GridCoverage2D) ((Resample) processor.getOperation("Resample")).doOperation(param, hints);
for (final GeneralParameterValue value : values.values()) { final String name = value.getDescriptor().getName().getCode(); if (value instanceof ParameterValueGroup) { descriptor = copy.getDescriptor().descriptor(name); if (descriptor instanceof ParameterDescriptorGroup) { final ParameterValueGroup groups = (ParameterValueGroup) descriptor.createValue(); copy((ParameterValueGroup) value, groups); values.groups(name).add(groups); continue; } else { final ParameterValue<?> target; try { target = copy.parameter(name); } catch (ParameterNotFoundException cause) { final InvalidParameterNameException exception = throw exception; final Object v = source.getValue(); final Unit<?> unit = source.getUnit(); if (unit == null) { target.setValue(v); } else if (v instanceof Number) { target.setValue(((Number) v).doubleValue(), unit);
final double roiTolerance = parameters.parameter(Crop.PARAMNAME_ROITOLERANCE).doubleValue(); final boolean forceMosaic = parameters.parameter(Crop.PARAMNAME_FORCEMOSAIC).booleanValue(); Range nodata = (Range) parameters.parameter(Crop.PARAMNAME_NODATA).getValue(); double[] destnodata = (double[]) parameters.parameter(Crop.PARAMNAME_DEST_NODATA).getValue(); final ParameterValue sourceParameter = parameters.parameter("Source"); if (sourceParameter == null || !(sourceParameter.getValue() instanceof GridCoverage2D)) { throw new CannotCropException( final ParameterValue envelopeParameter = parameters.parameter(PARAMNAME_ENVELOPE); final ParameterValue roiParameter = parameters.parameter(PARAMNAME_ROI); if ((envelopeParameter == null || envelopeParameter.getValue() == null) Envelope e2d = JTS.getEnvelope2D( cropRoi.getEnvelopeInternal(), source.getCoordinateReferenceSystem()); cropEnvelope = new GeneralEnvelope(e2d); final Envelope2D sourceEnvelope = source.getEnvelope2D(); destinationCRS = source.getCoordinateReferenceSystem2D(); ge.setCoordinateReferenceSystem(destinationCRS); destinationEnvelope = ge;
/** * Copies all parameter values from {@code source} to {@code target}. A typical usage of this * method is for transfering values from an arbitrary implementation to some specific * implementation (e.g. a parameter group implementation backed by a {@link * java.awt.image.renderable.ParameterBlock} for image processing operations). * * @param source The parameters to copy. * @param target Where to copy the source parameters. * @since 2.2 */ public static void copy(final ParameterValueGroup source, final ParameterValueGroup target) { for (final GeneralParameterValue param : source.values()) { final String name = param.getDescriptor().getName().getCode(); if (param instanceof ParameterValueGroup) { copy((ParameterValueGroup) param, target.addGroup(name)); } else { target.parameter(name).setValue(((ParameterValue) param).getValue()); } } }
String name = getName(param, group.getDescriptor().getName().getAuthority()); if (name == null) { name = param.getName().getCode(); if (param.getMinimumOccurs() != 0) { return Parameters.cast(group.parameter(name), param.getValueClass()); search = group.getDescriptor().descriptor(name); if (search instanceof ParameterDescriptor) { for (final GeneralParameterValue candidate : group.values()) { if (search.equals(candidate.getDescriptor())) { return Parameters.cast((ParameterValue) candidate, param.getValueClass());
final Polygon poly, final Resolution resolution) { final CoverageProcessor processor = CoverageProcessor.getInstance(); final AbstractOperation op = (AbstractOperation) processor.getOperation("Histogram"); final ParameterValueGroup params = op.getParameters(); params.parameter("Source").setValue(originalCoverage); params.parameter(BaseStatisticsOperationJAI.ROI.getName().getCode()).setValue(poly); params.parameter("lowValue").setValue(histogramConfig.getLowValues()); params.parameter("highValue").setValue(histogramConfig.getHighValues()); params.parameter("numBins").setValue(histogramConfig.getNumBins()); try { (javax.media.jai.Histogram) coverage.getProperty( Histogram.GT_SYNTHETIC_PROPERTY_HISTOGRAM);
@Override public ParameterValueGroup getOgcParameters( ParameterValueGroup netcdfParameters) { double lonNorthPole = (Double) netcdfParameters .parameter(NetCDFUtilities.CENTRAL_MERIDIAN) .getValue(); double latNorthPole = (Double) netcdfParameters .parameter(NetCDFUtilities.LATITUDE_OF_ORIGIN) .getValue(); // Rotated pole is ambiguous so we assume an origin in the northern // hemisphere if (latNorthPole >= 90 || latNorthPole <= 0) { throw new RuntimeException( "Unexpected north pole latitude: " + latNorthPole); } double lonOrigin = LatLonPointImpl.lonNormal(lonNorthPole + 180); double latOrigin = 90 - latNorthPole; ParameterValueGroup ogcParameters = netcdfParameters.clone(); ogcParameters .parameter(NetCDFUtilities.CENTRAL_MERIDIAN) .setValue(lonOrigin); ogcParameters .parameter(NetCDFUtilities.LATITUDE_OF_ORIGIN) .setValue(latOrigin); return ogcParameters; }
ReferencedEnvelope coveragesEnvelope = null; for (GridCoverage2D coverage : coverages) { ReferencedEnvelope re = ReferencedEnvelope.reference(coverage.getEnvelope2D()); if (coveragesEnvelope == null) { coveragesEnvelope = re; MathTransform2D mt = coverages.get(0).getGridGeometry().getCRSToGrid2D(); Rectangle rasterSpaceEnvelope; rasterSpaceEnvelope = CRS.transform(mt, targetEnvelope).toRectangle2D().getBounds(); processor.getOperation("Mosaic").getParameters().clone(); param.parameter("sources").setValue(coverages); param.parameter("geometry").setValue(gridGeometry); param.parameter(Mosaic.OUTNODATA_NAME).setValue(background); param.parameter(Mosaic.ALPHA_NAME).setValue(alphas); ((Mosaic) processor.getOperation("Mosaic")).doOperation(param, hints); } catch (Exception e) { throw new RuntimeException("Failed to mosaic the input coverages", e);
/** * Creates a transform from the specified group of parameter values. * * @param parameters The group of parameter values. * @return The created math transform. * @throws ParameterNotFoundException if a required parameter was not found. */ protected MathTransform createMathTransform(final ParameterValueGroup parameters) throws ParameterNotFoundException { // make sure we assume a spherical reference parameters .parameter("semi_minor") .setValue(parameters.parameter("semi_major").getValue()); return new Spherical(parameters); } }