Search in sources :

Example 6 with Envelope

use of org.opengis.geometry.Envelope in project sis by apache.

the class SpecializableTransformTest method create.

/**
 * Creates a transform to test.
 *
 * @throws IllegalArgumentException if {@link SpecializableTransform} constructor rejects a parameter.
 */
private static SpecializableTransform create(final boolean is2D) {
    final Map<Envelope, MathTransform> specializations = new HashMap<>(4);
    assertNull(specializations.put(new Envelope2D(null, -5, -4, 10, 7), translation(0.1)));
    assertNull(specializations.put(new Envelope2D(null, -3, -1, 5, 2), translation(0.2)));
    final MathTransform global = translation(0);
    if (is2D) {
        return new SpecializableTransform2D(global, specializations);
    }
    return new SpecializableTransform(global, specializations);
}
Also used : MathTransform(org.opengis.referencing.operation.MathTransform) HashMap(java.util.HashMap) Envelope(org.opengis.geometry.Envelope) Envelope2D(org.apache.sis.geometry.Envelope2D)

Example 7 with Envelope

use of org.opengis.geometry.Envelope in project sis by apache.

the class AbstractEnvelopeTest method testCrossingAntiMeridianTwice.

/**
 * Tests a the anti-meridian case with a larger empty space
 * on the left side.
 *
 * {@preformat text
 *      ───┐    ┌─────────              ───┐      ┌─────
 *         │    │  ┌────┐       or      ───┼──┐   │  ┌──
 *         │    │  └────┘               ───┼──┘   │  └──
 *      ───┘    └─────────              ───┘      └─────
 * }
 */
@Test
public void testCrossingAntiMeridianTwice() {
    final DirectPosition2D inside = new DirectPosition2D(18, 32);
    final DirectPosition2D outside = new DirectPosition2D(3, 32);
    final Envelope2D contained = (Envelope2D) create(RECTANGLE, 14, 16, 35, 40);
    final Envelope2D intersect = (Envelope2D) create(RECTANGLE, -2, 16, 35, 40);
    final Envelope2D disjoint = (Envelope2D) create(RECTANGLE, -2, 10, 35, 40);
    final Envelope2D spanning = (Envelope2D) create(RECTANGLE, 16, -8, 35, 40);
    for (int type = 0; type < LAST; type++) {
        final String label = "Type " + type;
        final Envelope envelope = create(type, 12, -364, 30, 50);
        final DirectPosition lower = envelope.getLowerCorner();
        final DirectPosition upper = envelope.getUpperCorner();
        assertEquals(label, 30, envelope.getMinimum(1), STRICT);
        assertEquals(label, 50, envelope.getMaximum(1), STRICT);
        assertEquals(label, 40, envelope.getMedian(1), STRICT);
        assertEquals(label, 20, envelope.getSpan(1), STRICT);
        assertEquals(label, 12, lower.getOrdinate(0), STRICT);
        assertEquals(label, -180, envelope.getMinimum(0), STRICT);
        assertEquals(label, -364, upper.getOrdinate(0), STRICT);
        assertEquals(label, +180, envelope.getMaximum(0), STRICT);
        // Note the alternance with the previous test methods.
        assertEquals(label, 4, envelope.getMedian(0), STRICT);
        // testCrossingAntiMeridian() + 360°.
        assertEquals(label, NaN, envelope.getSpan(0), STRICT);
        if (envelope instanceof AbstractEnvelope) {
            final AbstractEnvelope ext = (AbstractEnvelope) envelope;
            assertTrue(label, ext.contains(inside));
            assertFalse(label, ext.contains(outside));
            assertFalse(label, ext.contains(intersect, false));
            assertTrue(label, ext.intersects(intersect, false));
            assertFalse(label, ext.contains(spanning, false));
            assertTrue(label, ext.intersects(spanning, false));
            assertDisjoint(ext, disjoint);
            assertContains(ext, contained);
            break;
        }
        if (envelope instanceof Rectangle2D) {
            final Rectangle2D ext = (Rectangle2D) envelope;
            assertTrue(label, ext.contains(inside));
            assertFalse(label, ext.contains(outside));
            assertFalse(label, ext.contains(intersect));
            assertTrue(label, ext.intersects(intersect));
            assertFalse(label, ext.contains(spanning));
            assertTrue(label, ext.intersects(spanning));
            assertDisjoint(ext, disjoint);
            assertContains(ext, contained);
            break;
        }
        verifyInvariants(type, envelope);
    }
}
Also used : DirectPosition(org.opengis.geometry.DirectPosition) Rectangle2D(java.awt.geom.Rectangle2D) Envelope(org.opengis.geometry.Envelope) Test(org.junit.Test)

Example 8 with Envelope

use of org.opengis.geometry.Envelope in project sis by apache.

the class AbstractEnvelopeTest method testCrossingAntiMeridian.

/**
 * Tests a case crossing the anti-meridian.
 *
 * {@preformat text
 *      ─────┐  ┌─────────              ─────┐      ┌─────
 *           │  │  ┌────┐       or      ──┐  │      │  ┌──
 *           │  │  └────┘               ──┘  │      │  └──
 *      ─────┘  └─────────              ─────┘      └─────
 * }
 */
@Test
public void testCrossingAntiMeridian() {
    final DirectPosition2D inside = new DirectPosition2D(18, 32);
    final DirectPosition2D outside = new DirectPosition2D(3, 32);
    final Envelope2D contained = (Envelope2D) create(RECTANGLE, 14, 16, 35, 40);
    final Envelope2D intersect = (Envelope2D) create(RECTANGLE, -2, 16, 35, 40);
    final Envelope2D disjoint = (Envelope2D) create(RECTANGLE, -2, 10, 35, 40);
    final Envelope2D spanning = (Envelope2D) create(RECTANGLE, 16, -8, 35, 40);
    for (int type = 0; type < LAST; type++) {
        final String label = "Type " + type;
        final Envelope envelope = create(type, 12, -4, 30, 50);
        final DirectPosition lower = envelope.getLowerCorner();
        final DirectPosition upper = envelope.getUpperCorner();
        assertEquals(label, 30, envelope.getMinimum(1), STRICT);
        assertEquals(label, 50, envelope.getMaximum(1), STRICT);
        assertEquals(label, 40, envelope.getMedian(1), STRICT);
        assertEquals(label, 20, envelope.getSpan(1), STRICT);
        assertEquals(label, 12, lower.getOrdinate(0), STRICT);
        assertEquals(label, -180, envelope.getMinimum(0), STRICT);
        assertEquals(label, -4, upper.getOrdinate(0), STRICT);
        assertEquals(label, +180, envelope.getMaximum(0), STRICT);
        assertEquals(label, -176, envelope.getMedian(0), STRICT);
        // 360° - testSimpleEnvelope()
        assertEquals(label, 344, envelope.getSpan(0), STRICT);
        switch(type) {
            default:
                {
                    final AbstractEnvelope ext = (AbstractEnvelope) envelope;
                    assertTrue(label, ext.contains(inside));
                    assertFalse(label, ext.contains(outside));
                    assertFalse(label, ext.contains(intersect, false));
                    assertTrue(label, ext.intersects(intersect, false));
                    assertDisjoint(ext, disjoint);
                    assertContains(ext, contained);
                    assertContains(ext, spanning);
                    break;
                }
            case RECTANGLE:
                {
                    final Rectangle2D ext = (Rectangle2D) envelope;
                    assertTrue(label, ext.contains(inside));
                    assertFalse(label, ext.contains(outside));
                    assertFalse(label, ext.contains(intersect));
                    assertTrue(label, ext.intersects(intersect));
                    assertDisjoint(ext, disjoint);
                    assertContains(ext, contained);
                    assertContains(ext, spanning);
                    break;
                }
        }
        verifyInvariants(type, envelope);
    }
}
Also used : DirectPosition(org.opengis.geometry.DirectPosition) Rectangle2D(java.awt.geom.Rectangle2D) Envelope(org.opengis.geometry.Envelope) Test(org.junit.Test)

Example 9 with Envelope

use of org.opengis.geometry.Envelope in project sis by apache.

the class AbstractEnvelopeTest method testRange0.

/**
 * Tests an empty envelope from -0 to 0°
 */
@Test
public void testRange0() {
    final DirectPosition2D wasInside = new DirectPosition2D(18, 32);
    final DirectPosition2D outside = new DirectPosition2D(3, 32);
    final Envelope2D wasContained = (Envelope2D) create(RECTANGLE, 14, 16, 35, 40);
    final Envelope2D intersect = (Envelope2D) create(RECTANGLE, -2, 16, 35, 40);
    final Envelope2D spanning = (Envelope2D) create(RECTANGLE, 16, -8, 35, 40);
    for (int type = 0; type < LAST; type++) {
        final String label = "Type " + type;
        final Envelope envelope = create(type, -0.0, 0.0, 30, 50);
        assertEquals(label, 30, envelope.getMinimum(1), STRICT);
        assertEquals(label, 50, envelope.getMaximum(1), STRICT);
        assertEquals(label, 40, envelope.getMedian(1), STRICT);
        assertEquals(label, 20, envelope.getSpan(1), STRICT);
        assertEquals(label, -0.0, envelope.getMinimum(0), STRICT);
        assertEquals(label, 0.0, envelope.getMaximum(0), STRICT);
        assertEquals(label, 0, envelope.getMedian(0), STRICT);
        assertEquals(label, 0, envelope.getSpan(0), STRICT);
        switch(type) {
            default:
                {
                    final AbstractEnvelope ext = (AbstractEnvelope) envelope;
                    assertFalse(label, ext.contains(wasInside));
                    assertFalse(label, ext.contains(outside));
                    assertFalse(label, ext.contains(intersect, false));
                    assertTrue(label, ext.intersects(intersect, false));
                    assertFalse(label, ext.contains(spanning, false));
                    assertFalse(label, ext.intersects(spanning, false));
                    assertFalse(label, ext.intersects(spanning, false));
                    assertDisjoint(ext, wasContained);
                    break;
                }
            case RECTANGLE:
                {
                    final Rectangle2D ext = (Rectangle2D) envelope;
                    assertFalse(label, ext.contains(wasInside));
                    assertFalse(label, ext.contains(outside));
                    assertFalse(label, ext.contains(intersect));
                    assertTrue(label, ext.intersects(intersect));
                    assertFalse(label, ext.contains(spanning));
                    assertFalse(label, ext.intersects(spanning));
                    assertFalse(label, ext.intersects(spanning));
                    assertDisjoint(ext, wasContained);
                    break;
                }
        }
        verifyInvariants(type, envelope);
    }
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) Envelope(org.opengis.geometry.Envelope) Test(org.junit.Test)

Example 10 with Envelope

use of org.opengis.geometry.Envelope in project sis by apache.

the class AbstractEnvelopeTest method testSimpleEnvelope.

/**
 * Tests the simple case (no anti-meridian crossing).
 *
 * {@preformat text
 *     ┌─────────────┐
 *     │  ┌───────┐  │
 *     │  └───────┘  │
 *     └─────────────┘
 * }
 */
@Test
public void testSimpleEnvelope() {
    final DirectPosition2D inside = new DirectPosition2D(3, 32);
    final DirectPosition2D outside = new DirectPosition2D(-5, 32);
    final Envelope2D contained = (Envelope2D) create(RECTANGLE, -2, 10, 35, 40);
    final Envelope2D intersect = (Envelope2D) create(RECTANGLE, -2, 16, 35, 40);
    final Envelope2D disjoint = (Envelope2D) create(RECTANGLE, 14, 16, 35, 40);
    for (int type = 0; type < LAST; type++) {
        final String label = "Type " + type;
        final Envelope envelope = create(type, -4, 12, 30, 50);
        assertEquals(label, 30, envelope.getMinimum(1), STRICT);
        assertEquals(label, 50, envelope.getMaximum(1), STRICT);
        assertEquals(label, 40, envelope.getMedian(1), STRICT);
        assertEquals(label, 20, envelope.getSpan(1), STRICT);
        assertEquals(label, -4, envelope.getMinimum(0), STRICT);
        assertEquals(label, 12, envelope.getMaximum(0), STRICT);
        assertEquals(label, 4, envelope.getMedian(0), STRICT);
        assertEquals(label, 16, envelope.getSpan(0), STRICT);
        switch(type) {
            default:
                {
                    final AbstractEnvelope ext = (AbstractEnvelope) envelope;
                    assertTrue(label, ext.contains(inside));
                    assertFalse(label, ext.contains(outside));
                    assertFalse(label, ext.contains(intersect, false));
                    assertTrue(label, ext.intersects(intersect, false));
                    assertDisjoint(ext, disjoint);
                    assertContains(ext, contained);
                    break;
                }
            case RECTANGLE:
                {
                    final Rectangle2D ext = (Rectangle2D) envelope;
                    assertTrue(label, ext.contains(inside));
                    assertFalse(label, ext.contains(outside));
                    assertFalse(label, ext.contains(intersect));
                    assertTrue(label, ext.intersects(intersect));
                    assertDisjoint(ext, disjoint);
                    assertContains(ext, contained);
                    break;
                }
        }
        verifyInvariants(type, envelope);
    }
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) Envelope(org.opengis.geometry.Envelope) Test(org.junit.Test)

Aggregations

Envelope (org.opengis.geometry.Envelope)25 Test (org.junit.Test)11 Rectangle2D (java.awt.geom.Rectangle2D)7 Envelope2D (org.apache.sis.geometry.Envelope2D)5 DirectPosition (org.opengis.geometry.DirectPosition)5 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)5 GeneralEnvelope (org.apache.sis.geometry.GeneralEnvelope)4 TransformException (org.opengis.referencing.operation.TransformException)4 GeographicBoundingBox (org.opengis.metadata.extent.GeographicBoundingBox)3 Angle (javax.measure.quantity.Angle)2 Matrix3 (org.apache.sis.referencing.operation.matrix.Matrix3)2 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)2 GeographicCRS (org.opengis.referencing.crs.GeographicCRS)2 CoordinateSystem (org.opengis.referencing.cs.CoordinateSystem)2 ReferencedEnvelopeValues (com.sldeditor.rendertransformation.types.ReferencedEnvelopeValues)1 FieldConfigBase (com.sldeditor.ui.detail.config.FieldConfigBase)1 FieldConfigBoundingBox (com.sldeditor.ui.detail.config.FieldConfigBoundingBox)1 FieldConfigCommonData (com.sldeditor.ui.detail.config.FieldConfigCommonData)1 Shape (java.awt.Shape)1 BufferedWriter (java.io.BufferedWriter)1