/** Returns a deep copy of this position. */ @Override public GeneralDirectPosition clone() { return new GeneralDirectPosition(ordinates); } }
/** * Format the specified coordinates using the specified formatter, which should be an instance * of {@link CoordinateFormat}. */ private static String format(final Format cf, final double longitude, final double latitude) { return cf.format(new GeneralDirectPosition(longitude, latitude)); }
/** * Gets the derivative of this transform at a point. This method delegates to the {@link * #derivative(DirectPosition)} method because the transformation steps {@link #transform1} and * {@link #transform2} may not be instances of {@link MathTransform2D}. * * @param point The coordinate point where to evaluate the derivative. * @return The derivative at the specified point as a 2×2 matrix. * @throws TransformException if the derivative can't be evaluated at the specified point. */ @Override public Matrix derivative(final Point2D point) throws TransformException { return derivative(new GeneralDirectPosition(point)); }
/** * Creates a mapped position with {@linkplain #getSource source} and {@linkplain #getTarget * target} position of the specified dimension. The initial coordinate values are 0. */ public MappedPosition(final int dimension) { if (dimension == 2) { source = new DirectPosition2D(); target = new DirectPosition2D(); } else { source = new GeneralDirectPosition(dimension); target = new GeneralDirectPosition(dimension); } }
/** * A coordinate position consisting of all the {@linkplain #getMaximum maximal ordinates} for * each dimension for all points within the {@code Envelope}. * * @return The upper corner. */ @Override public DirectPosition getUpperCorner() { final int dim = ordinates.length / 2; final GeneralDirectPosition position = new GeneralDirectPosition(dim); System.arraycopy(ordinates, dim, position.ordinates, 0, dim); position.setCoordinateReferenceSystem(crs); return position; }
/** * A coordinate position consisting of all the {@linkplain #getMinimum minimal ordinates} for * each dimension for all points within the {@code Envelope}. * * @return The lower corner. */ @Override public DirectPosition getLowerCorner() { final int dim = ordinates.length / 2; final GeneralDirectPosition position = new GeneralDirectPosition(dim); System.arraycopy(ordinates, 0, position.ordinates, 0, dim); position.setCoordinateReferenceSystem(crs); return position; }
/** * Returns a new point with the same coordinates than this one, but transformed in the {@code * sourceCRS} given at {@linkplain #TransformedDirectPosition(CoordinateReferenceSystem, * CoordinateReferenceSystem, Hints) construction time}. This method never returns {@code this}, * so the returned point usually doesn't need to be cloned. * * @return The same position than {@code this}, but transformed in the source CRS. * @throws TransformException if a coordinate transformation was required and failed. * @since 2.3 */ public DirectPosition inverseTransform() throws TransformException { if (defaultCRS != null) { return inverseTransform(defaultCRS); } else { return new GeneralDirectPosition(this); } }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated modifiable */ public Object parse(ElementInstance instance, Node node, Object value) throws Exception { DirectPosition dp = null; if ("pos".equals(instance.getName())) { String[] CP = instance.getText().split(" "); double[] coordinates = new double[CP.length]; int c = 0; for (String coord : CP) { coordinates[c++] = Double.parseDouble(coord.trim()); } dp = new GeneralDirectPosition(coordinates); } return dp; }
public DirectPosition getUpperCorner() { return new GeneralDirectPosition(getMaxX(), getMaxY()); }
public DirectPosition getLowerCorner() { return new GeneralDirectPosition(getMinX(), getMinY()); }
/** * A coordinate position consisting of all the {@linkplain #getCenter(int) middle ordinates} for * each dimension for all points within the {@code Envelope}. * * @return The median coordinates. * @since 2.5 */ public DirectPosition getMedian() { final GeneralDirectPosition position = new GeneralDirectPosition(ordinates.length / 2); for (int i = position.ordinates.length; --i >= 0; ) { position.ordinates[i] = getMedian(i); } position.setCoordinateReferenceSystem(crs); return position; }
/** * Transforms a three-dimensional point and compare the result with the expected one-dimensional * value. * * @param transform The transform to test. * @param x The x value to transform. * @param y The y value to transform. * @param z The z value to transform. * @param ez The expected z value. */ public static void assertTransformEquals3_1( final MathTransform transform, final double x, final double y, final double z, final double ez) throws TransformException { final GeneralDirectPosition source = new GeneralDirectPosition(x, y, z); final GeneralDirectPosition target = new GeneralDirectPosition(1); assertSame(target, transform.transform(source, target)); final String message = "Expected (" + ez + "), " + "transformed=(" + target.ordinates[0] + ")"; assertEquals(message, ez, target.ordinates[0], 1E-2); // Greater tolerance level for Z. }
/** Transforms the specified {@code ptSrc} and stores the result in {@code ptDst}. */ public DirectPosition transform(final DirectPosition ptSrc, DirectPosition ptDst) { if (ptDst == null) { ptDst = new GeneralDirectPosition(2); } else { final int dimension = ptDst.getDimension(); if (dimension != 2) { throw new MismatchedDimensionException( Errors.format(ErrorKeys.MISMATCHED_DIMENSION_$3, "ptDst", dimension, 2)); } } final double[] array = ptSrc.getCoordinate(); transform(array, 0, array, 0, 1); ptDst.setOrdinate(0, array[0]); ptDst.setOrdinate(1, array[1]); return ptDst; }
/** * Transform the provided 2D direct position into 3D (0 Ellipsoidal height assumed when * converting from {@link DefaultGeographicCRS#WGS84} to {@link DefaultGeographicCRS#WGS84_3D}). * * @param srcPosition Source 2D position * @param transformToWGS84 From source CRS to To WGS84 * @param transformFromWGS84_3D From WGS84_3D to target CRS * @return Position in target CRS as calculated by transform2 * @throws TransformException */ private static DirectPosition transformTo3D( GeneralDirectPosition srcPosition, MathTransform transformToWGS84, MathTransform transformFromWGS84_3D) throws TransformException { DirectPosition world2D = transformToWGS84.transform(srcPosition, null); DirectPosition world3D = new GeneralDirectPosition(DefaultGeographicCRS.WGS84_3D); world3D.setOrdinate(0, world2D.getOrdinate(0)); world3D.setOrdinate(1, world2D.getOrdinate(1)); world3D.setOrdinate(2, 0.0); // 0 elliposial height is assumed DirectPosition targetPosition = transformFromWGS84_3D.transform(world3D, null); return targetPosition; }
/** Gets the derivative of this transform at a point. */ @Override public Matrix derivative(final DirectPosition point) throws TransformException { final int nSkipped = firstAffectedOrdinate + numTrailingOrdinates; final int transDim = subTransform.getSourceDimensions(); final int pointDim = point.getDimension(); if (pointDim != transDim + nSkipped) { throw new MismatchedDimensionException( Errors.format( ErrorKeys.MISMATCHED_DIMENSION_$3, "point", pointDim, transDim + nSkipped)); } final GeneralDirectPosition subPoint = new GeneralDirectPosition(transDim); for (int i = 0; i < transDim; i++) { subPoint.ordinates[i] = point.getOrdinate(i + firstAffectedOrdinate); } return expand( toGMatrix(subTransform.derivative(subPoint)), firstAffectedOrdinate, numTrailingOrdinates, 0); }
@Test public void toDirectPosition() { Coordinate c = new Coordinate(40, 40); DirectPosition wrapper = JTS.toDirectPosition(c, DefaultGeographicCRS.WGS84); GeneralDirectPosition expected = new GeneralDirectPosition(DefaultGeographicCRS.WGS84); expected.setOrdinate(0, 40); expected.setOrdinate(1, 40); assertEquals(expected, wrapper); }
/** Tests the creation of the math transform from the factory. */ public void testMathTransform() throws FactoryException, TransformException { final MathTransformFactory mtFactory = ReferencingFactoryFinder.getMathTransformFactory(null); final ParameterValueGroup p = mtFactory.getDefaultParameters("Earth gravitational model"); final MathTransform mt = mtFactory.createParameterizedTransform(p); DirectPosition pos = new GeneralDirectPosition(new double[] {45, 45, 1000}); pos = mt.transform(pos, pos); assertEquals(45.000, pos.getOrdinate(0), 0.001); assertEquals(45.000, pos.getOrdinate(1), 0.001); assertEquals(1001.515, pos.getOrdinate(2), 0.001); } }
/** Tests a transformation on a {@link DirectPosition} object. */ @Test public void testDirectPositionTransform() throws FactoryException, TransformException { CoordinateReferenceSystem crs = ReferencingFactoryFinder.getCRSFactory(null).createFromWKT(WKT.UTM_10N); MathTransform t = ReferencingFactoryFinder.getCoordinateOperationFactory(null) .createOperation(DefaultGeographicCRS.WGS84, crs) .getMathTransform(); DirectPosition position = new GeneralDirectPosition(-123, 55); position = t.transform(position, position); position = t.inverse().transform(position, position); assertEquals(-123, position.getOrdinate(0), 1E-6); assertEquals(55, position.getOrdinate(1), 1E-6); }
/** * Tests {@link GeneralDirectPosition#equals} method between different implementations. The * purpose of this test is also to run the assertion in the direct position implementations. */ @Test public void testEquals() { assertTrue(GeneralDirectPosition.class.desiredAssertionStatus()); assertTrue(DirectPosition2D.class.desiredAssertionStatus()); CoordinateReferenceSystem WGS84 = DefaultGeographicCRS.WGS84; DirectPosition p1 = new DirectPosition2D(WGS84, 48.543261561072285, -123.47009555832284); GeneralDirectPosition p2 = new GeneralDirectPosition(48.543261561072285, -123.47009555832284); assertFalse(p1.equals(p2)); assertFalse(p2.equals(p1)); p2.setCoordinateReferenceSystem(WGS84); assertTrue(p1.equals(p2)); assertTrue(p2.equals(p1)); } }
/** * Test case using example from EPSG Guidance Note number 7 part 2 (May 2005), section 2.4.3.1. */ @Test public void testTranslation() throws FactoryException, TransformException { final String classification = "Geocentric translations (geog2d domain)"; final MathTransformFactory factory = ReferencingFactoryFinder.getMathTransformFactory(null); final ParameterValueGroup param = factory.getDefaultParameters(classification); param.parameter("dx").setValue(84.87); param.parameter("dy").setValue(96.49); param.parameter("dz").setValue(116.95); final MathTransform test = factory.createParameterizedTransform(param); final GeneralDirectPosition position = new GeneralDirectPosition(3); position.setOrdinate(0, 3771793.97); position.setOrdinate(1, 140253.34); position.setOrdinate(2, 5124304.35); assertSame(position, test.transform(position, position)); assertEquals(3771878.84, position.getOrdinate(0), 1E-5); assertEquals(140349.83, position.getOrdinate(1), 1E-5); assertEquals(5124421.30, position.getOrdinate(2), 1E-5); }