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; }
/** * 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); } }
int[] getSelectedBandIndexes(GeneralParameterValue[] parameters) { // if the delegate cannot do band selection, don't bother if (delegate.getFormat() == null || !delegate.getFormat() .getReadParameters() .getDescriptor() .descriptors() .contains(AbstractGridFormat.BANDS)) { return null; } // lookup the bands if possible if (parameters != null) { for (int i = 0; i < parameters.length; i++) { final ParameterValue param = (ParameterValue) parameters[i]; if (AbstractGridFormat.BANDS.getName().equals(param.getDescriptor().getName())) { int[] bandIndicesParam = (int[]) param.getValue(); return bandIndicesParam; } } } return null; }
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); for (int i = 0; i < parameters.length; i++) { final ParameterValue param = (ParameterValue) parameters[i]; if (AbstractGridFormat.BANDS.getName().equals(param.getDescriptor().getName())) { int[] bandIndicesParam = (int[]) param.getValue(); if (bandIndicesParam != null) { selectedBandIndices = new ArrayList<Integer>(); 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 {
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 {
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);
(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);
parameter = dDescriptor.createValue(); assertEquals("name", "Test", dDescriptor.getName().getCode()); assertEquals("unit", SI.METRE, dDescriptor.getUnit()); assertEquals("class", Double.class, dDescriptor.getValueClass()); assertEquals("defaultValue", 12.0, dDescriptor.getDefaultValue().doubleValue(), 0.0); assertEquals("minimum", 4.0, dDescriptor.getMinimumValue()); assertEquals("maximum", 20.0, dDescriptor.getMaximumValue()); assertEquals("value", 12, parameter.intValue()); assertEquals("unit", SI.METRE, parameter.getUnit()); for (int i = 4; i <= 20; i++) { parameter.setValue(i); assertEquals("value", Double.valueOf(i), parameter.getValue()); assertEquals("unit", SI.METRE, parameter.getUnit()); assertEquals("value", i, parameter.doubleValue(SI.METRE), 0); parameter.setValue(3.0); fail("setValue(< min)"); } catch (InvalidParameterValueException exception) { parameter.setValue("12"); fail("setValue(Sring)"); } catch (InvalidParameterValueException exception) { parameter.setValue(i, MetricPrefix.CENTI(SI.METRE)); assertEquals("value", Double.valueOf(i), parameter.getValue()); assertEquals("unit", MetricPrefix.CENTI(SI.METRE), parameter.getUnit()); assertEquals("value", i / 100, parameter.doubleValue(SI.METRE), 0);
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 { 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); } else if (v instanceof double[]) { target.setValue((double[]) v, unit); } else { throw new InvalidParameterValueException(
/** * 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()); } } }
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);
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); } } };
protected void handleJAIEXTParams( ParameterBlockJAI parameters, ParameterValueGroup parameters2) { if (JAIExt.isJAIExtOperation(STATS)) { GridCoverage2D source = (GridCoverage2D) parameters2.parameter("source0").getValue(); // Handle ROI and NoData handleROINoDataInternal(parameters, source, STATS, 2, 3); // Setting the Statistic operation parameters.set(new StatsType[] {StatsType.EXTREMA}, 6); // Check on the band numnber int b = source.getRenderedImage().getSampleModel().getNumBands(); int[] indexes = new int[b]; for (int i = 0; i < b; i++) { indexes[i] = i; } parameters.set(indexes, 5); } } }
final Map<String, ?> dummyName = Collections.singletonMap("name", "Test"); for (final OperationMethod method : methods) { final String classification = method.getName().getCode(); final ParameterValueGroup param = mtFactory.getDefaultParameters(classification); try { param.parameter("semi_major").setValue(6377563.396); param.parameter("semi_minor").setValue(6356256.909237285); } catch (IllegalArgumentException e) { assertEquals( classification, ((MapProjection) mt).getParameterDescriptors().getName().getCode()); assertSame(mt, conversion.getMathTransform()); final OperationMethod projMethod = conversion.getMethod(); assertEquals(classification, projMethod.getName().getCode());