Search in sources :

Example 21 with GeneralParameterValue

use of org.opengis.parameter.GeneralParameterValue in project sis by apache.

the class Proj4Factory method createParameterizedTransform.

/**
 * Creates a transform from a group of parameters. The {@link OperationMethod} name is inferred from
 * the {@linkplain org.opengis.parameter.ParameterDescriptorGroup#getName() parameter group name}.
 * Each parameter value is formatted as a Proj.4 parameter in a definition string.
 *
 * <div class="note"><b>Example:</b>
 * {@preformat java
 *     ParameterValueGroup p = factory.getDefaultParameters("Mercator");
 *     p.parameter("semi_major").setValue(6378137.000);
 *     p.parameter("semi_minor").setValue(6356752.314);
 *     MathTransform mt = factory.createParameterizedTransform(p);
 * }
 *
 * The corresponding Proj.4 definition string is:
 *
 * {@preformat text
 *     +proj=merc +a=6378137.0 +b=6356752.314
 * }
 * </div>
 *
 * @param  parameters  the parameter values.
 * @return the parameterized transform.
 * @throws FactoryException if the object creation failed. This exception is thrown
 *         if some required parameter has not been supplied, or has illegal value.
 *
 * @see #getDefaultParameters(String)
 * @see #getAvailableMethods(Class)
 */
public MathTransform createParameterizedTransform(final ParameterValueGroup parameters) throws FactoryException {
    final String proj = name(parameters.getDescriptor(), Errors.Keys.UnsupportedOperation_1);
    final StringBuilder buffer = new StringBuilder(100).append(PROJ_PARAM).append(proj).append(STANDARD_OPTIONS);
    for (final GeneralParameterValue p : parameters.values()) {
        /*
             * Unconditionally ask the parameter name in order to throw an exception
             * with better error message in case of unrecognized parameter.
             */
        final String name = name(p.getDescriptor(), Errors.Keys.UnexpectedParameter_1);
        if (p instanceof ParameterValue) {
            final Object value = ((ParameterValue) p).getValue();
            if (value != null) {
                buffer.append(" +").append(name).append('=').append(value);
            }
        }
    }
    final String definition = buffer.toString();
    try {
        final PJ pj = unique(new PJ(definition));
        final PJ base = unique(new PJ(pj));
        return new Transform(base, false, pj, false);
    } catch (UnsatisfiedLinkError | NoClassDefFoundError e) {
        throw new UnavailableFactoryException(Proj4.unavailable(e), e);
    }
}
Also used : GeneralParameterValue(org.opengis.parameter.GeneralParameterValue) ParameterValue(org.opengis.parameter.ParameterValue) GeneralParameterValue(org.opengis.parameter.GeneralParameterValue) IdentifiedObject(org.opengis.referencing.IdentifiedObject) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) UnavailableFactoryException(org.apache.sis.referencing.factory.UnavailableFactoryException)

Aggregations

GeneralParameterValue (org.opengis.parameter.GeneralParameterValue)21 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)11 ParameterValue (org.opengis.parameter.ParameterValue)7 GeneralParameterDescriptor (org.opengis.parameter.GeneralParameterDescriptor)5 IdentifiedObject (org.opengis.referencing.IdentifiedObject)4 DependsOnMethod (org.apache.sis.test.DependsOnMethod)3 Test (org.junit.Test)3 InternationalString (org.opengis.util.InternationalString)3 ArrayList (java.util.ArrayList)2 FormattableObject (org.apache.sis.io.wkt.FormattableObject)2 Formatter (org.apache.sis.io.wkt.Formatter)2 DefaultParameterValue (org.apache.sis.parameter.DefaultParameterValue)2 UnavailableFactoryException (org.apache.sis.referencing.factory.UnavailableFactoryException)2 GeoTiffFormat (org.geotools.gce.geotiff.GeoTiffFormat)2 GeoTiffWriteParams (org.geotools.gce.geotiff.GeoTiffWriteParams)2 GeoTiffWriter (org.geotools.gce.geotiff.GeoTiffWriter)2 Identifier (org.opengis.metadata.Identifier)2 ParameterDescriptorGroup (org.opengis.parameter.ParameterDescriptorGroup)2 CoordinateSystem (org.opengis.referencing.cs.CoordinateSystem)2 OperationMethod (org.opengis.referencing.operation.OperationMethod)2