org.opengis.referencing.operation.MathTransform2D Java Examples
The following examples show how to use
org.opengis.referencing.operation.MathTransform2D.
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: LocationViewer.java From sis with Apache License 2.0 | 6 votes |
/** * Adds the location identified by the given label * * @param label a label that identify the location to add. * @param location the location to add to the list of locations shown by this widget. * @throws FactoryException if a transformation to the display CRS can not be obtained. * @throws TransformException if an error occurred while transforming an envelope. */ public void addLocation(final String label, final AbstractLocation location) throws FactoryException, TransformException { final Envelope envelope = location.getEnvelope(); final MathTransform2D tr = (MathTransform2D) CRS.findOperation( envelope.getCoordinateReferenceSystem(), displayCRS, null).getMathTransform(); final Shape shape = tr.createTransformedShape(new IntervalRectangle(envelope)); if (locations.putIfAbsent(label, shape) != null) { throw new IllegalArgumentException("A location is already defined for " + label); } final Rectangle2D b = shape.getBounds2D(); if (bounds == null) { bounds = b; } else { bounds.add(b); } }
Example #2
Source File: LocationViewer.java From sis with Apache License 2.0 | 5 votes |
/** * Adds all locations in the given area of interest. * * @param coder the encoder to use for computing locations and their envelopes. * @param areaOfInterest the geographic or projected area where to get locations. * @throws FactoryException if a transformation to the display CRS can not be obtained. * @throws TransformException if an error occurred while transforming an envelope. */ public void addLocations(final MilitaryGridReferenceSystem.Coder coder, final Envelope areaOfInterest) throws FactoryException, TransformException { final Iterator<String> it = coder.encode(areaOfInterest); while (it.hasNext()) { final String code = it.next(); addLocation(code, coder.decode(code)); } envelope = ((MathTransform2D) CRS.findOperation(areaOfInterest.getCoordinateReferenceSystem(), displayCRS, null) .getMathTransform()).createTransformedShape(new IntervalRectangle(areaOfInterest)); }
Example #3
Source File: TransformTestCase.java From sis with Apache License 2.0 | 5 votes |
/** * 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 #4
Source File: MathTransformTestCase.java From sis with Apache License 2.0 | 5 votes |
/** * Validates the current {@linkplain #transform transform}. This method verifies that * the transform implements {@link MathTransform1D} or {@link MathTransform2D} if the * transform dimension suggests that it should. In addition, all Apache SIS transforms * shall implement {@link Parameterized}. * * @see Validators#validate(MathTransform) */ protected final void validate() { assertNotNull("The 'transform' field shall be assigned a value.", transform); Validators.validate(transform); final int dimension = transform.getSourceDimensions(); if (transform.getTargetDimensions() == dimension) { assertEquals("transform instanceof MathTransform1D:", (transform instanceof MathTransform1D), dimension == 1); assertEquals("transform instanceof MathTransform2D:", (transform instanceof MathTransform2D), dimension == 2); } else { assertFalse("transform instanceof MathTransform1D:", transform instanceof MathTransform1D); assertFalse("transform instanceof MathTransform2D:", transform instanceof MathTransform2D); } assertInstanceOf("The transform does not implement all expected interfaces.", Parameterized.class, transform); }
Example #5
Source File: ProjectiveTransformTest.java From sis with Apache License 2.0 | 5 votes |
/** * Executed after every test in order to ensure that the {@linkplain #transform transform} * implements the {@link MathTransform1D} or {@link MathTransform2D} interface as needed. * In addition, all Apache SIS classes for linear transforms shall implement * {@link LinearTransform} and {@link Parameterized} interfaces. */ @After public final void ensureImplementRightInterface() { if (transform instanceof TransformResultComparator) { transform = ((TransformResultComparator) transform).tested; } /* * Below is a copy of MathTransformTestCase.validate(), with minor modifications * due to the fact that this class does not extend MathTransformTestCase. */ assertNotNull("The 'transform' field shall be assigned a value.", transform); Validators.validate(transform); final int dimension = transform.getSourceDimensions(); if (transform.getTargetDimensions() == dimension && !skipInterfaceCheckForDimension(dimension)) { assertEquals("MathTransform1D", dimension == 1, (transform instanceof MathTransform1D)); assertEquals("MathTransform2D", dimension == 2, (transform instanceof MathTransform2D)); } else { assertFalse("MathTransform1D", transform instanceof MathTransform1D); assertFalse("MathTransform2D", transform instanceof MathTransform2D); } assertInstanceOf("Parameterized", Parameterized.class, transform); /* * End of MathTransformTestCase.validate(). Remaining is specific to LinearTransform implementations. */ assertInstanceOf("Not a LinearTransform.", LinearTransform.class, transform); final Matrix tm = ((LinearTransform) transform).getMatrix(); assertTrue("The matrix declared by the MathTransform is not equal to the one given at creation time.", Matrices.equals(matrix, tm, tolerance, false)); assertSame("ParameterDescriptor", Affine.getProvider(transform.getSourceDimensions(), transform.getTargetDimensions(), true).getParameters(), ((Parameterized) transform).getParameterDescriptors()); }
Example #6
Source File: MathTransformsTest.java From sis with Apache License 2.0 | 5 votes |
/** * Tests the interfaces implemented by the transforms returned by {@link MathTransforms#translation(double...)}. */ @Test public void testTranslation() { MathTransform tr = MathTransforms.translation(4); assertInstanceOf("1D", MathTransform1D.class, tr); assertFalse("isIdentity", tr.isIdentity()); tr = MathTransforms.translation(4, 7); assertInstanceOf("2D", MathTransform2D.class, tr); assertFalse("isIdentity", tr.isIdentity()); }
Example #7
Source File: ConcatenatedTransformDirect2D.java From sis with Apache License 2.0 | 5 votes |
/** * Gets the derivative of this transform at a point. * * @param point the coordinate point where to evaluate the derivative. * @return the derivative at the specified point (never {@code null}). * @throws TransformException if the derivative can't be evaluated at the specified point. */ @Override public Matrix derivative(final Point2D point) throws TransformException { final MathTransform2D transform1 = (MathTransform2D) this.transform1; final MathTransform2D transform2 = (MathTransform2D) this.transform2; final Matrix matrix1 = transform1.derivative(point); final Matrix matrix2 = transform2.derivative(transform1.transform(point,null)); return Matrices.multiply(matrix2, matrix1); }
Example #8
Source File: PassThroughTransform2D.java From sis with Apache License 2.0 | 5 votes |
/** * Creates the inverse transform of this object. */ @Override public synchronized MathTransform2D inverse() throws NoninvertibleTransformException { if (inverse == null) { inverse = new PassThroughTransform2D(firstAffectedCoordinate, subTransform.inverse(), numTrailingCoordinates); inverse.inverse = this; } return (MathTransform2D) inverse; }
Example #9
Source File: SatelliteGroundTrack.java From sis with Apache License 2.0 | 4 votes |
/** * Returns the inverse of this transform, which is the enclosing {@link SatelliteGroundTrack} transform. */ @Override public MathTransform2D inverse() { return SatelliteGroundTrack.this; }
Example #10
Source File: TransformTestCase.java From sis with Apache License 2.0 | 4 votes |
/** * Tests conversions of an envelope or rectangle over a pole using a coordinate operation. * * @throws FactoryException if an error occurred while creating the operation. * @throws TransformException if an error occurred while transforming the envelope. */ @Test @DependsOnMethod("testTransform") public final void testTransformOverPole() throws FactoryException, TransformException { final ProjectedCRS sourceCRS = (ProjectedCRS) CRS.fromWKT( "PROJCS[“WGS 84 / Antarctic Polar Stereographic”,\n" + " GEOGCS[“WGS 84”,\n" + " DATUM[“World Geodetic System 1984”,\n" + " SPHEROID[“WGS 84”, 6378137.0, 298.257223563]],\n" + " PRIMEM[“Greenwich”, 0.0],\n" + " UNIT[“degree”, 0.017453292519943295]],\n" + " PROJECTION[“Polar Stereographic (variant B)”],\n" + " PARAMETER[“standard_parallel_1”, -71.0],\n" + " UNIT[“m”, 1.0]]"); final GeographicCRS targetCRS = sourceCRS.getBaseCRS(); final Conversion conversion = inverse(sourceCRS.getConversionFromBase()); final MathTransform2D transform = (MathTransform2D) conversion.getMathTransform(); /* * The rectangle to test, which contains the South pole. */ G rectangle = createFromExtremums(sourceCRS, -3943612.4042124213, -4078471.954436003, 3729092.5890516187, 4033483.085688618); /* * This is what we get without special handling of singularity point. * Note that is does not include the South pole as we would expect. * The commented out values are what we get by projecting an arbitrary * larger amount of points. */ G expected = createFromExtremums(targetCRS, // -178.4935231040927 -56.61747883535035 // empirical values -179.8650137390031, -88.99136583196396, // anti-regression values // 178.8122742080059 -40.90577500420587] // empirical values 137.9769431693009, -40.90577500420587); // anti-regression values /* * Tests what we actually get. First, test using the method working on MathTransform. * Next, test again the same transform, but using the API on Envelope objects. */ G actual = transform(targetCRS, transform, rectangle); assertGeometryEquals(expected, actual, ANGULAR_TOLERANCE, ANGULAR_TOLERANCE); /* * Using the transform(CoordinateOperation, …) method, * the singularity at South pole is taken in account. */ expected = createFromExtremums(targetCRS, -180, -90, 180, -40.905775004205864); actual = transform(conversion, rectangle); assertGeometryEquals(expected, actual, ANGULAR_TOLERANCE, ANGULAR_TOLERANCE); /* * Another rectangle containing the South pole, but this time the south * pole is almost in a corner of the rectangle */ rectangle = createFromExtremums(sourceCRS, -4000000, -4000000, 300000, 30000); expected = createFromExtremums(targetCRS, -180, -90, 180, -41.03163170198091); actual = transform(conversion, rectangle); assertGeometryEquals(expected, actual, ANGULAR_TOLERANCE, ANGULAR_TOLERANCE); /* * Another rectangle with the South pole close to the border. * This test should execute the step #3 in the transform method code. */ rectangle = createFromExtremums(sourceCRS, -2000000, -1000000, 200000, 2000000); expected = createFromExtremums(targetCRS, -180, -90, 180, -64.3861643256928); actual = transform(conversion, rectangle); assertGeometryEquals(expected, actual, ANGULAR_TOLERANCE, ANGULAR_TOLERANCE); }
Example #11
Source File: ConcatenatedTransform2D.java From sis with Apache License 2.0 | 4 votes |
/** * Creates the inverse transform of this object. */ @Override public MathTransform2D inverse() throws NoninvertibleTransformException { return (MathTransform2D) super.inverse(); }
Example #12
Source File: SpecializableTransform2D.java From sis with Apache License 2.0 | 4 votes |
/** * Returns the inverse transform of this object. */ @Override public MathTransform2D inverse() { return (MathTransform2D) super.inverse(); }
Example #13
Source File: SpecializableTransform2D.java From sis with Apache License 2.0 | 4 votes |
/** * Returns the inverse transform of this object. */ @Override public MathTransform2D inverse() throws NoninvertibleTransformException { return (MathTransform2D) super.inverse(); }
Example #14
Source File: InterpolatedMolodenskyTransform2D.java From sis with Apache License 2.0 | 4 votes |
/** * Returns the inverse transform of this transform. */ @Override public MathTransform2D inverse() { return (MathTransform2D) super.inverse(); }
Example #15
Source File: InterpolatedMolodenskyTransform2D.java From sis with Apache License 2.0 | 4 votes |
/** * Returns the inverse transform of this transform. */ @Override public MathTransform2D inverse() { return (MathTransform2D) super.inverse(); }
Example #16
Source File: ConcatenatedTransformDirect2D.java From sis with Apache License 2.0 | 4 votes |
/** * Constructs a concatenated transform. */ public ConcatenatedTransformDirect2D(final MathTransform2D transform1, final MathTransform2D transform2) { super(transform1, transform2); }
Example #17
Source File: SatelliteGroundTrack.java From sis with Apache License 2.0 | 4 votes |
/** * Returns the inverse of this transform. */ @Override public MathTransform2D inverse() { return inverse; }
Example #18
Source File: NormalizedProjection.java From sis with Apache License 2.0 | 4 votes |
/** * Returns the inverse of this math transform. */ @Override public MathTransform2D inverse() { return forward; }
Example #19
Source File: ZonedGridSystem.java From sis with Apache License 2.0 | 4 votes |
/** * Returns the inverse of this math transform. */ @Override public MathTransform2D inverse() { return forward; }
Example #20
Source File: InterpolatedGeocentricTransform2D.java From sis with Apache License 2.0 | 4 votes |
/** * Returns the inverse transform of this transform. */ @Override public MathTransform2D inverse() { return (MathTransform2D) super.inverse(); }
Example #21
Source File: InterpolatedGeocentricTransform2D.java From sis with Apache License 2.0 | 4 votes |
/** * Returns the inverse transform of this transform. */ @Override public MathTransform2D inverse() { return (MathTransform2D) super.inverse(); }
Example #22
Source File: MolodenskyTransform2D.java From sis with Apache License 2.0 | 4 votes |
/** * Returns the inverse transform of this transform. */ @Override public MathTransform2D inverse() { return (MathTransform2D) super.inverse(); }
Example #23
Source File: ConcatenatedTransformDirect2D.java From sis with Apache License 2.0 | 4 votes |
/** * Creates the inverse transform of this object. */ @Override public MathTransform2D inverse() throws NoninvertibleTransformException { return (MathTransform2D) super.inverse(); }
Example #24
Source File: ConcatenatedTransform.java From sis with Apache License 2.0 | 4 votes |
/** * Concatenates the two given transforms. * If the concatenation result works with two-dimensional input and output points, * then the returned transform will implement {@link MathTransform2D}. * Likewise if the concatenation result works with one-dimensional input and output points, * then the returned transform will implement {@link MathTransform1D}. * * <div class="note"><b>Implementation note:</b> * {@code ConcatenatedTransform} implementations are available in two versions: direct and non-direct. * The "non-direct" versions use an intermediate buffer when performing transformations; they are slower * and consume more memory. They are used only as a fallback when a "direct" version can not be created.</div> * * @param tr1 the first math transform. * @param tr2 the second math transform. * @param factory the factory which is (indirectly) invoking this method, or {@code null} if none. * @return the concatenated transform. * * @see MathTransforms#concatenate(MathTransform, MathTransform) */ public static MathTransform create(MathTransform tr1, MathTransform tr2, final MathTransformFactory factory) throws FactoryException, MismatchedDimensionException { final int dim1 = tr1.getTargetDimensions(); final int dim2 = tr2.getSourceDimensions(); if (dim1 != dim2) { throw new MismatchedDimensionException(Resources.format(Resources.Keys.CanNotConcatenateTransforms_2, getName(tr1), getName(tr2)) + ' ' + Errors.format(Errors.Keys.MismatchedDimension_2, dim1, dim2)); } MathTransform mt = createOptimized(tr1, tr2, factory); if (mt != null) { return mt; } /* * Can not avoid the creation of a ConcatenatedTransform object. * Check for the type to create (1D, 2D, general case...) */ final int dimSource = tr1.getSourceDimensions(); final int dimTarget = tr2.getTargetDimensions(); if (dimSource == 1 && dimTarget == 1) { /* * Result needs to be a MathTransform1D. */ if (tr1 instanceof MathTransform1D && tr2 instanceof MathTransform1D) { return new ConcatenatedTransformDirect1D((MathTransform1D) tr1, (MathTransform1D) tr2); } else { return new ConcatenatedTransform1D(tr1, tr2); } } else if (dimSource == 2 && dimTarget == 2) { /* * Result needs to be a MathTransform2D. */ if (tr1 instanceof MathTransform2D && tr2 instanceof MathTransform2D) { return new ConcatenatedTransformDirect2D((MathTransform2D) tr1, (MathTransform2D) tr2); } else { return new ConcatenatedTransform2D(tr1, tr2); } } else if (dimSource == tr1.getTargetDimensions() // dim1 = tr1.getTargetDimensions() and && dimTarget == tr2.getSourceDimensions()) // dim2 = tr2.getSourceDimensions() may not be true anymore. { return new ConcatenatedTransformDirect(tr1, tr2); } else { return new ConcatenatedTransform(tr1, tr2); } }
Example #25
Source File: InterpolatedTransform2D.java From sis with Apache License 2.0 | 4 votes |
/** * Returns the inverse transform of this transform. */ @Override public MathTransform2D inverse() { return (MathTransform2D) super.inverse(); }
Example #26
Source File: InterpolatedTransform2D.java From sis with Apache License 2.0 | 4 votes |
/** * Returns the inverse transform of this transform. */ @Override public MathTransform2D inverse() { return (MathTransform2D) super.inverse(); }
Example #27
Source File: MathTransforms.java From sis with Apache License 2.0 | 2 votes |
/** * Concatenates the given two-dimensional transforms. This is a convenience methods * delegating to {@link #concatenate(MathTransform, MathTransform)} and casting the * result to a {@link MathTransform2D} instance. * * @param tr1 the first math transform. * @param tr2 the second math transform. * @return the concatenated transform. * @throws MismatchedDimensionException if the output dimension of the first transform * does not match the input dimension of the second transform. */ public static MathTransform2D concatenate(MathTransform2D tr1, MathTransform2D tr2) throws MismatchedDimensionException { return (MathTransform2D) concatenate((MathTransform) tr1, (MathTransform) tr2); }
Example #28
Source File: AbstractMathTransform2D.java From sis with Apache License 2.0 | 2 votes |
/** * Returns the inverse of this math transform. * The returned transform should be the enclosing math transform. */ @Override public abstract MathTransform2D inverse();
Example #29
Source File: AbstractMathTransform2D.java From sis with Apache License 2.0 | 2 votes |
/** * Returns the inverse transform of this object. * The default implementation returns {@code this} if this transform is an identity transform, * or throws an exception otherwise. Subclasses should override this method. */ @Override public MathTransform2D inverse() throws NoninvertibleTransformException { return (MathTransform2D) super.inverse(); }
Example #30
Source File: ZonedGridSystem.java From sis with Apache License 2.0 | 2 votes |
/** * Returns the inverse of this map projection. * * @return the inverse of this map projection. */ @Override public MathTransform2D inverse() { return inverse; }