Search in sources :

Example 1 with DirectPosition2D

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);
}
Also used : CoordinateOperation(org.opengis.referencing.operation.CoordinateOperation) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) DirectPosition2D(org.apache.sis.geometry.DirectPosition2D) Test(org.junit.Test)

Example 2 with DirectPosition2D

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);
}
Also used : Matrix(org.opengis.referencing.operation.Matrix) HashMap(java.util.HashMap) DirectPosition2D(org.apache.sis.geometry.DirectPosition2D) Test(org.junit.Test)

Example 3 with DirectPosition2D

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());
}
Also used : GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) DirectPosition(org.opengis.geometry.DirectPosition) GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) DirectPosition2D(org.apache.sis.geometry.DirectPosition2D)

Example 4 with DirectPosition2D

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;
}
Also used : DirectPosition2D(org.apache.sis.geometry.DirectPosition2D)

Example 5 with DirectPosition2D

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));
    }
}
Also used : DirectPosition2D(org.apache.sis.geometry.DirectPosition2D) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Aggregations

DirectPosition2D (org.apache.sis.geometry.DirectPosition2D)25 Test (org.junit.Test)12 DependsOnMethod (org.apache.sis.test.DependsOnMethod)7 DirectPosition (org.opengis.geometry.DirectPosition)4 Rectangle2D (java.awt.geom.Rectangle2D)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Envelope2D (org.apache.sis.geometry.Envelope2D)2 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)2 MathTransform (org.opengis.referencing.operation.MathTransform)2 Matrix (org.opengis.referencing.operation.Matrix)2 WireFeed (com.sun.syndication.feed.WireFeed)1 GeoRSSModule (com.sun.syndication.feed.module.georss.GeoRSSModule)1 Channel (com.sun.syndication.feed.rss.Channel)1 Item (com.sun.syndication.feed.rss.Item)1 WireFeedInput (com.sun.syndication.io.WireFeedInput)1 XmlReader (com.sun.syndication.io.XmlReader)1 AffineTransform (java.awt.geom.AffineTransform)1