Search in sources :

Example 1 with UnsupportedImplementationException

use of org.apache.sis.util.UnsupportedImplementationException in project sis by apache.

the class UnitDimension method combine.

/**
 * Returns the product or the quotient of this dimension with the specified one.
 *
 * @param  other   the dimension by which to multiply or divide this dimension.
 * @param  divide  {@code false} for a multiplication, {@code true} for a division.
 * @return the product or division of this dimension by the given dimension.
 */
private UnitDimension combine(final Dimension other, final boolean divide) {
    final Map<UnitDimension, Fraction> product = new LinkedHashMap<>(components);
    for (final Map.Entry<? extends Dimension, Fraction> entry : getBaseDimensions(other).entrySet()) {
        final Dimension dim = entry.getKey();
        Fraction p = entry.getValue();
        if (divide) {
            p = p.negate();
        }
        if (dim instanceof UnitDimension) {
            product.merge((UnitDimension) dim, p, (sum, toAdd) -> {
                sum = sum.add(toAdd);
                return (sum.numerator != 0) ? sum : null;
            });
        } else if (p.numerator != 0) {
            throw new UnsupportedImplementationException(Errors.format(Errors.Keys.UnsupportedImplementation_1, dim.getClass()));
        }
    }
    return create(product);
}
Also used : Fraction(org.apache.sis.math.Fraction) Dimension(javax.measure.Dimension) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) UnsupportedImplementationException(org.apache.sis.util.UnsupportedImplementationException)

Example 2 with UnsupportedImplementationException

use of org.apache.sis.util.UnsupportedImplementationException in project sis by apache.

the class DefaultPassThroughOperation method getModifiedCoordinates.

/**
 * Returns the ordered sequence of indices in a source coordinate tuple of the coordinates
 * affected by this pass-through operation.
 *
 * @return zero-based indices of the modified source coordinates.
 *
 * @see PassThroughTransform#getModifiedCoordinates()
 */
@Override
public int[] getModifiedCoordinates() {
    final MathTransform transform = super.getMathTransform();
    if (transform instanceof PassThroughTransform) {
        return ((PassThroughTransform) transform).getModifiedCoordinates();
    } else {
        /*
             * Should not happen with objects created by public methods since the constructor created the transform
             * itself. However may happen with operations parsed from GML. As a fallback, search in the components
             * of CompoundCRS. This is not a universal fallback, but work for the most straightforward cases.
             */
        final CoordinateReferenceSystem sourceCRS = super.getSourceCRS();
        if (sourceCRS instanceof CompoundCRS) {
            int firstAffectedOrdinate = 0;
            final CoordinateReferenceSystem search = operation.getSourceCRS();
            for (final CoordinateReferenceSystem c : ((CompoundCRS) sourceCRS).getComponents()) {
                final int dim = ReferencingUtilities.getDimension(c);
                if (c == search) {
                    final int[] indices = new int[dim];
                    for (int i = 0; i < dim; i++) {
                        indices[i] = firstAffectedOrdinate + i;
                    }
                    return indices;
                }
                firstAffectedOrdinate += dim;
            }
        }
        throw new UnsupportedImplementationException(transform.getClass());
    }
}
Also used : MathTransform(org.opengis.referencing.operation.MathTransform) CompoundCRS(org.opengis.referencing.crs.CompoundCRS) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) PassThroughTransform(org.apache.sis.referencing.operation.transform.PassThroughTransform) UnsupportedImplementationException(org.apache.sis.util.UnsupportedImplementationException)

Aggregations

UnsupportedImplementationException (org.apache.sis.util.UnsupportedImplementationException)2 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Dimension (javax.measure.Dimension)1 Fraction (org.apache.sis.math.Fraction)1 PassThroughTransform (org.apache.sis.referencing.operation.transform.PassThroughTransform)1 CompoundCRS (org.opengis.referencing.crs.CompoundCRS)1 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)1 MathTransform (org.opengis.referencing.operation.MathTransform)1