MathTransform toMeters = CRS.findMathTransform(wgs, crs, false); MathTransform fromMeters = CRS.findMathTransform(crs, wgs, false); GeometryFactory geomf = JTSFactoryFinder.getGeometryFactory();
CoordinateReferenceSystem crs = gg.getCoordinateReferenceSystem2D(); try { MathTransform tr = CRS.findMathTransform(crs, DefaultGeographicCRS.WGS84);
try { final CoordinateReferenceSystem WGS84 = CRS.decode("EPSG:4326", true); tr = CRS.findMathTransform(coverageCRS, WGS84); } catch (Exception e) { LOG.error("error creating CRS transform.", e);
/** * Test method for {@link CoordinateOperationFactoryUsingWKT#createCoordinateOperation}. * * @throws TransformException */ @Test public void testCreateOperationFromCustomCodes() throws Exception { // Test CRSs CoordinateReferenceSystem source = CRS.decode(SOURCE_CRS); CoordinateReferenceSystem target = CRS.decode(TARGET_CRS); MathTransform mt = CRS.findMathTransform(source, target, true); // Test MathTransform double[] p = new double[2]; mt.transform(SRC_TEST_POINT, 0, p, 0, 1); assertEquals(p[0], DST_TEST_POINT[0], 1e-8); assertEquals(p[1], DST_TEST_POINT[1], 1e-8); }
int i = 0; try { MathTransform tr = CRS.findMathTransform(crs, DefaultGeographicCRS.WGS84);
/** * Test method for {@link CoordinateOperationFactoryUsingWKT#createCoordinateOperation}. * * @throws TransformException */ @Test public void testOverrideEPSGOperation() throws Exception { // Test CRSs CoordinateReferenceSystem source = CRS.decode("EPSG:4269"); CoordinateReferenceSystem target = CRS.decode("EPSG:4326"); MathTransform mt = CRS.findMathTransform(source, target, true); // Test MathTransform double[] p = new double[2]; mt.transform(SRC_TEST_POINT, 0, p, 0, 1); assertEquals(p[0], DST_TEST_POINT[0], 1e-8); assertEquals(p[1], DST_TEST_POINT[1], 1e-8); }
/** See if we can use the stgeorge grid shift files as the ESPG db would like us to */ @Test public void testNadCon() throws Exception { CoordinateReferenceSystem crs4138 = CRS.decode("EPSG:4138"); CoordinateReferenceSystem crs4326 = CRS.decode("EPSG:4326"); MathTransform mt = CRS.findMathTransform(crs4138, crs4326); assertTrue(mt.toWKT().contains("NADCON")); double[] src = new double[] {-169.625, 56.575}; double[] expected = new double[] {-169.62744, 56.576034}; double[] p = new double[2]; mt.transform(src, 0, p, 0, 1); assertEquals(expected[0], p[0], 1e-6); assertEquals(expected[1], p[1], 1e-6); } }
if (!CRS.equalsIgnoreMetadata(crs, this.crs)) { try { destinationToSourceTransform = CRS.findMathTransform(crs, this.crs, true); } catch (FactoryException e) { throw new DataSourceException("Unable to inspect request CRS", e);
mathTransform = CRS.findMathTransform(sourceCrs, destCrs, false);
private boolean isWrappingException( CoordinateReferenceSystem sourceCrs, CoordinateReferenceSystem targetCRS) throws FactoryException { MathTransform mt = CRS.findMathTransform(sourceCrs, targetCRS); // this projection does not wrap coordinates, generates values larger than 180 instead if (mt instanceof Mercator) { return true; } return false; } }
private MathTransform transform( CoordinateReferenceSystem source, CoordinateReferenceSystem target) { try { return CRS.findMathTransform(source, target, true); } catch (FactoryException e) { throw new IllegalArgumentException("Could not create math transform", e); } }
public static Envelope reprojectEnvelopeByEpsg(int srcEpsg, int destEpsg, Envelope srcEnvelope) throws FactoryException, TransformException { CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:" + srcEpsg); // $NON-NLS-1$ CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:" + destEpsg); // $NON-NLS-1$ MathTransform tr = CRS.findMathTransform(sourceCRS, targetCRS); // From that point, I'm not sure which kind of object is returned by // getLatLonBoundingBox(). But there is some convenience methods if CRS // like: return JTS.transform(srcEnvelope, tr); }
public static MathTransform getMathTransform( CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem destCRS) { try { return CRS.findMathTransform(sourceCRS, destCRS, true); } catch (OperationNotFoundException e) { LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e); } catch (FactoryException e) { LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e); } return null; }
static Geometry reprojectAndDensify( Geometry first, CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem targetCRS) throws FactoryException, TransformException { if (targetCRS == null) { targetCRS = CRS.parseWKT(ECKERT_IV_WKT); } MathTransform firstTransform = CRS.findMathTransform(sourceCRS, targetCRS); Geometry geometry = JTS.transform(densify(first, sourceCRS, 0.01d), firstTransform); return geometry; }
/** Makes sure that the transform between two EPSG:4326 is the identity transform. */ public void testFindMathTransformIdentity() throws FactoryException { CoordinateReferenceSystem crs1default = CRS.decode("EPSG:4326"); CoordinateReferenceSystem crs2default = CRS.decode("EPSG:4326"); MathTransform tDefault = CRS.findMathTransform(crs1default, crs2default); assertTrue("WSG84 transformed to WSG84 should be Identity", tDefault.isIdentity()); CoordinateReferenceSystem crs1force = CRS.decode("EPSG:4326", true); CoordinateReferenceSystem crs2force = CRS.decode("EPSG:4326", true); MathTransform tForce = CRS.findMathTransform(crs1force, crs2force); assertTrue("WSG84 transformed to WSG84 should be Identity", tForce.isIdentity()); }
@Test public void testTransform() throws NoSuchAuthorityCodeException, FactoryException { CoordinateReferenceSystem epsg0 = CRS.decode("EPSG:" + CODE); CoordinateReferenceSystem epsg42101 = CRS.decode("EPSG:42101"); assertTrue(CRS.findMathTransform(DefaultEngineeringCRS.GENERIC_2D, epsg42101).isIdentity()); assertTrue(CRS.findMathTransform(epsg42101, DefaultEngineeringCRS.GENERIC_2D).isIdentity()); assertTrue(CRS.findMathTransform(epsg0, epsg42101).isIdentity()); assertTrue(CRS.findMathTransform(epsg42101, epsg0).isIdentity()); }
public void testNadCon() throws Exception { CoordinateReferenceSystem crs4138 = CRS.decode("EPSG:4138"); CoordinateReferenceSystem crs4326 = CRS.decode("EPSG:4326"); MathTransform mt = CRS.findMathTransform(crs4138, crs4326); assertTrue(mt.toWKT().contains("NADCON")); double[] src = new double[] {56.575, -169.625}; double[] expected = new double[] {56.576034, -169.62744}; double[] p = new double[2]; mt.transform(src, 0, p, 0, 1); assertEquals(expected[0], p[0], 1e-6); assertEquals(expected[1], p[1], 1e-6); }
@BeforeClass public static void setupClass() throws FactoryException, TransformException { sphericalGeosCRS = CRS.parseWKT(sphericalGeosWKT); sphericalGeosToGeog = CRS.findMathTransform( sphericalGeosCRS, CRS.getProjectedCRS(sphericalGeosCRS).getBaseCRS(), true); geogToSphericalGeos = sphericalGeosToGeog.inverse(); ellipsoidalGeosCRS = CRS.parseWKT(ellipsoidalGeosWKT); ellipsoidalGeosToGeog = CRS.findMathTransform( ellipsoidalGeosCRS, CRS.getProjectedCRS(ellipsoidalGeosCRS).getBaseCRS(), true); geogToEllipsoidalGeos = ellipsoidalGeosToGeog.inverse(); }
@Test public void testTransformExtraMZ() throws Exception { LiteCoordinateSequence cs = new LiteCoordinateSequence(1, 4); cs.setArray(new double[] {1000000, 4000000, 25, 48}); CoordinateReferenceSystem sourceCrs = CRS.parseWKT(JTSTest.UTM_ZONE_10N); CoordinateReferenceSystem destCrs = DefaultGeographicCRS.WGS84; DefaultCoordinateSequenceTransformer cst; cst = new DefaultCoordinateSequenceTransformer(new LiteCoordinateSequenceFactory()); MathTransform tx = CRS.findMathTransform(sourceCrs, destCrs, true); LiteCoordinateSequence transformed = (LiteCoordinateSequence) cst.transform(cs, tx); assertEquals(25.0, transformed.getOrdinate(0, 2), 0.0); assertEquals(48.0, transformed.getOrdinate(0, 3), 0.0); }
@Test public void testLiteToStandard() throws Exception { LiteCoordinateSequence cs = new LiteCoordinateSequence(1, 2); cs.setArray(new double[] {1000000, 4000000}); CoordinateReferenceSystem sourceCrs = CRS.parseWKT(JTSTest.UTM_ZONE_10N); CoordinateReferenceSystem destCrs = DefaultGeographicCRS.WGS84; DefaultCoordinateSequenceTransformer cst; cst = new DefaultCoordinateSequenceTransformer(/* standard cs factory */ ); MathTransform tx = CRS.findMathTransform(sourceCrs, destCrs, true); CoordinateSequence transformed = cst.transform(cs, tx); CoordinateSequence reference = transform(cs, tx); assertEquals(reference.getOrdinate(0, 0), transformed.getOrdinate(0, 0), 0.0); assertEquals(reference.getOrdinate(0, 1), transformed.getOrdinate(0, 1), 0.0); }