Search in sources :

Example 11 with Envelope

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

the class EnvelopesTest method testFromWKT.

/**
 * Tests {@link Envelopes#fromWKT(CharSequence)}. This test is provided as a matter of principle,
 * but the real test is done by {@link GeneralEnvelopeTest#testWktParsing()}.
 *
 * @throws FactoryException if an error occurred during WKT parsing.
 */
@Test
public void testFromWKT() throws FactoryException {
    final Envelope envelope = Envelopes.fromWKT("BOX(-100 -80, 70 40)");
    assertEquals(2, envelope.getDimension());
    assertEquals(-100, envelope.getMinimum(0), 0);
    assertEquals(70, envelope.getMaximum(0), 0);
    assertEquals(-80, envelope.getMinimum(1), 0);
    assertEquals(40, envelope.getMaximum(1), 0);
    validate(envelope);
}
Also used : Envelope(org.opengis.geometry.Envelope) Test(org.junit.Test)

Example 12 with Envelope

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

the class FranceGeocentricInterpolationTest method verifyGrid.

/**
 * Verifies the envelope and the interpolation performed by the given grid.
 *
 * @throws TransformException if an error occurred while computing the envelope.
 */
private static void verifyGrid(final DatumShiftGridFile<Angle, Length> grid) throws TransformException {
    final Envelope envelope = grid.getDomainOfValidity();
    assertEquals("xmin", 2.2 - 0.05, envelope.getMinimum(0), 1E-12);
    assertEquals("xmax", 2.5 + 0.05, envelope.getMaximum(0), 1E-12);
    assertEquals("ymin", 48.5 - 0.05, envelope.getMinimum(1), 1E-12);
    assertEquals("ymax", 49.0 + 0.05, envelope.getMaximum(1), 1E-12);
    /*
         * The values in the NTG_88 document are:
         *
         * (gridX=2, gridY=3)  00002    2.400000000   48.800000000  -168.252   -58.630   320.170  01   2314
         * (gridX=2, gridY=4)  00002    2.400000000   48.900000000  -168.275   -58.606   320.189  01   2314
         * (gridX=3, gridY=3)  00002    2.500000000   48.800000000  -168.204   -58.594   320.125  01   2314
         * (gridX=3, gridY=4)  00002    2.500000000   48.900000000  -168.253   -58.554   320.165  01   2314
         *
         * Directions (signs) are reversed compared to NTG_88 document.
         */
    assertEquals("translationDimensions", 3, grid.getTranslationDimensions());
    assertEquals("grid.accuracy", 0.05, grid.accuracy, STRICT);
    assertEquals("getCellValue", 168.196, grid.getCellValue(0, 2, 1), STRICT);
    assertEquals("getCellValue", 58.778, grid.getCellValue(1, 2, 1), STRICT);
    assertEquals("getCellValue", -320.127, grid.getCellValue(2, 2, 1), STRICT);
    /*
         * Interpolate the (ΔX, ΔY, ΔZ) at a point.
         * Directions (signs) are reversed compared to NTG_88 document.
         */
    final double[] expected = { // ΔX: Toward prime meridian
    168.253, // ΔY: Toward 90° east
    58.609, // ΔZ: Toward north pole
    -320.170 };
    final double[] point = samplePoint(3);
    final double[] vector = grid.interpolateAt(point[0], point[1]);
    assertArrayEquals("(ΔX, ΔY, ΔZ)", expected, vector, 0.0005);
}
Also used : Envelope(org.opengis.geometry.Envelope)

Example 13 with Envelope

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

the class NADCONTest method testNADCON.

/**
 * Implementation of {@link #testLoader()} and {@link #testNADCON(Path, Path)}.
 *
 * @param  xmin  westmost longitude.
 * @param  xmax  eastmost longitude.
 * @param  ymin  southmost latitude.
 * @param  ymax  northmost latitude.
 */
private static void testNADCON(final Path latitudeShifts, final Path longitudeShifts, final double xmin, final double xmax, final double ymin, final double ymax) throws IOException, FactoryException, TransformException {
    final DatumShiftGridFile<Angle, Angle> grid = NADCON.getOrLoad(latitudeShifts, longitudeShifts);
    assertInstanceOf("Should not be compressed.", DatumShiftGridFile.Float.class, grid);
    assertEquals("coordinateUnit", Units.DEGREE, grid.getCoordinateUnit());
    assertEquals("translationUnit", Units.DEGREE, grid.getTranslationUnit());
    assertEquals("translationDimensions", 2, grid.getTranslationDimensions());
    assertTrue("isCellValueRatio", grid.isCellValueRatio());
    assertTrue("cellPrecision", grid.getCellPrecision() > 0);
    /*
         * Verify the envelope and the conversion between geographic coordinates and grid indices.
         * The cells are expected to have the same size (0.25°) in longitudes and latitudes.
         */
    final double cellSize = 0.25;
    final Envelope envelope = grid.getDomainOfValidity();
    assertEquals("xmin", xmin - cellSize / 2, envelope.getMinimum(0), STRICT);
    assertEquals("xmax", xmax + cellSize / 2, envelope.getMaximum(0), STRICT);
    assertEquals("ymin", ymin - cellSize / 2, envelope.getMinimum(1), STRICT);
    assertEquals("ymax", ymax + cellSize / 2, envelope.getMaximum(1), STRICT);
    assertMatrixEquals("coordinateToGrid", new Matrix3(cellSize, 0, xmin, 0, cellSize, ymin, 0, 0, 1), grid.getCoordinateToGrid().inverse().getMatrix(), STRICT);
    /*
         * Test the Meades Ranch station. If we were using the complete Conus files, we would obtain
         * after conversion the grid indices listed on the left side. But since we are using a sub-set
         * of the grid, we rather obtain the grid indices on the right side.
         *
         *   gridX ≈ 129.83277 in official file,   ≈ 4.83277 in the test file.
         *   gridY ≈  76.89632 in official file,   ≈ 6.89632 in the test file.
         */
    final double[] position = samplePoint(1);
    final double[] expected = samplePoint(2);
    final double[] indices = new double[position.length];
    final double[] vector = new double[2];
    grid.getCoordinateToGrid().transform(position, 0, indices, 0, 1);
    grid.interpolateInCell(indices[0], indices[1], vector);
    vector[0] *= cellSize * DatumShiftGridLoader.DEGREES_TO_SECONDS;
    vector[1] *= cellSize * DatumShiftGridLoader.DEGREES_TO_SECONDS;
    assertArrayEquals("interpolateInCell", expected, vector, 0.5E-5);
    // Same test than above, but let DatumShiftGrid do the conversions for us.
    expected[0] /= DatumShiftGridLoader.DEGREES_TO_SECONDS;
    expected[1] /= DatumShiftGridLoader.DEGREES_TO_SECONDS;
    assertArrayEquals("interpolateAt", expected, grid.interpolateAt(position), ANGULAR_TOLERANCE);
    assertSame("Grid should be cached.", grid, NADCON.getOrLoad(latitudeShifts, longitudeShifts));
}
Also used : Angle(javax.measure.quantity.Angle) Envelope(org.opengis.geometry.Envelope) Matrix3(org.apache.sis.referencing.operation.matrix.Matrix3)

Example 14 with Envelope

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

the class NTv2Test method writeSubGrid.

// ////////////////////////////////////////////////
// //////                                  ////////
// //////        TEST FILE CREATION        ////////
// //////                                  ////////
// ////////////////////////////////////////////////
/**
 * Writes a sub-grid of the given grid in pseudo-NTv2 format. This method is used only for creating the test file.
 * The file created by this method is not fully NTv2 compliant (in particular, we do not write complete header),
 * but we take this opportunity for testing {@code NTv2.Loader} capability to be lenient.
 *
 * <p>This method has been executed once for creating the {@code "NTF_R93-extract.gsb"} test file and should not
 * be needed anymore, but we keep it around in case we have new test files to generate. The parameter used for
 * creating the test file are:</p>
 *
 * <ul>
 *   <li>{@code gridX} = 72</li>
 *   <li>{@code gridY} = 74</li>
 *   <li>{@code nx}    =  6</li>
 *   <li>{@code ny}    =  7</li>
 * </ul>
 *
 * This ensure that the grid indices (75.7432814, 78.4451225) is included in the test file.
 * Those grid indices is the location of the (2°25′32.4187″N 48°50′40.2441″W) test point to interpolate.
 *
 * <div class="section">Limitations</div>
 * This method assumes that bounding box and increments have integer values, and that any fractional part
 * is rounding errors. This is usually the case when using the {@code "SECONDS"} unit of measurement.
 * This assumption does not apply to the shift values.
 *
 * @param  grid   the full grid from which to extract a few values.
 * @param  out    where to write the test file.
 * @param  gridX  index along the longitude axis of the first cell to write.
 * @param  gridY  index along the latitude axis of the first cell to write.
 * @param  nx     number of cells to write along the longitude axis.
 * @param  ny     number of cells to write along the latitude axis.
 * @throws TransformException if an error occurred while computing the envelope.
 * @throws IOException if an error occurred while writing the test file.
 */
public static void writeSubGrid(final DatumShiftGridFile<Angle, Angle> grid, final Path out, final int gridX, final int gridY, final int nx, final int ny) throws IOException, TransformException {
    Envelope envelope = new Envelope2D(null, gridX, gridY, nx - 1, ny - 1);
    envelope = Envelopes.transform(grid.getCoordinateToGrid().inverse(), envelope);
    final ByteBuffer buffer = ByteBuffer.allocate(4096);
    buffer.order(ByteOrder.LITTLE_ENDIAN);
    writeString(buffer, "NUM_OREC");
    buffer.putInt(5);
    nextRecord(buffer);
    writeString(buffer, "NUM_SREC");
    buffer.putInt(7);
    nextRecord(buffer);
    writeString(buffer, "NUM_FILE");
    buffer.putInt(1);
    nextRecord(buffer);
    writeString(buffer, "GS_TYPE");
    writeString(buffer, "SECONDS");
    // Last overview record.
    writeString(buffer, "VERSION");
    // Last overview record.
    writeString(buffer, "SIS_TEST");
    writeString(buffer, "S_LAT");
    buffer.putDouble(StrictMath.rint(envelope.getMinimum(1)));
    writeString(buffer, "N_LAT");
    buffer.putDouble(StrictMath.rint(envelope.getMaximum(1)));
    // Sign reversed.
    writeString(buffer, "E_LONG");
    // Sign reversed.
    buffer.putDouble(StrictMath.rint(-envelope.getMaximum(0)));
    writeString(buffer, "W_LONG");
    buffer.putDouble(StrictMath.rint(-envelope.getMinimum(0)));
    writeString(buffer, "LAT_INC");
    buffer.putDouble(StrictMath.rint(envelope.getSpan(1) / (ny - 1)));
    writeString(buffer, "LONG_INC");
    buffer.putDouble(StrictMath.rint(envelope.getSpan(0) / (nx - 1)));
    writeString(buffer, "GS_COUNT");
    buffer.putInt(nx * ny);
    nextRecord(buffer);
    for (int y = 0; y < ny; y++) {
        for (int x = 0; x < nx; x++) {
            buffer.putFloat((float) grid.getCellValue(1, gridX + x, gridY + y));
            buffer.putFloat((float) grid.getCellValue(0, gridX + x, gridY + y));
            buffer.putFloat(ACCURACY);
            buffer.putFloat(ACCURACY);
        }
    }
    writeString(buffer, "END");
    nextRecord(buffer);
    try (WritableByteChannel c = Files.newByteChannel(out, StandardOpenOption.CREATE, StandardOpenOption.WRITE)) {
        buffer.flip();
        c.write(buffer);
    }
}
Also used : WritableByteChannel(java.nio.channels.WritableByteChannel) Envelope(org.opengis.geometry.Envelope) Envelope2D(org.apache.sis.geometry.Envelope2D) ByteBuffer(java.nio.ByteBuffer)

Example 15 with Envelope

use of org.opengis.geometry.Envelope 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)

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