Search in sources :

Example 6 with GeneralDirectPosition

use of org.apache.sis.geometry.GeneralDirectPosition in project sis by apache.

the class Transformer method transform.

/**
 * Transforms the given points.
 */
final double[][] transform(final double[][] points) {
    final MathTransform mt = operation.getMathTransform();
    final GeneralDirectPosition sourcePt = new GeneralDirectPosition(mt.getSourceDimensions());
    final GeneralDirectPosition targetPt = new GeneralDirectPosition(mt.getTargetDimensions());
    final double[][] result = new double[points.length][];
    for (int j = 0; j < points.length; j++) {
        final double[] coords = points[j];
        if (coords != null) {
            // Paranoiac check.
            for (int i = sourcePt.ordinates.length; --i >= 0; ) {
                sourcePt.ordinates[i] = (i < coords.length) ? coords[i] : 0;
            }
            try {
                result[j] = mt.transform(sourcePt, targetPt).getCoordinate();
            } catch (TransformException exception) {
                /*
                     * The coordinate operation failed for this particular point. But maybe it will
                     * succeed for an other point. Set the values to NaN and continue the loop. Note:
                     * we will report the failure for logging purpose, but only the first one since
                     * all subsequent failures are likely to be the same one.
                     */
                final double[] pad = new double[mt.getTargetDimensions()];
                Arrays.fill(pad, Double.NaN);
                result[j] = pad;
                if (warning == null) {
                    warning = exception;
                }
            }
        }
    }
    return result;
}
Also used : GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) MathTransform(org.opengis.referencing.operation.MathTransform) TransformException(org.opengis.referencing.operation.TransformException)

Example 7 with GeneralDirectPosition

use of org.apache.sis.geometry.GeneralDirectPosition in project sis by apache.

the class ReferencingAssert method assertDisjoint.

/**
 * Tests if the given {@code e1} envelope is disjoint with the given {@code e2} envelope.
 * This method will also verify class consistency by invoking the {@code contains} method,
 * and by interchanging the arguments.
 *
 * @param e1  the first envelope to test.
 * @param e2  the second envelope to test.
 */
public static void assertDisjoint(final AbstractEnvelope e1, final Envelope e2) {
    assertFalse("e1.intersects(e2)", e1.intersects(e2, false));
    assertFalse("e1.intersects(e2)", e1.intersects(e2, true));
    assertFalse("e1.contains(e2)", e1.contains(e2, false));
    assertFalse("e1.contains(e2)", e1.contains(e2, true));
    if (e2 instanceof AbstractEnvelope) {
        final AbstractEnvelope ae = (AbstractEnvelope) e2;
        assertFalse("e2.intersects(e1)", ae.intersects(e1, false));
        assertFalse("e2.intersects(e1)", ae.intersects(e1, true));
        assertFalse("e2.contains(e1)", ae.contains(e1, false));
        assertFalse("e2.contains(e1)", ae.contains(e1, true));
    }
    final int dimension = e1.getDimension();
    final int numCases = toIntExact(round(pow(3, dimension)));
    final GeneralDirectPosition pos = new GeneralDirectPosition(dimension);
    for (int index = 0; index < numCases; index++) {
        int n = index;
        for (int i = 0; i < dimension; i++) {
            final double ordinate;
            switch(n % 3) {
                case 0:
                    ordinate = e2.getMinimum(i);
                    break;
                case 1:
                    ordinate = e2.getMedian(i);
                    break;
                case 2:
                    ordinate = e2.getMaximum(i);
                    break;
                default:
                    throw new AssertionError(i);
            }
            pos.setOrdinate(i, ordinate);
            n /= 3;
        }
        // Opportunist check of this assert method.
        assertEquals(0, n);
        assertFalse("e1.contains(" + pos + ')', e1.contains(pos));
    }
}
Also used : GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) AbstractEnvelope(org.apache.sis.geometry.AbstractEnvelope)

Aggregations

GeneralDirectPosition (org.apache.sis.geometry.GeneralDirectPosition)7 AbstractEnvelope (org.apache.sis.geometry.AbstractEnvelope)2 DirectPosition2D (org.apache.sis.geometry.DirectPosition2D)1 DirectPosition (org.opengis.geometry.DirectPosition)1 Envelope (org.opengis.geometry.Envelope)1 MathTransform (org.opengis.referencing.operation.MathTransform)1 TransformException (org.opengis.referencing.operation.TransformException)1