use of org.apache.sis.geometry.DirectPosition2D in project sis by apache.
the class DefaultCoordinateOperationFactoryTest method testMercatorToGoogle.
/**
* Tests the conversion from Mercator projection to the Google projection. The referencing module
* should detects that the conversion is something more complex that an identity transform.
*
* @throws ParseException if a CRS used in this test can not be parsed.
* @throws FactoryException if the operation can not be created.
* @throws TransformException if an error occurred while converting the test points.
*/
@Test
public void testMercatorToGoogle() throws ParseException, FactoryException, TransformException {
final CoordinateReferenceSystem sourceCRS = parse("$Mercator");
final CoordinateReferenceSystem targetCRS = parse("ProjectedCRS[“WGS 84 / Pseudo-Mercator”,\n" + " BaseGeodCRS[“WGS 84”,\n" + " Datum[“World Geodetic System 1984”,\n" + " Ellipsoid[“WGS 84”, 6378137.0, 298.257223563]],\n" + " Unit[“degree”, 0.017453292519943295]],\n" + " Conversion[“Popular Visualisation Pseudo-Mercator”,\n" + " Method[“Popular Visualisation Pseudo Mercator”]],\n" + " CS[Cartesian, 2],\n" + " Axis[“Easting (X)”, east],\n" + " Axis[“Northing (Y)”, north],\n" + " Unit[“metre”, 1],\n" + " Id[“EPSG”, 3857]]");
final CoordinateOperation operation = factory.createOperation(sourceCRS, targetCRS);
assertSame("sourceCRS", sourceCRS, operation.getSourceCRS());
assertSame("targetCRS", targetCRS, operation.getTargetCRS());
assertInstanceOf("operation", ConcatenatedOperation.class, operation);
transform = operation.getMathTransform();
tolerance = 1;
assertFalse("Mercator to Google should not be an identity transform.", transform.isIdentity());
// Approximatively 40°N 3°W
final DirectPosition2D sourcePt = new DirectPosition2D(334000, 4840000);
final DirectPosition2D targetPt = new DirectPosition2D();
assertSame(targetPt, transform.transform(sourcePt, targetPt));
assertEquals("Easting should be unchanged", sourcePt.getX(), targetPt.getX(), STRICT);
assertEquals("Expected 27 km shift", 27476, targetPt.getY() - sourcePt.getY(), tolerance);
}
use of org.apache.sis.geometry.DirectPosition2D in project sis by apache.
the class LinearTransformBuilderTest method testMinimalist2D.
/**
* Tests a very simple case where an exact answer is expected.
* Tolerance threshold is set to zero because the math transform has been built from exactly 3 points,
* in which case we expect an exact solution without rounding errors at the scale of the {@code double}
* type. This is possible because SIS implementation uses double-double arithmetic.
*
* @throws FactoryException if the transform can not be created.
*/
@Test
public void testMinimalist2D() throws FactoryException {
final Map<DirectPosition2D, DirectPosition2D> pos = new HashMap<>(8);
assertNull(pos.put(new DirectPosition2D(1, 1), new DirectPosition2D(3, 2)));
assertNull(pos.put(new DirectPosition2D(1, 2), new DirectPosition2D(3, 5)));
assertNull(pos.put(new DirectPosition2D(2, 2), new DirectPosition2D(5, 5)));
final LinearTransformBuilder builder = new LinearTransformBuilder();
builder.setControlPoints(pos);
assertArrayEquals(new double[] { 3, 2 }, builder.getControlPoint(new int[] { 1, 1 }), STRICT);
assertArrayEquals(new double[] { 3, 5 }, builder.getControlPoint(new int[] { 1, 2 }), STRICT);
assertArrayEquals(new double[] { 5, 5 }, builder.getControlPoint(new int[] { 2, 2 }), STRICT);
assertNull(builder.getControlPoint(new int[] { 2, 1 }));
final Matrix m = builder.create(null).getMatrix();
// First row (x)
assertEquals("m₀₀", 2, m.getElement(0, 0), STRICT);
assertEquals("m₀₁", 0, m.getElement(0, 1), STRICT);
assertEquals("m₀₂", 1, m.getElement(0, 2), STRICT);
// Second row (y)
assertEquals("m₁₀", 0, m.getElement(1, 0), STRICT);
assertEquals("m₁₁", 3, m.getElement(1, 1), STRICT);
assertEquals("m₁₂", -1, m.getElement(1, 2), STRICT);
assertArrayEquals("correlation", new double[] { 1, 1 }, builder.correlation(), STRICT);
}
use of org.apache.sis.geometry.DirectPosition2D in project sis by apache.
the class EllipsoidToCentricTransformTest method testDerivative.
/**
* Executes the derivative test using the given ellipsoid.
*
* @param ellipsoid the ellipsoid to use for the test.
* @param hasHeight {@code true} if geographic coordinates include an ellipsoidal height (i.e. are 3-D),
* or {@code false} if they are only 2-D.
* @throws FactoryException if an error occurred while creating a transform.
* @throws TransformException should never happen.
*/
private void testDerivative(final Ellipsoid ellipsoid, final boolean hasHeight) throws FactoryException, TransformException {
createGeodeticConversion(ellipsoid, hasHeight);
DirectPosition point = hasHeight ? new GeneralDirectPosition(-10, 40, 200) : new DirectPosition2D(-10, 40);
/*
* Derivative of the direct transform.
*/
tolerance = 1E-2;
// Approximatively one metre.
derivativeDeltas = new double[] { toRadians(1.0 / 60) / 1852 };
verifyDerivative(point.getCoordinate());
/*
* Derivative of the inverse transform.
*/
point = transform.transform(point, null);
transform = transform.inverse();
tolerance = 1E-8;
// Approximatively one metre.
derivativeDeltas = new double[] { 1 };
verifyDerivative(point.getCoordinate());
}
use of org.apache.sis.geometry.DirectPosition2D in project sis by apache.
the class LatLonPointRadius method getCircularRegionApproximation.
/**
* Gets the circular region approximation on the earth surface using haversine
* formula.
*
* @param numberOfPoints
* the number of points used to estimate the circular region
* @return an array of DirectPosition2D representing the points that estimate the
* circular region
*/
public DirectPosition2D[] getCircularRegionApproximation(int numberOfPoints) {
if (radius >= DistanceUtils.HALF_EARTH_CIRCUMFERENCE) {
DirectPosition2D[] points = new DirectPosition2D[5];
points[0] = new DirectPosition2D(-180.0, -90.0);
points[1] = new DirectPosition2D(-180.0, 90.0);
points[2] = new DirectPosition2D(180.0, 90.0);
points[3] = new DirectPosition2D(180.0, -90.0);
points[4] = points[0];
return points;
}
// plus one to add closing point
DirectPosition2D[] points = new DirectPosition2D[numberOfPoints + 1];
double bearingIncrement = 0;
if (numberOfPoints > 0) {
bearingIncrement = 360 / numberOfPoints;
}
for (int i = 0; i < numberOfPoints; i++) {
points[i] = DistanceUtils.getPointOnGreatCircle(center.getOrdinate(1), center.getOrdinate(0), radius, i * bearingIncrement);
}
points[numberOfPoints] = points[0];
return points;
}
use of org.apache.sis.geometry.DirectPosition2D in project sis by apache.
the class GeohashReferenceSystemTest method testEncodePosition.
/**
* Tests the {@link GeohashReferenceSystem.Coder#encode(DirectPosition)} method.
*
* @throws TransformException if an exception occurred while formatting the geohash.
*/
@Test
@DependsOnMethod("testEncode")
public void testEncodePosition() throws TransformException {
final GeohashReferenceSystem.Coder coder = instance().createCoder();
final DirectPosition2D position = new DirectPosition2D(CommonCRS.WGS84.geographic());
for (final Place place : PLACES) {
position.x = place.latitude;
position.y = place.longitude;
assertEquals(place.name, place.geohash, coder.encode(position));
}
}
Aggregations