Search in sources :

Example 11 with ParameterValue

use of org.opengis.parameter.ParameterValue 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

ParameterValue (org.opengis.parameter.ParameterValue)11 GeneralParameterValue (org.opengis.parameter.GeneralParameterValue)9 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)8 GeneralParameterDescriptor (org.opengis.parameter.GeneralParameterDescriptor)3 DefaultParameterValue (org.apache.sis.parameter.DefaultParameterValue)2 UnavailableFactoryException (org.apache.sis.referencing.factory.UnavailableFactoryException)2 Matrix3 (org.apache.sis.referencing.operation.matrix.Matrix3)2 DependsOnMethod (org.apache.sis.test.DependsOnMethod)2 Test (org.junit.Test)2 IdentifiedObject (org.opengis.referencing.IdentifiedObject)2 Matrix (org.opengis.referencing.operation.Matrix)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Unit (javax.measure.Unit)1 Angle (javax.measure.quantity.Angle)1 CC_OperationParameterGroupTest (org.apache.sis.internal.jaxb.referencing.CC_OperationParameterGroupTest)1 FormattableObject (org.apache.sis.io.wkt.FormattableObject)1 DefaultParameterDescriptorGroup (org.apache.sis.parameter.DefaultParameterDescriptorGroup)1 DefaultParameterValueGroup (org.apache.sis.parameter.DefaultParameterValueGroup)1 BursaWolfParameters (org.apache.sis.referencing.datum.BursaWolfParameters)1