/** * Copies all aliases and all identifiers except EPSG, but using the alias specified by the given authority * as the primary name. The old primary name (usually the EPSG name) is discarded. * * <p>This is a convenience method for defining the parameters of an ESRI-specific (or any other authority) * projection using the EPSG parameters as template.</p> * * @param template the parameter from which to copy the names. * @param authority the authority to use for the primary name. * @param builder an initially clean builder where to add the names. * @return the given {@code builder}, for method call chaining. * * @since 0.8 */ static ParameterBuilder alternativeAuthority(final ParameterDescriptor<Double> template, final Citation authority, final ParameterBuilder builder) { return copyAliases(template, authority, null, null, builder.addName(sameNameAs(authority, template))); }
/** * Creates a three-dimensional map projections for the given parameters. * The ellipsoidal height is assumed to be in the third dimension. */ @Override public MathTransform createMathTransform(MathTransformFactory factory, ParameterValueGroup parameters) throws FactoryException { return factory.createPassThroughTransform(0, redimensioned.createMathTransform(factory, parameters), 1); } }
/** * Notifies {@code DefaultMathTransformFactory} that map projections require * values for the {@code "semi_major"} and {@code "semi_minor"} parameters. * * @return 1, meaning that the operation requires a source ellipsoid. */ @Override public int getEllipsoidsMask() { return redimensioned.getEllipsoidsMask(); }
/** * Same as {@link #getAndStore(ParameterDescriptor)}, but returns the given default value if the parameter * is not specified. This method shall be used only for parameters having a default value more complex than * what we can represent in {@link ParameterDescriptor#getDefaultValue()}. */ final double getAndStore(final ParameterDescriptor<Double> descriptor, final double defaultValue) { final Double value = parameters.getValue(descriptor); // Apply a unit conversion if needed. if (value == null) { return defaultValue; } MapProjection.validate(descriptor, value); context.getOrCreate(descriptor).setValue(value); return value; }
/** * Constructs a three-dimensional map projection for the given two-dimensional projection. */ MapProjection3D(final MapProjection proj) { super(3, 3, proj.getParameters()); redimensioned = proj; }
/** * Returns the operation type for this map projection. */ @Override public Class<? extends Projection> getOperationType() { return redimensioned.getOperationType(); }
/** * Creates a map projection from the specified group of parameter values. * * @param factory the factory to use for creating and concatenating the (de)normalization transforms. * @param parameters the group of parameter values. * @return the map projection created from the given parameter values. * @throws ParameterNotFoundException if a required parameter was not found. * @throws FactoryException if the map projection can not be created. */ @Override public final MathTransform createMathTransform(final MathTransformFactory factory, final ParameterValueGroup parameters) throws ParameterNotFoundException, FactoryException { return createProjection(Parameters.castOrWrap(parameters)).createMapProjection(factory); }
/** * Returns the same parameter than the given one, except that the alias of the ESRI authority * is promoted as the primary name. The old primary name and identifiers (which are usually the * EPSG ones) are discarded. * * @param template the parameter from which to copy the names and identifiers. * @param builder an initially clean builder where to add the names. * @return the given {@code builder}, for method call chaining. */ @SuppressWarnings("unchecked") static ParameterDescriptor<Double> asPrimary(final ParameterDescriptor<Double> template, final ParameterBuilder builder) { return MapProjection.alternativeAuthority(template, Citations.ESRI, builder).createBounded((MeasurementRange<Double>) ((DefaultParameterDescriptor<Double>) template).getValueDomain(), template.getDefaultValue()); } }
final OperationMethod proj3D = ((MapProjection) method).redimension(sourceDimensions ^ 1, targetDimensions ^ 1); assertNotSame("redimension(3,3) should return a new method.", method, proj3D); assertSame("redimension(2,2) should give back the original method.", method, ((DefaultOperationMethod) proj3D).redimension(sourceDimensions, targetDimensions)); assertSame("Value of redimension(3,3) should have been cached.", proj3D, ((MapProjection) method).redimension(sourceDimensions ^ 1, targetDimensions ^ 1)); } else try { ((DefaultOperationMethod) method).redimension(sourceDimensions ^ 1, targetDimensions ^ 1);
/** * Same as {@link #getAndStore(ParameterDescriptor)}, but returns the given default value if the parameter * is not specified. This method shall be used only for parameters having a default value more complex than * what we can represent in {@link ParameterDescriptor#getDefaultValue()}. */ final double getAndStore(final ParameterDescriptor<Double> descriptor, final double defaultValue) { final Double value = parameters.getValue(descriptor); // Apply a unit conversion if needed. if (value == null) { return defaultValue; } MapProjection.validate(descriptor, value); context.getOrCreate(descriptor).setValue(value); return value; }
/** * Constructs a three-dimensional map projection for the given two-dimensional projection. */ MapProjection3D(final MapProjection proj) { super(3, 3, proj.getParameters()); redimensioned = proj; }
/** * Returns the operation type for this map projection. */ @Override public Class<? extends Projection> getOperationType() { return redimensioned.getOperationType(); }
/** * Creates a map projection from the specified group of parameter values. * * @param factory the factory to use for creating and concatenating the (de)normalization transforms. * @param parameters the group of parameter values. * @return the map projection created from the given parameter values. * @throws ParameterNotFoundException if a required parameter was not found. * @throws FactoryException if the map projection can not be created. */ @Override public final MathTransform createMathTransform(final MathTransformFactory factory, final ParameterValueGroup parameters) throws ParameterNotFoundException, FactoryException { return createProjection(Parameters.castOrWrap(parameters)).createMapProjection(factory); }
/** * Gets a parameter value identified by the given descriptor and stores it in the {@link #context}. * A "contextual parameter" is a parameter that apply to the normalize → {@code this} → denormalize * chain as a whole. It does not really apply to a {@code NormalizedProjection} instance taken alone. * * <p>This method performs the following actions:</p> * <ul> * <li>Convert the value to the units specified by the descriptor.</li> * <li>Ensure that the value is contained in the range specified by the descriptor.</li> * <li>Store the value only if different than the default value.</li> * </ul> */ final double getAndStore(final ParameterDescriptor<? extends Number> descriptor) { if (descriptor == null) { return 0; // Default value for all parameters except scale factor. } /* * Get the parameter value, or its default value if the parameter was not set. That default value * (which is specified by the descriptor of the user-supplied parameters) is not necessarily the * same than the default value of the map projection implementation (which is specified by the * descriptor given in argument to this method). */ final double value = parameters.doubleValue(descriptor); // Apply a unit conversion if needed. final Number defaultValue = descriptor.getDefaultValue(); if (defaultValue == null || !defaultValue.equals(value)) { MapProjection.validate(descriptor, value); context.getOrCreate(descriptor).setValue(value); } return value; }
/** * Copies all aliases and all identifiers except EPSG, but using the alias specified by the given authority * as the primary name. The old primary name (usually the EPSG name) is discarded. * * <p>This is a convenience method for defining the parameters of an ESRI-specific (or any other authority) * projection using the EPSG parameters as template.</p> * * @param template the parameter from which to copy the names. * @param authority the authority to use for the primary name. * @param builder an initially clean builder where to add the names. * @return the given {@code builder}, for method call chaining. * * @since 0.8 */ static ParameterBuilder alternativeAuthority(final ParameterDescriptor<Double> template, final Citation authority, final ParameterBuilder builder) { return copyAliases(template, authority, null, null, builder.addName(sameNameAs(authority, template))); }
/** * Notifies {@code DefaultMathTransformFactory} that map projections require * values for the {@code "semi_major"} and {@code "semi_minor"} parameters. * * @return 1, meaning that the operation requires a source ellipsoid. */ @Override public int getEllipsoidsMask() { return redimensioned.getEllipsoidsMask(); }
/** * Creates a three-dimensional map projections for the given parameters. * The ellipsoidal height is assumed to be in the third dimension. */ @Override public MathTransform createMathTransform(MathTransformFactory factory, ParameterValueGroup parameters) throws FactoryException { return factory.createPassThroughTransform(0, redimensioned.createMathTransform(factory, parameters), 1); } }
/** * Gets a parameter value identified by the given descriptor and stores it in the {@link #context}. * A "contextual parameter" is a parameter that apply to the normalize → {@code this} → denormalize * chain as a whole. It does not really apply to a {@code NormalizedProjection} instance taken alone. * * <p>This method performs the following actions:</p> * <ul> * <li>Convert the value to the units specified by the descriptor.</li> * <li>Ensure that the value is contained in the range specified by the descriptor.</li> * <li>Store the value only if different than the default value.</li> * </ul> */ final double getAndStore(final ParameterDescriptor<? extends Number> descriptor) { if (descriptor == null) { return 0; // Default value for most parameters except scale factor. } /* * Get the parameter value, or its default value if the parameter was not set. That default value * (which is specified by the descriptor of the user-supplied parameters) is not necessarily the * same than the default value of the map projection implementation (which is specified by the * descriptor given in argument to this method). */ final double value = parameters.doubleValue(descriptor); // Apply a unit conversion if needed. final Number defaultValue = descriptor.getDefaultValue(); if (defaultValue == null || !defaultValue.equals(value)) { MapProjection.validate(descriptor, value); context.getOrCreate(descriptor).setValue(value); } return value; }
/** * Copies name, aliases and identifiers of the given {@code template}, except the alias and identifiers of the * given authority which are replaced by the alias and identifiers of the same authority in {@code replacement}. * * @param template the parameter from which to copy names and identifiers. * @param toRename authority of the alias to rename. * @param replacement the parameter from which to get the new name for the alias to rename. * @param builder an initially clean builder where to add the names and identifiers. * @return the given {@code builder}, for method call chaining. * * @since 0.8 */ static ParameterBuilder renameAlias(final ParameterDescriptor<Double> template, final Citation toRename, final ParameterDescriptor<Double> replacement, final ParameterBuilder builder) { return copyAliases(template, toRename, sameNameAs(toRename, replacement), (ReferenceIdentifier) IdentifiedObjects.getIdentifier(replacement, toRename), builder.addName(template.getName())); }
/** * Gets a parameter value identified by the given descriptor and stores it only if different than zero. * This method performs the same work than {@code Initializer.getAndStore(ParameterDescriptor)} in the * {@link org.apache.sis.referencing.operation.projection} package. * * @param source the parameters from which to read the value. * @param target where to store the parameter values. * @param descriptor the descriptor that specify the parameter names and desired units. * @return the parameter value in the units given by the descriptor. * @throws IllegalArgumentException if the given value is out of bounds. */ private static double getAndStore(final Parameters source, final ParameterValueGroup target, final ParameterDescriptor<Double> descriptor) throws IllegalArgumentException { final double value = source.doubleValue(descriptor); // Apply a unit conversion if needed. MapProjection.validate(descriptor, value); // Unconditional validation for all parameters. if (value != 0) { // All default values in this class are zero. target.parameter(descriptor.getName().getCode()).setValue(value); } return value; }