org.opengis.referencing.operation.TransformException Java Examples

The following examples show how to use org.opengis.referencing.operation.TransformException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GeometryUtils.java    From geowave with Apache License 2.0 6 votes vote down vote up
/**
 * Build a buffer around a geometry
 *
 * @param crs
 * @param geometry
 * @param distanceUnits
 * @param distance
 * @return the buffered geometry and the degrees that it was buffered
 * @throws TransformException
 */
public static final Pair<Geometry, Double> buffer(
    final CoordinateReferenceSystem crs,
    final Geometry geometry,
    final String distanceUnits,
    final double distance) throws TransformException {
  Unit<Length> unit;
  try {
    unit = lookup(distanceUnits);
  } catch (final Exception e) {
    unit = Units.METRE;
    LOGGER.warn("Cannot lookup unit of measure " + distanceUnits, e);
  }
  final double meterDistance = unit.getConverterTo(Units.METRE).convert(distance);
  final double degrees = distanceToDegrees(crs, geometry, meterDistance);
  // buffer does not respect the CRS; it uses simple cartesian math.
  // nor does buffer handle dateline boundaries
  return Pair.of(adjustGeo(crs, geometry.buffer(degrees)), degrees);
}
 
Example #2
Source File: PolarStereographicTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Verifies the consistency of elliptical formulas with the spherical formulas.
 * This test compares the results of elliptical formulas with the spherical ones
 * for some random points.
 *
 * @throws FactoryException if an error occurred while creating the map projection.
 * @throws TransformException if an error occurred while projecting a coordinate.
 */
private void compareEllipticalWithSpherical(final CoordinateDomain domain, final double latitudeOfOrigin,
        final long randomSeed) throws FactoryException, TransformException
{
    createCompleteProjection(new PolarStereographicA(),
            6371007,            // Semi-major axis length
            6371007,            // Semi-minor axis length
            0.5,                // Central meridian
            latitudeOfOrigin,   // Latitude of origin
            NaN,                // Standard parallel 1 (none)
            NaN,                // Standard parallel 2 (none)
            0.994,              // Scale factor
            200,                // False easting
            100);               // False northing
    tolerance = Formulas.LINEAR_TOLERANCE;
    compareEllipticalWithSpherical(domain, randomSeed);
}
 
Example #3
Source File: GridGeometry.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Computes the envelope with the given coordinate reference system. This method is invoked from constructors.
 * The {@link #extent}, {@link #gridToCRS} and {@link #cornerToCRS} fields must be set before this method is invoked.
 *
 * @param  specified  the transform specified by the user. This is not necessarily {@link #gridToCRS}.
 * @param  crs        the coordinate reference system to declare in the envelope.
 * @param  limits     if non-null, intersect with that envelope. The CRS must be the same than {@code crs}.
 */
private ImmutableEnvelope computeEnvelope(final MathTransform specified, final CoordinateReferenceSystem crs,
        final Envelope limits) throws TransformException
{
    final GeneralEnvelope env;
    if (extent != null && cornerToCRS != null) {
        env = extent.toCRS(cornerToCRS, specified, limits);
        env.setCoordinateReferenceSystem(crs);
        if (limits != null) {
            env.intersect(limits);
        }
    } else if (crs != null) {
        env = new GeneralEnvelope(crs);
        env.setToNaN();
    } else {
        return null;
    }
    return new ImmutableEnvelope(env);
}
 
Example #4
Source File: ZonedGridSystemTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests converting a point using the <cite>Transverse Mercator Zoned Grid System</cite> projection.
 *
 * @throws FactoryException if an error occurred while creating the map projection.
 * @throws TransformException if an error occurred while transforming a coordinate.
 */
@Test
public void testUTM() throws FactoryException, TransformException {
    createProjection(true);
    /*
     * Verify parameters.
     */
    final ParameterValueGroup values = ((Parameterized) transform).getParameterValues();
    assertEquals(0.9996, values.parameter(Constants.SCALE_FACTOR) .doubleValue(Units.UNITY ), 0);
    assertEquals(500000, values.parameter(Constants.FALSE_EASTING).doubleValue(Units.METRE ), 0);
    assertEquals(  -180, values.parameter("Initial longitude")    .doubleValue(Units.DEGREE), 0);
    assertEquals(     6, values.parameter("Zone width")           .doubleValue(Units.DEGREE), 0);
    /*
     * Tests projection of CN Tower coordinate, which is in UTM zone 17.
     */
    verifyTransform(new double[] {
        -79 - (23 - 13.70/60)/60,   // 79°23′13.70″W
         43 + (38 + 33.24/60)/60    // 43°38′33.24″N
    }, new double[] {
        17630698.19, 4833450.51
    });
}
 
Example #5
Source File: EquirectangularTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests conversion of random points. This test is actually of limited interest since the Equirectangular
 * projection is implemented by an affine transform, which has been tested elsewhere.
 *
 * @throws FactoryException if an error occurred while creating the map projection.
 * @throws TransformException if an error occurred while projecting a point.
 */
@Test
public void testRandomPoints() throws FactoryException, TransformException {
    createCompleteProjection(new Equirectangular(),
            WGS84_A,    // Semi-major axis length
            WGS84_B,    // Semi-minor axis length
            0.5,        // Central meridian
            0,          // Latitude of origin (none)
            20,         // Standard parallel 1
            NaN,        // Standard parallel 2
            NaN,        // Scale factor (none)
            200,        // False easting
            100);       // False northing
    tolerance = Formulas.LINEAR_TOLERANCE;  // Not NORMALIZED_TOLERANCE since this is not a NormalizedProjection.
    derivativeDeltas = new double[] {100, 100};
    verifyInDomain(CoordinateDomain.GEOGRAPHIC, 0);
}
 
Example #6
Source File: LinearInterpolator1DTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Transforms point and verifies that the result is consistent with the inverse transform and the derivative.
 */
private void verifyConsistency(final double min, final double max, final long randomSeed) throws TransformException {
    transform = LinearInterpolator1D.create(preimage, values);
    tolerance = 1E-10;
    derivativeDeltas = new double[] {0.1};
    /*
     * Convert a x value to y value, then back to x.
     * This code is provided mostly as a convenience place where to step into with a debugger.
     */
    if (isInverseTransformSupported) {
        final double xm = (min + max) / 2;
        final double ym = ((MathTransform1D) transform).transform(xm);
        assertEquals(xm,  ((MathTransform1D) transform.inverse()).transform(ym), tolerance);
    }
    /*
     * The actual test: 100 random values, test all transform methods
     * (including those working on arrays), verify consistency and derivatives.
     */
    verifyInDomain(new double[] {min}, new double[] {max}, new int[] {100}, new Random(randomSeed));
}
 
Example #7
Source File: GeometryCoordinateTransform.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Transforms the given sequence of coordinate tuples, producing a new sequence of tuples.
 * This method tries to transform coordinates in batches, in order to reduce the amount of
 * calls to {@link MathTransform#transform(double[], int, double[], int, int)}.
 *
 * @param  sequence   sequence of coordinate tuples to transform.
 * @param  minPoints  minimum number of points to preserve.
 * @return the transformed sequence of coordinate tuples.
 * @throws TransformException if an error occurred while transforming a tuple.
 */
@Override
protected CoordinateSequence transform(final CoordinateSequence sequence, final int minPoints) throws TransformException {
    final int srcDim   = transform.getSourceDimensions();
    final int tgtDim   = transform.getTargetDimensions();
    final int maxDim   = Math.max(srcDim, tgtDim);
    final int count    = sequence.size();
    final int capacity = Math.max(4, Math.min(100, count));
    final CoordinateSequence out = coordinateFactory.create(count, sequence.getDimension());
    if (coordinates == null || coordinates.length / maxDim < capacity) {
        coordinates = new double[capacity * maxDim];
    }
    for (int base=0, n; (n = Math.min(count - base, capacity)) > 0; base += n) {
        int batch = n * srcDim;
        for (int i=0; i<batch; i++) {
            coordinates[i] = sequence.getOrdinate(base + i/srcDim, i % srcDim);
        }
        transform.transform(coordinates, 0, coordinates, 0, n);
        batch = n * tgtDim;
        for (int i=0; i<batch; i++) {
            out.setOrdinate(base + i/tgtDim, i % tgtDim, coordinates[i]);
        }
    }
    return out;
}
 
Example #8
Source File: CopyTransformTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests transform from 3D to 2D.
 *
 * @throws TransformException should never happen.
 */
@Test
@DependsOnMethod("testConstantDimension")
public void testDimensionReduction() throws TransformException {
    isInverseTransformSupported = false;
    create(3, 0, 1);
    assertIsNotIdentity(transform);

    final double[] source = generateRandomCoordinates();
    final double[] target = new double[source.length * 2/3];
    for (int i=0,j=0; i<source.length; i++) {
        target[j++] = source[i++];
        target[j++] = source[i++];
        // Skip one i (in the for loop).
    }
    verifyTransform(source, target);

    makeProjectiveTransform();
    verifyTransform(source, target);
}
 
Example #9
Source File: AlbersEqualAreaTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests a few "special" points which need special care in inverse projection algorithm.
 *
 * @throws FactoryException if an error occurred while creating the map projection.
 * @throws TransformException if an error occurred while projecting a point.
 */
@Test
@DependsOnMethod("testEllipse")
public void testSingularity() throws FactoryException, TransformException {
    createCompleteProjection(new org.apache.sis.internal.referencing.provider.AlbersEqualArea(),
            WGS84_A,    // Semi-major axis length
            WGS84_B,    // Semi-minor axis length
            0,          // Central meridian
            0,          // Latitude of origin
            0,          // Standard parallel 1
            2,          // Standard parallel 2
            NaN,        // Scale factor (none)
            0,          // False easting
            0);         // False northing

    tolerance = Formulas.LINEAR_TOLERANCE;
    verifyTransform(new double[] {0,        0,
                                  0,      +90,
                                  0,      -90},
                    new double[] {0,        0,
                                  0, +6420271.594575703,    // Computed empirically with SIS (not from an external source).
                                  0, -6309429.217});
}
 
Example #10
Source File: SpecializableTransform.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Inverse transforms a list of coordinate points.
 * The transformed points are written directly in the destination array.
 */
@Override
public void transform(double[] srcPts, int srcOff, final double[] dstPts, final int dstOff, final int numPts)
        throws TransformException
{
    if (numPts <= 0) return;
    final int srcInc = global.getSourceDimensions();
    final int dstInc = global.getTargetDimensions();
    if (srcPts == dstPts) {
        final int srcEnd = srcOff + numPts*srcInc;
        if (srcEnd > dstOff || dstOff + numPts*dstInc > srcOff) {
            srcPts = Arrays.copyOfRange(srcPts, srcOff, srcEnd);
            srcOff = 0;
        }
    }
    final double[] refPts = srcPts;
    transform((tr, src, dst, num) -> tr.transform(refPts, src, dstPts, dst, num),
              dstPts, srcOff, dstOff, srcInc, dstInc, numPts);
}
 
Example #11
Source File: TransformSeparatorTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests separation of a pass through transform containing another pass through transform.
 *
 * @throws FactoryException if an error occurred while creating a new transform.
 * @throws TransformException if an error occurred while transforming coordinates for comparison purpose.
 */
@Test
@DependsOnMethod("testConcatenatedPassThroughTransform")
public void testNestedPassThroughTransform() throws FactoryException, TransformException {
    final MathTransform nonLinear    = new PseudoTransform(3, 2);
    final MathTransform passthrough1 = MathTransforms.passThrough(2, nonLinear, 1);
    final MathTransform concatenated = new ConcatenatedTransform(MathTransforms.scale(4, 3, 2, 1, 1, 6), passthrough1);
    final MathTransform passthrough2 = new PassThroughTransform(2, concatenated, 3);
    final TransformSeparator sep = new TransformSeparator(passthrough2);
    sep.addSourceDimensionRange(3, 7);
    MathTransform mt = sep.separate();
    assertInstanceOf("separate()", ConcatenatedTransform.class, mt);
    assertMatrixEquals("Leading passthrough dimensions", Matrices.create(5, 5, new double[] {
        3, 0, 0, 0, 0,
        0, 2, 0, 0, 0,
        0, 0, 1, 0, 0,
        0, 0, 0, 1, 0,
        0, 0, 0, 0, 1}), MathTransforms.getMatrix(((ConcatenatedTransform) mt).transform1), STRICT);

    mt = ((ConcatenatedTransform) mt).transform2;
    assertInstanceOf("subTransform", PassThroughTransform.class, mt);
    final PassThroughTransform ps = ((PassThroughTransform) mt);
    assertEquals("firstAffectedCoordinate", 1, ps.firstAffectedCoordinate);
    assertEquals("numTrailingCoordinates",  0, ps.numTrailingCoordinates);
    assertSame  ("subTransform",    nonLinear, ps.subTransform);
}
 
Example #12
Source File: LogarithmicTransform1DTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the concatenation of a logarithmic operation with the exponential one.
 *
 * @throws TransformException should never happen.
 */
@Test
@DependsOnMethod("testSingleWithOffset")
public void testLogarithmicConcatenation() throws TransformException {
    transform = MathTransforms.concatenate(
            LogarithmicTransform1D.create(8, C0),
            ExponentialTransform1D.create(10, ExponentialTransform1DTest.SCALE));
    validate();

    final double lnBase = log(8);
    final double[] values = generateRandomCoordinates(CoordinateDomain.RANGE_10, 0);
    final double[] expected = new double[values.length];
    for (int i=0; i<values.length; i++) {
        final double value = abs(values[i]) + 0.001;        // Makes the values valid for logarithms.
        values[i] = value;
        expected[i] = ExponentialTransform1DTest.SCALE * pow(10, log(value) / lnBase + C0);
    }
    verifyTransform(values, expected);
}
 
Example #13
Source File: ConfigurationDtoPostProcessor.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
private double getUnitLength(String mapCrsKey, Bbox mapBounds) throws LayerException {
	try {
		if (null == mapBounds) {
			throw new LayerException(ExceptionCode.MAP_MAX_EXTENT_MISSING);
		}
		Crs crs = geoService.getCrs2(mapCrsKey);
		GeodeticCalculator calculator = new GeodeticCalculator(crs);
		Coordinate center = new Coordinate(0.5 * (mapBounds.getX() + mapBounds.getMaxX()),
				0.5 * (mapBounds.getY() + mapBounds.getMaxY()));
		calculator.setStartingPosition(new DirectPosition2D(crs, center.getX(), center.getY()));
		calculator.setDestinationPosition(new DirectPosition2D(crs, center.getX() + 1, center.getY()));
		return calculator.getOrthodromicDistance();
	} catch (TransformException e) {
		throw new LayerException(e, ExceptionCode.TRANSFORMER_CREATE_LAYER_TO_MAP_FAILED);
	}
}
 
Example #14
Source File: CoordinateOperationFinderTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests a transformation with a three-dimensional geographic source CRS.
 * This method verifies with both a three-dimensional and a two-dimensional target CRS.
 *
 * @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
@DependsOnMethod("testGeocentricTranslationInGeographic2D")
public void testGeocentricTranslationInGeographic3D() throws ParseException, FactoryException, TransformException {
    final GeographicCRS sourceCRS = (GeographicCRS) parse(
            "GeodeticCRS[“NAD27”,\n" +
            "  Datum[“North American Datum 1927”,\n" +
            "    Ellipsoid[“Clarke 1866”, 6378206.4, 294.9786982138982],\n" +
            "    ToWGS84[-8, 160, 176]]," +                                     // See comment in above test.
            "  CS[ellipsoidal, 3],\n" +
            "    Axis[“Latitude (φ)”, NORTH, Unit[“degree”, 0.017453292519943295]],\n" +
            "    Axis[“Longitude (λ)”, EAST, Unit[“degree”, 0.017453292519943295]],\n" +
            "    Axis[“Height (h)”, UP, Unit[“m”, 1]]]");

    testGeocentricTranslationInGeographicDomain("Geocentric translations (geog3D domain)",
            sourceCRS, CommonCRS.WGS84.geographic3D());

    isInverseTransformSupported = false;                // Because lost of height values changes (φ,λ) results.
    testGeocentricTranslationInGeographicDomain("Geocentric translations (geog3D domain)",
            sourceCRS, CommonCRS.WGS84.geographic());
}
 
Example #15
Source File: InterpolatedGeocentricTransformTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests transformation of sample point from RGF93 to NTF.
 * We call this transformation "forward" because it uses the grid values directly,
 * without doing first an approximation followed by an iteration.
 *
 * @throws FactoryException if an error occurred while loading the grid.
 * @throws TransformException if an error occurred while transforming the coordinate.
 */
@Test
public void testForwardTransform() throws FactoryException, TransformException {
    createGeodeticTransformation();   // Create the inverse of the transform we are interrested in.
    transform = transform.inverse();
    isInverseTransformSupported = false;
    verifyTransform(FranceGeocentricInterpolationTest.samplePoint(3),
                    FranceGeocentricInterpolationTest.samplePoint(1));
    validate();
    /*
     * Input:     2.424971108333333    48.84444583888889
     * Expected:  2.425671861111111    48.84451225
     * Actual:    2.425671863799633    48.844512255374376   (interpolated geocentric transform)
     * Actual:    2.4256718922236735   48.84451219111167    (interpolated Molodensky transform)
     */
}
 
Example #16
Source File: RasterUtils.java    From geowave with Apache License 2.0 6 votes vote down vote up
private static Coordinate[] getWorldCoordinates(
    final double minX,
    final double minY,
    final double maxX,
    final double maxY,
    final int numPointsPerSegment,
    final MathTransform gridToCRS) throws MismatchedDimensionException, TransformException {
  final Point2D[] gridCoordinates =
      getGridCoordinates(minX, minY, maxX, maxY, numPointsPerSegment);
  final Coordinate[] worldCoordinates = new Coordinate[gridCoordinates.length];
  for (int i = 0; i < gridCoordinates.length; i++) {
    final DirectPosition2D worldPt = new DirectPosition2D();
    final DirectPosition2D dp = new DirectPosition2D(gridCoordinates[i]);
    gridToCRS.transform(dp, worldPt);
    worldCoordinates[i] = new Coordinate(worldPt.getX(), worldPt.getY());
  }
  return worldCoordinates;
}
 
Example #17
Source File: CylindricalEqualAreaTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests <cite>Lambert Cylindrical Equal Area (Spherical)</cite> projection.
 * The difference between this test and {@link #testSpherical()} is that this case shall
 * compute the radius of the conformal sphere instead than using the semi-major axis length.
 * The result near the equator are almost the same however.
 *
 * @throws FactoryException if an error occurred while creating the map projection.
 * @throws TransformException if an error occurred while projecting a point.
 */
@Test
@DependsOnMethod("testSpherical")
public void testSphericalWithConformalSphereRadius() throws FactoryException, TransformException {
    createCompleteProjection(new LambertCylindricalEqualAreaSpherical(),
            WGS84_A,    // Semi-major axis length
            WGS84_B,    // Semi-minor axis length
            0,          // Central meridian
            NaN,        // Latitude of origin
            0,          // Standard parallel 1
            NaN,        // Standard parallel 2
            NaN,        // Scale factor (none)
            0,          // False easting
            0);         // False northing
    tolerance = Formulas.LINEAR_TOLERANCE;
    final double λ = 2;
    final double φ = 1;
    final double x = 222390.10;             // Anti-regression values (not from an external source).
    final double y = 111189.40;
    verifyTransform(new double[] {λ, φ,  -λ, φ,  λ, -φ,  -λ, -φ},
                    new double[] {x, y,  -x, y,  x, -y,  -x, -y});
    testDerivative();
}
 
Example #18
Source File: CylindricalEqualArea.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * <div class="note"><b>Note:</b>
 * This method must be overridden because the {@link CylindricalEqualArea} class
 * overrides the {@link NormalizedProjection} default implementation.</div>
 */
@Override
public void transform(final double[] srcPts, int srcOff,
                      final double[] dstPts, int dstOff, int numPts)
        throws TransformException
{
    if (srcPts != dstPts || srcOff != dstOff) {
        super.transform(srcPts, srcOff, dstPts, dstOff, numPts);
    } else {
        dstOff--;
        while (--numPts >= 0) {
            final double φ = dstPts[dstOff += DIMENSION];       // Same as srcPts[srcOff + 1].
            dstPts[dstOff] = sin(φ);
        }
    }
}
 
Example #19
Source File: InterpolatedTransformTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the derivatives at sample points outside the grid. Those derivatives must be consistent
 * in order to allow inverse transformation to work when the initial point is outside the grid.
 *
 * @throws TransformException if an error occurred while transforming the coordinate.
 */
@Test
@DependsOnMethod("testDerivative")
public void testExtrapolations() throws TransformException {
    createSinusoidal(-50);
    final double[] point = new double[SinusoidalShiftGrid.DIMENSION];
    derivativeDeltas = new double[] {0.002, 0.002};
    isInverseTransformSupported = false;                                                // For focusing on a single aspect.
    tolerance = 1E-10;
    for (int i=0; i<=4; i++) {
        switch (i) {
            default: throw new AssertionError(i);
            case 0: point[0] = -50; point[1] =  40; break;       // Point outside grid on the left.
            case 1: point[0] = 200; point[1] =  60; break;       // Point outside grid on the right.
            case 2: point[0] =  20; point[1] = -50; break;       // Point outside grid on the top.
            case 3: point[0] = -80; point[1] = 230; break;       // Point outside grid two sides.
            case 4: point[0] =  80; point[1] = 185;              // Point outside grid on the bottom.
                    tolerance = 0.3; break;
        }
        verifyDerivative(point);
    }
}
 
Example #20
Source File: MilitaryGridReferenceSystemTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests iteration over all codes in a given area of interest. The geographic area used for this test is based on
 * <a href="https://www.ff-reichertshausen.de/cms/wp-content/uploads/2012/10/utmmeldegitter.jpg">this picture</a>
 * (checked on March 2017).
 *
 * <div class="note"><b>Tip:</b> in case of test failure, see {@link LocationViewer} as a debugging tool.</div>
 *
 * @throws TransformException if an error occurred while computing the coordinate.
 */
@Test
@DependsOnMethod("testEncodeUTM")
public void testIteratorNorthUTM() throws TransformException {
    /*
     * Following is the list of MGRS references that we expect to find in the above area of interest.
     * The references are distributed in 3 zones (31, 32 and 33) and 3 latitude bands (T, U and V).
     * This test includes the Norway special case: between 56° and 64°N (latitude band V), zone 32
     * is widened to 9° at the expense of zone 31. The test needs to be insensitive to iteration order.
     */
    testIterator(new Envelope2D(CommonCRS.defaultGeographic(), 5, 47, 8, 10), Arrays.asList(
        "31TFN", "31TGN",    "32TKT", "32TLT", "32TMT", "32TNT", "32TPT", "32TQT",    "33TTN", "33TUN",
        "31TFP", "31TGP",    "32TKU", "32TLU", "32TMU", "32TNU", "32TPU", "32TQU",    "33TTP", "33TUP",
        "31UFP", "31UGP",    "32UKU", "32ULU", "32UMU", "32UNU", "32UPU", "32UQU",    "33UTP", "33UUP",
        "31UFQ", "31UGQ",    "32UKV", "32ULV", "32UMV", "32UNV", "32UPV", "32UQV",    "33UTQ", "33UUQ",
        "31UFR", "31UGR",    "32UKA", "32ULA", "32UMA", "32UNA", "32UPA", "32UQA",    "33UTR", "33UUR",
        "31UFS", "31UGS",    "32UKB", "32ULB", "32UMB", "32UNB", "32UPB", "32UQB",    "33UTS", "33UUS",
        "31UFT", "31UGT",    "32UKC", "32ULC", "32UMC", "32UNC", "32UPC", "32UQC",    "33UTT", "33UUT",
        "31UFU", "31UGU",    "32UKD", "32ULD", "32UMD", "32UND", "32UPD", "32UQD",    "33UTU", "33UUU",
        "31UFV", "31UGV",    "32UKE", "32ULE", "32UME", "32UNE", "32UPE", "32UQE",    "33UTV", "33UUV",
        "31UFA",                      "32ULF", "32UMF", "32UNF", "32UPF",             "33UUA",
        "31UFB",                      "32ULG", "32UMG", "32UNG", "32UPG",             "33UUB",
        "31UFC",                      "32ULH", "32UMH", "32UNH", "32UPH",             "33UUC",
        /* Norway case */    "32VKH", "32VLH", "32VMH", "32VNH", "32VPH",             "33VUC",
        /* Norway case */    "32VKJ", "32VLJ", "32VMJ", "32VNJ", "32VPJ",             "33VUD"));
}
 
Example #21
Source File: JTSTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests various {@code transform} methods. This includes (sometime indirectly):
 *
 * <ul>
 *   <li>{@link JTS#transform(Geometry, CoordinateReferenceSystem)}</li>
 *   <li>{@link JTS#transform(Geometry, CoordinateOperation)}</li>
 *   <li>{@link JTS#transform(Geometry, MathTransform)}</li>
 * </ul>
 *
 * @throws FactoryException if an EPSG code can not be resolved.
 * @throws TransformException if a coordinate can not be transformed.
 */
@Test
public void testTransform() throws FactoryException, TransformException {
    final GeometryFactory factory = new GeometryFactory();
    final Geometry in = factory.createPoint(new Coordinate(5, 6));
    /*
     * Test exception when transforming geometry without CRS.
     */
    try {
        JTS.transform(in, CommonCRS.WGS84.geographic());
        fail("Geometry has no CRS, transform should have failed.");
    } catch (TransformException ex) {
        assertNotNull(ex.getMessage());
    }
    /*
     * Test axes inversion transform.
     */
    in.setUserData(CommonCRS.WGS84.normalizedGeographic());
    Geometry out = JTS.transform(in, CommonCRS.WGS84.geographic());
    assertTrue(out instanceof Point);
    assertEquals(6, ((Point) out).getX(), STRICT);
    assertEquals(5, ((Point) out).getY(), STRICT);
    assertEquals(CommonCRS.WGS84.geographic(), out.getUserData());
    /*
     * Test affine transform. User data must be preserved.
     */
    final AffineTransform2D trs = new AffineTransform2D(1, 0, 0, 1, 10, 20);
    out = JTS.transform(in, trs);
    assertTrue(out instanceof Point);
    assertEquals(15, ((Point) out).getX(), STRICT);
    assertEquals(26, ((Point) out).getY(), STRICT);
}
 
Example #22
Source File: TransformTestCase.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the transformation of an envelope or rectangle. This is a relatively simple test case
 * working in the two-dimensional space only, with a coordinate operation of type "conversion"
 * (not a "transformation") and with no need to adjust for poles.
 *
 * @throws FactoryException if an error occurred while creating the operation.
 * @throws TransformException if an error occurred while transforming the envelope.
 */
@Test
public final void testTransform() throws FactoryException, TransformException {
    final ProjectedCRS    targetCRS  = CommonCRS.WGS84.universal(10, -123.5);
    final GeographicCRS   sourceCRS  = targetCRS.getBaseCRS();
    final Conversion      conversion = targetCRS.getConversionFromBase();
    final MathTransform2D transform  = (MathTransform2D) conversion.getMathTransform();
    /*
     * Transforms envelopes using MathTransform. Geographic coordinates are in (latitude, longitude) order.
     * Opportunistically check that the transform using a CoordinateOperation object produces the same result.
     */
    final G rectλφ = createFromExtremums(sourceCRS, -20, -126, 40, -120);
    final G rectXY = transform(targetCRS, transform, rectλφ);
    assertEquals("Conversion should produce the same result.", rectXY, transform(conversion, rectλφ));
    /*
     * Expected values are determined empirically by projecting many points.
     * Those values are the same than in EnvelopesTest.testTransform().
     */
    final G expected = createFromExtremums(targetCRS, 166021.56, -2214294.03,
                                                      833978.44,  4432069.06);
    assertGeometryEquals(expected, rectXY, LINEAR_TOLERANCE, LINEAR_TOLERANCE);
    /*
     * Test the inverse conversion.
     * Final envelope should be slightly bigger than the original.
     */
    final G rectBack = transform(sourceCRS, transform.inverse(), rectXY);
    assertTrue("Transformed envelope should not be smaller than the original one.", contains(rectBack, rectλφ));
    assertGeometryEquals(rectλφ, rectBack, 0.05, 1.0);
}
 
Example #23
Source File: MilitaryGridReferenceSystemTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests iterating over part of North pole, in an area between 10°W to 70°E.
 * This area is restricted to the lower part of UPS projection, which allow
 * {@code IteratorAllZones} to simplify to a single {@code IteratorOneZone}.
 *
 * <div class="note"><b>Tip:</b> in case of test failure, see {@link LocationViewer} as a debugging tool.</div>
 *
 * @throws TransformException if an error occurred while computing the coordinate.
 */
@Test
@DependsOnMethod("testEncodeUPS")
public void testIteratorNorthPole() throws TransformException {
    testIterator(new Envelope2D(CommonCRS.defaultGeographic(), -10, 85, 80, 5), Arrays.asList(
        "YZG", "ZAG", "ZBG", "ZCG",
        "YZF", "ZAF", "ZBF", "ZCF", "ZFF", "ZGF", "ZHF",
        "YZE", "ZAE", "ZBE", "ZCE", "ZFE", "ZGE", "ZHE",
        "YZD", "ZAD", "ZBD", "ZCD", "ZFD", "ZGD",
        "YZC", "ZAC", "ZBC", "ZCC", "ZFC",
        "YZB", "ZAB", "ZBB", "ZCB"));
}
 
Example #24
Source File: ServicesForMetadataTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests (indirectly) {@link ServicesForMetadata#setBounds(Envelope, DefaultVerticalExtent)}
 * from an ellipsoidal height
 *
 * @throws TransformException should never happen.
 */
@Test
public void testSetVerticalBoundsFromEllipsoid() throws TransformException {
    final DefaultVerticalExtent extent = new DefaultVerticalExtent();
    extent.setBounds(createEnvelope(HardCodedCRS.WGS84_3D));
    verifyVerticalExtent(CommonCRS.Vertical.ELLIPSOIDAL, extent);
}
 
Example #25
Source File: Projection.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public Geometry transform(final Geometry g, final boolean translate) {
	Geometry geom = GeometryUtils.GEOMETRY_FACTORY.createGeometry(g);
	if (transformer != null) {
		try {
			geom = transformer.transform(g);
		} catch (final TransformException e) {
			e.printStackTrace();
		}
	}
	if (translate) {
		translate(geom);
		convertUnit(geom);
	}
	return geom;
}
 
Example #26
Source File: CartesianToPolarTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests coordinate conversions in the cylindrical case.
 *
 * @throws FactoryException if the transform can not be created.
 * @throws TransformException if a coordinate can not be transformed.
 */
@Test
@DependsOnMethod("testConversion")
public void testCylindricalConversion() throws FactoryException, TransformException {
    transform = CartesianToPolar.INSTANCE.passthrough(PolarToCartesianTest.factory());
    tolerance = 1E-12;
    final double[][] data = PolarToCartesianTest.testData(true);
    verifyTransform(data[1], data[0]);
}
 
Example #27
Source File: PassThroughTransform.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the derivative of this transform at a point.
 *
 * @return {@inheritDoc}
 * @throws TransformException if the {@linkplain #subTransform sub-transform} failed.
 */
@Override
public Matrix derivative(final DirectPosition point) throws TransformException {
    final int nSkipped = firstAffectedCoordinate + numTrailingCoordinates;
    final int transDim = subTransform.getSourceDimensions();
    ensureDimensionMatches("point", transDim + nSkipped, point);
    final GeneralDirectPosition subPoint = new GeneralDirectPosition(transDim);
    for (int i=0; i<transDim; i++) {
        subPoint.coordinates[i] = point.getOrdinate(i + firstAffectedCoordinate);
    }
    return expand(MatrixSIS.castOrCopy(subTransform.derivative(subPoint)),
            firstAffectedCoordinate, numTrailingCoordinates, 0);
}
 
Example #28
Source File: TransformResultComparator.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Delegates to the tested implementation and verifies that the values are equal
 * to the ones provided by the reference implementation.
 */
@Override
public void transform(double[] srcPts, int srcOff, double[] dstPts, int dstOff, int numPts) throws TransformException {
    final double[] expected = new double[numPts * reference.getTargetDimensions()];
    reference.transform(srcPts, srcOff, expected, 0, numPts);
    tested.transform(srcPts, srcOff, dstPts, dstOff, numPts);
    assertArrayEquals("transform(double[], …, double[], …)", expected,
            Arrays.copyOfRange(dstPts, dstOff, dstOff + numPts * tested.getTargetDimensions()), tolerance);
}
 
Example #29
Source File: PolarToCartesianTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests coordinate conversions in the polar case.
 *
 * @throws FactoryException if the transform can not be created.
 * @throws TransformException if a coordinate can not be transformed.
 */
@Test
public void testConversion() throws FactoryException, TransformException {
    transform = PolarToCartesian.INSTANCE.completeTransform(factory());
    tolerance = 1E-12;
    final double[][] data = testData(false);
    verifyTransform(data[0], data[1]);
}
 
Example #30
Source File: MolodenskyTransformTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the derivative of the Molodensky transformation.
 *
 * @throws FactoryException if an error occurred while creating a transform step.
 * @throws TransformException if the transformation failed.
 */
@Test
@DependsOnMethod("testAbridgedMolodenskyDerivative")
public void testMolodenskyDerivative() throws FactoryException, TransformException {
    create(false);
    verifyDerivative( 0,  0,  0);
    verifyDerivative(-3, 30,  7);
    verifyDerivative(+6, 60, 20);
}