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);
}
}
Aggregations