Search in sources :

Example 1 with GeneralEnvelope

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

the class CRS method getDomainOfValidity.

/**
 * Returns the domain of validity of the specified coordinate reference system, or {@code null} if unknown.
 * If non-null, then the returned envelope will use the same coordinate reference system them the given CRS
 * argument.
 *
 * @param  crs  the coordinate reference system, or {@code null}.
 * @return the envelope with coordinates in the given CRS, or {@code null} if none.
 *
 * @see #getGeographicBoundingBox(CoordinateReferenceSystem)
 *
 * @category information
 * @since 0.8
 */
public static Envelope getDomainOfValidity(final CoordinateReferenceSystem crs) {
    Envelope envelope = null;
    GeneralEnvelope merged = null;
    /* if (envelope == null) */
    {
        // Condition needed on other branches but not on trunk.
        final GeographicBoundingBox bounds = getGeographicBoundingBox(crs);
        if (bounds != null && !Boolean.FALSE.equals(bounds.getInclusion())) {
            /*
                 * We do not assign WGS84 unconditionally to the geographic bounding box, because
                 * it is not defined to be on a particular datum; it is only approximative bounds.
                 * We try to get the GeographicCRS from the user-supplied CRS in order to reduce
                 * the amount of transformation needed.
                 */
            final SingleCRS targetCRS = getHorizontalComponent(crs);
            final GeographicCRS sourceCRS = ReferencingUtilities.toNormalizedGeographicCRS(targetCRS);
            if (sourceCRS != null) {
                envelope = merged = new GeneralEnvelope(bounds);
                merged.translate(-getGreenwichLongitude(sourceCRS), 0);
                merged.setCoordinateReferenceSystem(sourceCRS);
                try {
                    envelope = Envelopes.transform(envelope, targetCRS);
                } catch (TransformException exception) {
                    /*
                         * The envelope is probably outside the range of validity for this CRS.
                         * It should not occurs, since the envelope is supposed to describe the
                         * CRS area of validity. Logs a warning and returns null, since it is a
                         * legal return value according this method contract.
                         */
                    unexpectedException("getEnvelope", exception);
                    envelope = null;
                }
            }
        }
    }
    return envelope;
}
Also used : SingleCRS(org.opengis.referencing.crs.SingleCRS) TransformException(org.opengis.referencing.operation.TransformException) GeographicBoundingBox(org.opengis.metadata.extent.GeographicBoundingBox) DefaultGeographicBoundingBox(org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox) GeographicCRS(org.opengis.referencing.crs.GeographicCRS) DefaultGeographicCRS(org.apache.sis.referencing.crs.DefaultGeographicCRS) Envelope(org.opengis.geometry.Envelope) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope)

Example 2 with GeneralEnvelope

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

the class MatricesTest method testCreateTransformFromEnvelopes.

/**
 * Tests {@link Matrices#createTransform(Envelope, Envelope)}.
 * This method tests the example given in {@code Matrices.createTransform(…)} javadoc.
 */
@Test
public void testCreateTransformFromEnvelopes() {
    final Envelope srcEnvelope = new Envelope2D(null, -20, -40, 100, 200);
    final Envelope dstEnvelope = new Envelope2D(null, -10, -25, 300, 500);
    MatrixSIS matrix = Matrices.createTransform(srcEnvelope, dstEnvelope);
    assertTrue("isAffine", matrix.isAffine());
    assertFalse("isIdentity", matrix.isIdentity());
    assertEquals("numRow", 3, matrix.getNumRow());
    assertEquals("numCol", 3, matrix.getNumCol());
    assertEquals(Matrices.create(3, 3, new double[] { 3.0, 0, 50, 0, 2.5, 75, 0, 0, 1 }), matrix);
    /*
         * Test dropping a dimension.
         */
    final GeneralEnvelope expanded = new GeneralEnvelope(3);
    expanded.subEnvelope(0, 2).setEnvelope(srcEnvelope);
    expanded.setRange(2, 1000, 2000);
    matrix = Matrices.createTransform(expanded, dstEnvelope);
    assertEquals("numRow", 3, matrix.getNumRow());
    assertEquals("numCol", 4, matrix.getNumCol());
    assertEquals(Matrices.create(3, 4, new double[] { 3.0, 0, 0, 50, 0, 2.5, 0, 75, 0, 0, 0, 1 }), matrix);
    /*
         * Test adding a dimension with ordinate values set to zero.
         */
    expanded.subEnvelope(0, 2).setEnvelope(dstEnvelope);
    matrix = Matrices.createTransform(srcEnvelope, expanded);
    assertEquals("numRow", 4, matrix.getNumRow());
    assertEquals("numCol", 3, matrix.getNumCol());
    assertEquals(Matrices.create(4, 3, new double[] { 3.0, 0, 50, 0, 2.5, 75, 0, 0, 0, 0, 0, 1 }), matrix);
}
Also used : Envelope(org.opengis.geometry.Envelope) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) Envelope2D(org.apache.sis.geometry.Envelope2D) Test(org.junit.Test)

Example 3 with GeneralEnvelope

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

the class MatricesTest method testCreateTransformFromEnvelopesAndAxes.

/**
 * Tests {@link Matrices#createTransform(Envelope, AxisDirection[], Envelope, AxisDirection[])}.
 * This method tests the example given in {@code Matrices.createTransform(…)} javadoc.
 */
@Test
@DependsOnMethod({ "testCreateTransformFromEnvelopes", "testCreateTransformWithLessAxes" })
public void testCreateTransformFromEnvelopesAndAxes() {
    // swapped (y,-x)
    final Envelope srcEnvelope = new Envelope2D(null, -40, +20, 200, 100);
    final Envelope dstEnvelope = new Envelope2D(null, -10, -25, 300, 500);
    MatrixSIS matrix = Matrices.createTransform(srcEnvelope, new AxisDirection[] { NORTH, WEST }, dstEnvelope, new AxisDirection[] { EAST, NORTH });
    assertTrue("isAffine", matrix.isAffine());
    assertFalse("isIdentity", matrix.isIdentity());
    assertEquals("numRow", 3, matrix.getNumRow());
    assertEquals("numCol", 3, matrix.getNumCol());
    assertMatrixEquals("(N,E) → (E,N)", Matrices.create(3, 3, new double[] { 0, -3.0, 350, 2.5, 0, 75, 0, 0, 1 }), matrix, STRICT);
    /*
         * Test dropping a dimension.
         */
    final GeneralEnvelope expanded = new GeneralEnvelope(3);
    expanded.subEnvelope(0, 2).setEnvelope(srcEnvelope);
    expanded.setRange(2, 1000, 2000);
    matrix = Matrices.createTransform(expanded, new AxisDirection[] { NORTH, WEST, UP }, dstEnvelope, new AxisDirection[] { EAST, NORTH });
    assertEquals("numRow", 3, matrix.getNumRow());
    assertEquals("numCol", 4, matrix.getNumCol());
    assertMatrixEquals("(N,E,U) → (E,N)", Matrices.create(3, 4, new double[] { 0, -3.0, 0, 350, 2.5, 0, 0, 75, 0, 0, 0, 1 }), matrix, STRICT);
}
Also used : AxisDirection(org.opengis.referencing.cs.AxisDirection) Envelope(org.opengis.geometry.Envelope) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) Envelope2D(org.apache.sis.geometry.Envelope2D) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 4 with GeneralEnvelope

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

the class LocationViewer method main.

/**
 * Shows the locations tested by {@code MilitaryGridReferenceSystemTest.testIterator()} methods.
 *
 * @param  args  ignored.
 * @throws Exception if an error occurred while transforming an envelope to the display CRS.
 */
public static void main(final String[] args) throws Exception {
    final MilitaryGridReferenceSystem.Coder coder = new MilitaryGridReferenceSystem().createCoder();
    coder.setPrecision(100000);
    switch(1) {
        /*
             * UTM North: 3 zones (31, 32 and 33) and 3 latitude bands (T, U and V).
             * Include the Norway special case: in latitude band V, zone 32 is widened at the expense of zone 31.
             */
        case 1:
            {
                show("UTM zones 31, 32 and 33 North", coder, new Envelope2D(CommonCRS.defaultGeographic(), 5, 47, 8, 10), CommonCRS.WGS84.universal(1, 9));
                break;
            }
        /*
             * UTM South: 3 zones (31, 32 and 33) and 2 latitude bands (G and H).
             */
        case 2:
            {
                show("UTM zones 31, 32 and 33 South", coder, new Envelope2D(CommonCRS.defaultGeographic(), 5, -42, 8, 4), CommonCRS.WGS84.universal(1, 9));
                break;
            }
        /*
             * Crossing the anti-meridian. There is two columns of cells: on the west side and on the east side.
             */
        case 3:
            {
                final GeneralEnvelope ge = new GeneralEnvelope(CommonCRS.defaultGeographic());
                ge.setRange(0, 170, -175);
                ge.setRange(1, 40, 42);
                show("15° of longitude spanning the anti-meridian", coder, ge, null);
                break;
            }
        /*
             * Complete North pole case surrounded by part of V latitude band.
             * This include the Svalbard special case in zones 31 to 37.
             */
        case 4:
            {
                show("North pole surrounded by V latitude band", coder, new Envelope2D(CommonCRS.defaultGeographic(), -180, 80, 360, 10), CommonCRS.WGS84.universal(90, 0));
                break;
            }
        /*
             * Complete South pole case surrounded by one latitude band.
             */
        case 5:
            {
                show("South pole surrounded by C latitude band", coder, new Envelope2D(CommonCRS.defaultGeographic(), -180, -90, 360, 12), CommonCRS.WGS84.universal(-90, 0));
                break;
            }
        /*
             * Partial North pole case.
             */
        case 6:
            {
                show("10°W to 70°E close to North pole", coder, new Envelope2D(CommonCRS.defaultGeographic(), -10, 85, 80, 5), CommonCRS.WGS84.universal(90, 0));
                break;
            }
        /*
             * Partial South pole case with zone UTM zones.
             */
        case 7:
            {
                show("70°W to 120°W close to South pole", coder, new Envelope2D(CommonCRS.defaultGeographic(), -120, -83, 50, 5), CommonCRS.WGS84.universal(-90, 0));
                break;
            }
    }
}
Also used : GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) Envelope2D(org.apache.sis.geometry.Envelope2D)

Example 5 with GeneralEnvelope

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

the class MilitaryGridReferenceSystemTest method testIteratorOverAntiMeridian.

/**
 * Tests iteration spanning the anti-meridian.
 *
 * <div class="note"><b>Tip:</b> in case of test failure, see {@link LocationViewer} as a debugging tool.</div>
 *
 * @throws TransformException if an error occurred while computing the coordinate.
 */
@Test
@DependsOnMethod("testEncodeUTM")
public void testIteratorOverAntiMeridian() throws TransformException {
    final GeneralEnvelope areaOfInterest = new GeneralEnvelope(CommonCRS.defaultGeographic());
    areaOfInterest.setRange(0, 170, -175);
    areaOfInterest.setRange(1, 40, 42);
    testIterator(areaOfInterest, Arrays.asList("59SME", "59SNE", "59SPE", "59SQE", "60STK", "60SUK", "60SVK", "60SWK", "60SXK", "60SYK", "1SBE", "1SCE", "1SDE", "1SEE", "1SFE", "59TME", "59TNE", "59TPE", "59TQE", "60TTK", "60TUK", "60TVK", "60TWK", "60TXK", "60TYK", "1TBE", "1TCE", "1TDE", "1TEE", "1TFE", "59TMF", "59TNF", "59TPF", "59TQF", "60TTL", "60TUL", "60TVL", "60TWL", "60TXL", "60TYL", "1TBF", "1TCF", "1TDF", "1TEF", "1TFF", "59TMG", "59TNG", "59TPG", "59TQG", "60TTM", "60TUM", "60TVM", "60TWM", "60TXM", "60TYM", "1TBG", "1TCG", "1TDG", "1TEG", "1TFG"));
}
Also used : GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Aggregations

GeneralEnvelope (org.apache.sis.geometry.GeneralEnvelope)14 Envelope2D (org.apache.sis.geometry.Envelope2D)3 Test (org.junit.Test)3 Envelope (org.opengis.geometry.Envelope)3 DependsOnMethod (org.apache.sis.test.DependsOnMethod)2 Envelope2D (com.esri.core.geometry.Envelope2D)1 Geometry (com.esri.core.geometry.Geometry)1 Point (com.esri.core.geometry.Point)1 Polygon (com.esri.core.geometry.Polygon)1 Shape (java.awt.Shape)1 Rectangle2D (java.awt.geom.Rectangle2D)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Instant (java.time.Instant)1 Time (javax.measure.quantity.Time)1 GeodeticObjectBuilder (org.apache.sis.internal.referencing.GeodeticObjectBuilder)1 DefaultGeographicBoundingBox (org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox)1 DefaultGeographicCRS (org.apache.sis.referencing.crs.DefaultGeographicCRS)1 DataStoreReferencingException (org.apache.sis.storage.DataStoreReferencingException)1 GeographicBoundingBox (org.opengis.metadata.extent.GeographicBoundingBox)1 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)1