/** * 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); } }
/** Replace or add the provided parameter in the read parameters */ public static <T> GeneralParameterValue[] replaceParameter( GeneralParameterValue[] readParameters, Object value, ParameterDescriptor<T> pd) { // scan all the params looking for the one we want to add for (GeneralParameterValue gpv : readParameters) { // in case of match of any alias add a param value to the lot if (gpv.getDescriptor().getName().equals(pd.getName())) { ((ParameterValue) gpv).setValue(value); // leave return readParameters; } } // add it to the array // add to the list GeneralParameterValue[] readParametersClone = new GeneralParameterValue[readParameters.length + 1]; System.arraycopy(readParameters, 0, readParametersClone, 0, readParameters.length); final ParameterValue<T> pv = pd.createValue(); pv.setValue(value); readParametersClone[readParameters.length] = pv; return readParametersClone; } }
/** * Utility methods for find param by key * * @param params DOCUMENT ME! * @param key DOCUMENT ME! * @return DOCUMENT ME! */ public static ParameterValue find(ParameterValueGroup params, String key) { List list = params.values(); Iterator it = list.iterator(); ParameterDescriptor descr; ParameterValue val; while (it.hasNext()) { val = (ParameterValue) it.next(); descr = (ParameterDescriptor) val.getDescriptor(); if (key.equalsIgnoreCase(descr.getName().toString())) { return val; } } return null; }
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; }
if (aliases.contains(pd.getName().getCode())) { final ParameterValue pv = (ParameterValue) pd.createValue(); pv.setValue(value);
final String readGeometryKey = AbstractGridFormat.READ_GRIDGEOMETRY2D.getName().toString(); if ((params != null) && (params.values().size() > 0)) { final List<GeneralParameterValue> elements = params.values(); for (GeneralParameterValue elem : elements) { final ParameterValue<?> val = (ParameterValue<?>) elem; final ParameterDescriptor<?> descr = val.getDescriptor(); final String _key = descr.getName().toString(); new DefaultParameterDescriptor(_key, descr.getValueClass(), null, value) .createValue());
/** Helper method that checks if the delegate reader support bands selection. */ private boolean checkIfDelegateReaderSupportsBands() { List<GeneralParameterDescriptor> parameters = delegate.getFormat().getReadParameters().getDescriptor().descriptors(); for (GeneralParameterDescriptor parameterDescriptor : parameters) { if (parameterDescriptor.getName().equals(AbstractGridFormat.BANDS.getName())) { return true; } } return false; }
@Test public void testGetOutputTransparentColor() { ParameterDescriptor<Color> pdescriptor = ImageMosaicFormat.OUTPUT_TRANSPARENT_COLOR; ParameterValue<Color> pvalue = pdescriptor.createValue(); String key = pdescriptor.getName().getCode(); Map values = Collections.singletonMap(key, "0xFFFFFF"); Object value = CoverageUtils.getCvParamValue(key, pvalue, values); assertTrue(value instanceof Color); assertEquals(Color.WHITE, value); }
@Override public ParameterValueGroup getReadParameters() { HashMap<String, String> info = new HashMap<String, String>(); info.put("name", getName()); info.put("description", getDescription()); info.put("vendor", getVendor()); info.put("docURL", getDocURL()); info.put("version", getVersion()); List<GeneralParameterDescriptor> delegateFormatParams = new ArrayList<GeneralParameterDescriptor>(); delegateFormatParams.addAll( delegateFormat.getReadParameters().getDescriptor().descriptors()); // add bands parameter descriptor only if the delegate reader doesn't have it // already if (!checkIfDelegateReaderSupportsBands()) { delegateFormatParams.add(AbstractGridFormat.BANDS); } return new ParameterGroup( new DefaultParameterDescriptorGroup( info, delegateFormatParams.toArray( new GeneralParameterDescriptor [delegateFormatParams.size()]))); }
/** Helper for read method. */ private static List<?> extractValue(GeneralParameterValue param) { if (param instanceof ParameterValue<?>) { final Object paramVal = ((ParameterValue<?>) param).getValue(); if (paramVal != null) { if (paramVal instanceof List) { final List<?> list = (List<?>) paramVal; return list; } else { throw new UnsupportedOperationException( "Custom dimension value must be a list"); } } } throw new UnsupportedOperationException("Custom dimension value must be a list"); } }
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; }
final String readGeometryKey = AbstractGridFormat.READ_GRIDGEOMETRY2D.getName().toString(); if ((params != null) && (params.values().size() > 0)) { final List list = params.values(); final Iterator it = list.iterator(); while (it.hasNext()) { final ParameterDescriptor descr = (ParameterDescriptor) val.getDescriptor(); final String _key = descr.getName().toString(); Object value = val.getValue(); String text = "";
@Test public void testMaxTiles() { ParameterDescriptor<Integer> pdescriptor = ImageMosaicFormat.MAX_ALLOWED_TILES; ParameterValue<Integer> pvalue = pdescriptor.createValue(); String key = pdescriptor.getName().getCode(); Map values = Collections.singletonMap(key, "1"); Object value = CoverageUtils.getCvParamValue(key, pvalue, values); assertTrue(value instanceof Integer); assertEquals(Integer.valueOf(1), value); } }
/** * <strong>Reprojecting</strong><br> * The new grid geometry can have a different coordinate reference system than the underlying * grid geometry. For example, a grid coverage can be reprojected from a geodetic coordinate * reference system to Universal Transverse Mercator CRS. * * @param coverage GridCoverage2D * @param sourceCRS CoordinateReferenceSystem * @param targetCRS CoordinateReferenceSystem * @return GridCoverage2D * @throws WcsException */ public static GridCoverage2D resample( final GridCoverage2D coverage, final CoordinateReferenceSystem sourceCRS, final CoordinateReferenceSystem targetCRS, final GridGeometry2D gridGeometry, final Interpolation interpolation) throws WcsException { final ParameterValueGroup param = (ParameterValueGroup) PROCESSOR.getOperation("Resample").getParameters(); param.parameter("Source").setValue(coverage); param.parameter("CoordinateReferenceSystem").setValue(targetCRS); param.parameter("GridGeometry").setValue(gridGeometry); param.parameter("InterpolationType").setValue(interpolation); return (GridCoverage2D) ((Resample) PROCESSOR.getOperation("Resample")).doOperation(param, hints); }
final String readGeometryKey = AbstractGridFormat.READ_GRIDGEOMETRY2D.getName().toString(); if ((params != null) && (params.values().size() > 0)) { List list = params.values(); final Iterator it = list.iterator(); while (it.hasNext()) { final ParameterDescriptor descr = (ParameterDescriptor) val.getDescriptor(); final String _key = descr.getName().toString(); continue; final Object value = val.getValue();
public static Coverage bandSelect(final GridCoverage coverage, final int[] bands) { Coverage bandSelectedCoverage; if ((bands != null) && (bands.length > 0)) { /* Operations.DEFAULT.selectSampleDimension(coverage, bands) */ final ParameterValueGroup param = (ParameterValueGroup) PROCESSOR.getOperation("SelectSampleDimension").getParameters(); param.parameter("Source").setValue(coverage); param.parameter("SampleDimensions").setValue(bands); // param.parameter("VisibleSampleDimension").setValue(bands); bandSelectedCoverage = ((SelectSampleDimension) PROCESSOR.getOperation("SelectSampleDimension")) .doOperation(param, hints); } else { bandSelectedCoverage = coverage; } return bandSelectedCoverage; }
/** * Crops the coverage to the specified bounds * * @param coverage * @param bounds */ public static GridCoverage2D crop(final GridCoverage2D coverage, final Envelope bounds) { // checks final ReferencedEnvelope cropBounds = new ReferencedEnvelope(bounds); final ReferencedEnvelope coverageBounds = new ReferencedEnvelope(coverage.getEnvelope()); if (cropBounds.contains((org.locationtech.jts.geom.Envelope) coverageBounds)) { return coverage; } Polygon polygon = JTS.toGeometry(cropBounds); Geometry roi = polygon.getFactory().createMultiPolygon(new Polygon[] {polygon}); // perform the crops final ParameterValueGroup param = PROCESSOR.getOperation("CoverageCrop").getParameters(); param.parameter("Source").setValue(coverage); param.parameter("Envelope").setValue(bounds); param.parameter("ROI").setValue(roi); return (GridCoverage2D) PROCESSOR.doOperation(param); }