Search in sources :

Example 6 with Envelope2D

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

the class MilitaryGridReferenceSystemTest method decode.

/**
 * Decodes the given reference and returns its direct position.
 */
private static DirectPosition decode(final MilitaryGridReferenceSystem.Coder coder, final String reference) throws TransformException {
    final AbstractLocation loc = coder.decode(reference);
    final Envelope2D envelope = new Envelope2D(loc.getEnvelope());
    final DirectPosition2D pos = new DirectPosition2D(loc.getPosition().getDirectPosition());
    assertTrue(reference, envelope.contains(pos));
    return pos;
}
Also used : Envelope2D(org.apache.sis.geometry.Envelope2D) DirectPosition2D(org.apache.sis.geometry.DirectPosition2D)

Example 7 with Envelope2D

use of org.apache.sis.geometry.Envelope2D 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 8 with Envelope2D

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

the class NADCONTest method writeSubGrid.

// ////////////////////////////////////////////////
// //////                                  ////////
// //////        TEST FILE CREATION        ////////
// //////                                  ////////
// ////////////////////////////////////////////////
/**
 * Writes a sub-grid of the given grid in pseudo-NADCON ASCII format.
 * This method is used only for creating the test file, and the output is not fully NADCON compliant.
 * We take this opportunity for testing the parser capability to be lenient.
 *
 * <p>This method has been executed once for creating the {@code "conus-extract.laa"} and
 * {@code "conus-extract.loa"} test files 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} = 125</li>
 *   <li>{@code gridY} =  70</li>
 *   <li>{@code nx}    =   8</li>
 *   <li>{@code ny}    =  10</li>
 * </ul>
 *
 * This ensure that the grid indices (129.83277, 76.89632) is included in the test file.
 * Those grid indices is the location of the (39°13′26.71″N, 98°32′31.75″W) test point to interpolate.
 *
 * @param  grid   the full grid from which to extract a few values.
 * @param  file   where to write the test file.
 * @param  dim    0 for writing longitudes, or 1 for writing latitudes.
 * @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 file, final int dim, 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);
    try (BufferedWriter out = Files.newBufferedWriter(file)) {
        out.write("NADCON EXTRACTED REGION\n");
        out.write(String.format(Locale.US, "%4d %3d %3d %11.5f %11.5f %11.5f %11.5f %11.5f\n", nx, ny, 1, envelope.getMinimum(0), envelope.getSpan(0) / (nx - 1), envelope.getMinimum(1), envelope.getSpan(1) / (ny - 1), 0.0));
        for (int y = 0; y < ny; y++) {
            for (int x = 0; x < nx; x++) {
                out.write(String.format(Locale.US, " %11.6f", grid.getCellValue(dim, gridX + x, gridY + y)));
            }
            out.write('\n');
        }
    }
}
Also used : Envelope(org.opengis.geometry.Envelope) Envelope2D(org.apache.sis.geometry.Envelope2D) BufferedWriter(java.io.BufferedWriter)

Aggregations

Envelope2D (org.apache.sis.geometry.Envelope2D)8 Envelope (org.opengis.geometry.Envelope)5 GeneralEnvelope (org.apache.sis.geometry.GeneralEnvelope)3 DirectPosition2D (org.apache.sis.geometry.DirectPosition2D)2 Test (org.junit.Test)2 Rectangle2D (java.awt.geom.Rectangle2D)1 BufferedWriter (java.io.BufferedWriter)1 PrintWriter (java.io.PrintWriter)1 ByteBuffer (java.nio.ByteBuffer)1 WritableByteChannel (java.nio.channels.WritableByteChannel)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 QuadTreeData (org.apache.sis.index.tree.QuadTreeData)1 DependsOnMethod (org.apache.sis.test.DependsOnMethod)1 AxisDirection (org.opengis.referencing.cs.AxisDirection)1 MathTransform (org.opengis.referencing.operation.MathTransform)1