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;
}
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);
}
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');
}
}
}
Aggregations