Those changes do not apply anymore to Apache SIS, since this implementation has been replaced by a functional interface
with only the createMathTransform(…)
method.
Command line:
svn diff --extensions "--unified --ignore-space-change --ignore-all-space --ignore-eol-style" -r7306:7857 https://svn.osgeo.org/geotools/trunk/modules/library/referencing/src/main/java/org/geotools/referencing/operation/MathTransformProvider.java
Revision 7306 | Revision 7857 |
---|---|
package org.geotools.referencing.operation; // J2SE dependencies import java.util.Map; import java.util.HashMap; import java.util.Collections; import java.util.Locale; // OpenGIS dependencies import org.opengis.parameter.ParameterValue; import org.opengis.parameter.OperationParameter; import org.opengis.parameter.ParameterValueGroup; import org.opengis.parameter.GeneralParameterValue; import org.opengis.parameter.OperationParameterGroup; import org.opengis.parameter.GeneralOperationParameter; import org.opengis.parameter.ParameterNotFoundException; import org.opengis.parameter.ParameterNotFoundException; import org.opengis.parameter.InvalidParameterNameException; import org.opengis.parameter.InvalidParameterValueException; import org.opengis.metadata.Identifier; import org.opengis.referencing.IdentifiedObject; import org.opengis.referencing.FactoryException; import org.opengis.referencing.operation.MathTransform; import org.opengis.spatialschema.geometry.MismatchedDimensionException; // Geotools dependencies import org.geotools.resources.cts.Resources; import org.geotools.resources.cts.ResourceKeys; /** * An {@linkplain OperationMethod operation method} capable to creates a {@linkplain MathTransform * math transform} from set of {@linkplain GeneralParameterValue parameter values}. |
package org.geotools.referencing.operation; // J2SE dependencies import java.util.HashMap; import java.util.Locale; import java.util.Map; import org.geotools.parameter.Parameters; import org.geotools.resources.cts.ResourceKeys; import org.geotools.resources.cts.Resources; import org.opengis.metadata.Identifier; import org.opengis.parameter.GeneralParameterDescriptor; import org.opengis.parameter.GeneralParameterValue; import org.opengis.parameter.InvalidParameterNameException; import org.opengis.parameter.InvalidParameterValueException; import org.opengis.parameter.ParameterDescriptor; import org.opengis.parameter.ParameterDescriptorGroup; import org.opengis.parameter.ParameterNotFoundException; import org.opengis.parameter.ParameterValue; import org.opengis.parameter.ParameterValueGroup; import org.opengis.referencing.FactoryException; import org.opengis.referencing.IdentifiedObject; import org.opengis.referencing.operation.MathTransform; /** * An {@linkplain OperationMethod operation method} capable to creates a {@linkplain MathTransform * math transform} from set of {@linkplain GeneralParameterValue parameter values}. |
private static final long serialVersionUID = 7530475536803158473L; /** * The {@linkplain #getParameters parameters} represented as a group of descriptors. This * convenience field make it easier to {@linkplain OperationParameterGroup#getParameter(String) * search for named parameters}. */ protected final OperationParameterGroup parameters; /** * Constructs a math transform provider from a set of parameters. The provider * {@linkplain #getIdentifiers identifiers} will be the same than the parameter * ones. |
private static final long serialVersionUID = 7530475536803158473L; /** * Constructs a math transform provider from a set of parameters. The provider * {@linkplain #getIdentifiers identifiers} will be the same than the parameter * ones. |
*/
public MathTransformProvider(final int sourceDimensions,
final int targetDimensions,
final OperationParameterGroup parameters)
{
this(toMap(parameters, null), sourceDimensions, targetDimensions, parameters);
} |
*/
public MathTransformProvider(final int sourceDimensions,
final int targetDimensions,
final ParameterDescriptorGroup parameters)
{
this(toMap(parameters, null), sourceDimensions, targetDimensions, parameters);
} |
/**
* Constructs a math transform provider from a set of properties.
* The properties map is given unchanged to the
* {@linkplain OperationMethod#OperationMethod(Map,int,int,GeneralOperationParameter[])
* super-class constructor}.
*
* @param properties Set of properties. Should contains at least <code>"name"</code>. |
/**
* Constructs a math transform provider from a set of properties.
* The properties map is given unchanged to the
* {@linkplain OperationMethod#OperationMethod(Map,int,int,GeneralParameterDescriptor[])
* super-class constructor}.
*
* @param properties Set of properties. Should contains at least <code>"name"</code>. |
public MathTransformProvider(final Map properties, final int sourceDimensions, final int targetDimensions, final OperationParameterGroup parameters) { super(properties, sourceDimensions, targetDimensions, parameters.getParameters()); this.parameters = parameters; } /** |
public MathTransformProvider(final Map properties, final int sourceDimensions, final int targetDimensions, final ParameterDescriptorGroup parameters) { super(properties, sourceDimensions, targetDimensions, parameters); } /** |
throw new IllegalArgumentException();
}
final Map properties = new HashMap(4);
properties.put("name", (parameters!=null) ? parameters.getName(null) : identifiers[0].getCode());
properties.put("identifiers", identifiers);
return properties;
} |
throw new IllegalArgumentException();
}
final Map properties = new HashMap(4);
properties.put("name", (parameters!=null) ? parameters.getName().toString() : identifiers[0].getCode());
properties.put("identifiers", identifiers);
return properties;
} |
* @param identifiers The operation identifiers. Should contains at least one identifier. * @param parameters The set of parameters, or <code>null</code> or an empty array if none. */ protected static OperationParameterGroup group(final Identifier[] identifiers, final GeneralOperationParameter[] parameters) { return new org.geotools.parameter.OperationParameterGroup(toMap(null, identifiers), parameters); } /** |
* @param identifiers The operation identifiers. Should contains at least one identifier. * @param parameters The set of parameters, or <code>null</code> or an empty array if none. */ protected static ParameterDescriptorGroup group(final Identifier[] identifiers, final GeneralParameterDescriptor[] parameters) { return new org.geotools.parameter.ParameterGroupDescriptor(toMap(null, identifiers), parameters); } /** |
* compares all parameter names against the name declared in {@link #parameters} and * thrown an exception if an unknow parameter is found. It also ensure that all values * are assignable to the * {@linkplain org.geotools.parameter.OperationParameter#getValueClass expected class}, are between the * {@linkplain org.geotools.parameter.OperationParameter#getMinimumValue minimum} and * {@linkplain org.geotools.parameter.OperationParameter#getMaximumValue maximum} values and are one of the * {@linkplain org.geotools.parameter.OperationParameter#getValidValues set of valid values}. * If the value fails any of those tests, then an exception is thrown. * * @param values The parameters values to check. |
* compares all parameter names against the name declared in {@link #parameters} and * thrown an exception if an unknow parameter is found. It also ensure that all values * are assignable to the * {@linkplain org.geotools.parameter.ParameterDescriptor#getValueClass expected class}, are between the * {@linkplain org.geotools.parameter.ParameterDescriptor#getMinimumValue minimum} and * {@linkplain org.geotools.parameter.ParameterDescriptor#getMaximumValue maximum} values and are one of the * {@linkplain org.geotools.parameter.ParameterDescriptor#getValidValues set of valid values}. * If the value fails any of those tests, then an exception is thrown. * * @param values The parameters values to check. |
for (int i=0; i<values.length; i++) { final GeneralParameterValue value = values[i]; if (value instanceof ParameterValueGroup) { ensureValidValues(((ParameterValueGroup) value).getValues()); continue; } final String name; final GeneralOperationParameter userDescriptor = value.getDescriptor(); final Identifier[] identifiers = userDescriptor.getIdentifiers(); if (identifiers!=null && identifiers.length!=0) { name = identifiers[0].getCode(); } else { name = userDescriptor.getName(null); } final OperationParameter descriptor; try { descriptor = parameters.getParameter(name); } catch (ParameterNotFoundException cause) { final InvalidParameterNameException exception = new InvalidParameterNameException(Resources.format( |
for (int i=0; i<values.length; i++) { final GeneralParameterValue value = values[i]; if (value instanceof ParameterValueGroup) { ensureValidValues( Parameters.array((ParameterValueGroup) value)); continue; } final String name; final GeneralParameterDescriptor userDescriptor = value.getDescriptor(); final Identifier[] identifiers = userDescriptor.getIdentifiers(); if (identifiers!=null && identifiers.length!=0) { name = identifiers[0].getCode(); } else { name = userDescriptor.getName().toString(); } final ParameterDescriptor descriptor; try { descriptor = getParameters().getParameter(name); } catch (ParameterNotFoundException cause) { final InvalidParameterNameException exception = new InvalidParameterNameException(Resources.format( |
throw exception;
}
if (value instanceof ParameterValue) {
org.geotools.parameter.ParameterValue.ensureValidValue(descriptor,
((ParameterValue) value).getValue());
}
} |
throw exception;
}
if (value instanceof ParameterValue) {
org.geotools.parameter.Parameter.ensureValidValue(descriptor,
((ParameterValue) value).getValue());
}
} |
* Creates a math transform from the specified set of parameter values. The default * implementation ensures that the specified set of values do not contains any parameter * unknow to {@link #parameters}. It also ensures that all values are assignable to the * {@linkplain org.geotools.parameter.OperationParameter#getValueClass expected class}, are between the * {@linkplain org.geotools.parameter.OperationParameter#getMinimumValue minimum} and * {@linkplain org.geotools.parameter.OperationParameter#getMaximumValue maximum} values and are one of the * {@linkplain org.geotools.parameter.OperationParameter#getValidValues set of valid values}. * Then it wraps wraps the values in a group and invokes * {@link #createMathTransform(ParameterValueGroup)}. * |
* Creates a math transform from the specified set of parameter values. The default * implementation ensures that the specified set of values do not contains any parameter * unknow to {@link #parameters}. It also ensures that all values are assignable to the * {@linkplain org.geotools.parameter.ParameterDescriptor#getValueClass expected class}, are between the * {@linkplain org.geotools.parameter.ParameterDescriptor#getMinimumValue minimum} and * {@linkplain org.geotools.parameter.ParameterDescriptor#getMaximumValue maximum} values and are one of the * {@linkplain org.geotools.parameter.ParameterDescriptor#getValidValues set of valid values}. * Then it wraps wraps the values in a group and invokes * {@link #createMathTransform(ParameterValueGroup)}. * |
ensureValidValues(values); if (values.length == 1) { final GeneralParameterValue value = values[0]; if (parameters.equals(value.getDescriptor())) { if (value instanceof ParameterValueGroup) { return createMathTransform((ParameterValueGroup) value); } } } return createMathTransform(new FallbackParameterValueGroup(parameters, values)); } /** * Creates a math transform from the specified group of parameter values. |
ensureValidValues(values); if (values.length == 1) { final GeneralParameterValue value = values[0]; if (getParameters().equals(value.getDescriptor())) { if (value instanceof ParameterValueGroup) { return createMathTransform((ParameterValueGroup) value); } } } ParameterDescriptorGroup group = getParameters(); System.out.println( group ); ParameterValueGroup params = (ParameterValueGroup) group.createValue(); System.out.println( params ); for( int i=0; i<values.length; i++){ if( values[i] instanceof ParameterValue ){ ParameterValue value = (ParameterValue) values[i]; ParameterDescriptor descriptor = (ParameterDescriptor) value.getDescriptor(); String name = descriptor.getName().toString( null ); if( descriptor.getMaximumOccurs() == 1 && params.parameter( name ) != null ){ params.parameter( name ).setValue( value.getValue() ); } else { params.add( value ); } } else if (values[i] instanceof ParameterValueGroup ){ params.add( (ParameterValueGroup) values[i] ); } } return createMathTransform( params ); // return createMathTransform( new FallbackParameterValueGroup( getParameters(), values) ); } /** * Creates a math transform from the specified group of parameter values. |
* @todo Revisit if a more elaborated test is needed for choosing an identifier.
*/
private static ParameterValue getValue(final ParameterValueGroup group,
final OperationParameter param)
throws ParameterNotFoundException
{
final Identifier[] identifiers = param.getIdentifiers(); |
* @todo Revisit if a more elaborated test is needed for choosing an identifier.
*/
private static ParameterValue getValue(final ParameterValueGroup group,
final ParameterDescriptor param)
throws ParameterNotFoundException
{
final Identifier[] identifiers = param.getIdentifiers(); |
if (identifiers!=null && identifiers.length!=0) { name = identifiers[0].getCode(); } else { name = param.getName(null); } return group.getValue(name); } /** |
if (identifiers!=null && identifiers.length!=0) { name = identifiers[0].getCode(); } else { name = param.getName().toString(); } return group.parameter(name); } /** |
* @throws ParameterNotFoundException if the parameter is not found.
*/
protected static int intValue(final ParameterValueGroup group,
final OperationParameter param)
throws ParameterNotFoundException
{
return getValue(group, param).intValue(); |
* @throws ParameterNotFoundException if the parameter is not found.
*/
protected static int intValue(final ParameterValueGroup group,
final ParameterDescriptor param)
throws ParameterNotFoundException
{
return getValue(group, param).intValue(); |
* for null units).
*/
protected static double doubleValue(final ParameterValueGroup group,
final OperationParameter param)
throws ParameterNotFoundException
{
return getValue(group, param).doubleValue(); |
* for null units).
*/
protected static double doubleValue(final ParameterValueGroup group,
final ParameterDescriptor param)
throws ParameterNotFoundException
{
return getValue(group, param).doubleValue(); |
} /** * Returns the resources key for {@linkplain #getName localized name}. * This method is for internal purpose by Geotools implementation only. */ |
} /** * Returns the parameter value for the specified operation parameter. * This convenience method is used by constructor for initializing * {@linkplain MathTransform math transform} from a set of parameters. * * @param group The parameter value group to search into. * @param param The parameter to look for. * @return The requested parameter value. * @throws ParameterNotFoundException if the parameter is not found. */ protected static String stringValue(final ParameterValueGroup group, final ParameterDescriptor param) throws ParameterNotFoundException { return getValue(group, param).stringValue(); } /** * Returns the resources key for {@linkplain #getName localized name}. * This method is for internal purpose by Geotools implementation only. */ |