org.geotools.referencing.CRS.findMathTransform()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(633)

本文整理了Java中org.geotools.referencing.CRS.findMathTransform()方法的一些代码示例,展示了CRS.findMathTransform()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CRS.findMathTransform()方法的具体详情如下:
包路径:org.geotools.referencing.CRS
类名称:CRS
方法名:findMathTransform

CRS.findMathTransform介绍

[英]Grab a transform between two Coordinate Reference Systems. This convenience method is a shorthand for the following: FactoryFinder. ReferencingFactoryFinder#getCoordinateOperationFactory(null). CoordinateOperationFactory#createOperation(sourceCRS, targetCRS). CoordinateOperation#getMathTransform(); Note that some metadata like CoordinateOperation#getPositionalAccuracy are lost by this method. If those metadata are wanted, use the CoordinateOperationFactory directly.

Sample use:

MathTransform transform = CRS.findMathTransform( CRS. #decode("EPSG:42102"), CRS. #decode("EPSG:4326") );
[中]获取两个坐标参照系之间的变换。此方便的方法是以下内容的简写:FactoryFinder. ReferencingFactoryFinder#getCoordinateOperationFactory(null). CoordinateOperationFactory#createOperation(sourceCRS, targetCRS). CoordinateOperation#getMathTransform();注意,某些元数据(如CoordinationOperation#GetPositionAccurance)会因此方法而丢失。如果需要这些元数据,请直接使用CoordinateOperationFactory。
样本使用:
MathTransform transform = CRS.findMathTransform( CRS. #decode("EPSG:42102"), CRS. #decode("EPSG:4326") );

代码示例

代码示例来源:origin: opentripplanner/OpenTripPlanner

  1. MathTransform toMeters = CRS.findMathTransform(wgs, crs, false);
  2. MathTransform fromMeters = CRS.findMathTransform(crs, wgs, false);
  3. GeometryFactory geomf = JTSFactoryFinder.getGeometryFactory();

代码示例来源:origin: opentripplanner/OpenTripPlanner

  1. CoordinateReferenceSystem crs = gg.getCoordinateReferenceSystem2D();
  2. try {
  3. MathTransform tr = CRS.findMathTransform(crs, DefaultGeographicCRS.WGS84);

代码示例来源:origin: opentripplanner/OpenTripPlanner

  1. try {
  2. final CoordinateReferenceSystem WGS84 = CRS.decode("EPSG:4326", true);
  3. tr = CRS.findMathTransform(coverageCRS, WGS84);
  4. } catch (Exception e) {
  5. LOG.error("error creating CRS transform.", e);

代码示例来源:origin: geoserver/geoserver

  1. /**
  2. * Test method for {@link CoordinateOperationFactoryUsingWKT#createCoordinateOperation}.
  3. *
  4. * @throws TransformException
  5. */
  6. @Test
  7. public void testCreateOperationFromCustomCodes() throws Exception {
  8. // Test CRSs
  9. CoordinateReferenceSystem source = CRS.decode(SOURCE_CRS);
  10. CoordinateReferenceSystem target = CRS.decode(TARGET_CRS);
  11. MathTransform mt = CRS.findMathTransform(source, target, true);
  12. // Test MathTransform
  13. double[] p = new double[2];
  14. mt.transform(SRC_TEST_POINT, 0, p, 0, 1);
  15. assertEquals(p[0], DST_TEST_POINT[0], 1e-8);
  16. assertEquals(p[1], DST_TEST_POINT[1], 1e-8);
  17. }

代码示例来源:origin: opentripplanner/OpenTripPlanner

  1. int i = 0;
  2. try {
  3. MathTransform tr = CRS.findMathTransform(crs, DefaultGeographicCRS.WGS84);

代码示例来源:origin: geoserver/geoserver

  1. /**
  2. * Test method for {@link CoordinateOperationFactoryUsingWKT#createCoordinateOperation}.
  3. *
  4. * @throws TransformException
  5. */
  6. @Test
  7. public void testOverrideEPSGOperation() throws Exception {
  8. // Test CRSs
  9. CoordinateReferenceSystem source = CRS.decode("EPSG:4269");
  10. CoordinateReferenceSystem target = CRS.decode("EPSG:4326");
  11. MathTransform mt = CRS.findMathTransform(source, target, true);
  12. // Test MathTransform
  13. double[] p = new double[2];
  14. mt.transform(SRC_TEST_POINT, 0, p, 0, 1);
  15. assertEquals(p[0], DST_TEST_POINT[0], 1e-8);
  16. assertEquals(p[1], DST_TEST_POINT[1], 1e-8);
  17. }

代码示例来源:origin: geoserver/geoserver

  1. /** See if we can use the stgeorge grid shift files as the ESPG db would like us to */
  2. @Test
  3. public void testNadCon() throws Exception {
  4. CoordinateReferenceSystem crs4138 = CRS.decode("EPSG:4138");
  5. CoordinateReferenceSystem crs4326 = CRS.decode("EPSG:4326");
  6. MathTransform mt = CRS.findMathTransform(crs4138, crs4326);
  7. assertTrue(mt.toWKT().contains("NADCON"));
  8. double[] src = new double[] {-169.625, 56.575};
  9. double[] expected = new double[] {-169.62744, 56.576034};
  10. double[] p = new double[2];
  11. mt.transform(src, 0, p, 0, 1);
  12. assertEquals(expected[0], p[0], 1e-6);
  13. assertEquals(expected[1], p[1], 1e-6);
  14. }
  15. }

代码示例来源:origin: geoserver/geoserver

  1. if (!CRS.equalsIgnoreMetadata(crs, this.crs)) {
  2. try {
  3. destinationToSourceTransform = CRS.findMathTransform(crs, this.crs, true);
  4. } catch (FactoryException e) {
  5. throw new DataSourceException("Unable to inspect request CRS", e);

代码示例来源:origin: opentripplanner/OpenTripPlanner

  1. mathTransform = CRS.findMathTransform(sourceCrs, destCrs, false);

代码示例来源:origin: geotools/geotools

  1. private boolean isWrappingException(
  2. CoordinateReferenceSystem sourceCrs, CoordinateReferenceSystem targetCRS)
  3. throws FactoryException {
  4. MathTransform mt = CRS.findMathTransform(sourceCrs, targetCRS);
  5. // this projection does not wrap coordinates, generates values larger than 180 instead
  6. if (mt instanceof Mercator) {
  7. return true;
  8. }
  9. return false;
  10. }
  11. }

代码示例来源:origin: geotools/geotools

  1. private MathTransform transform(
  2. CoordinateReferenceSystem source, CoordinateReferenceSystem target) {
  3. try {
  4. return CRS.findMathTransform(source, target, true);
  5. } catch (FactoryException e) {
  6. throw new IllegalArgumentException("Could not create math transform", e);
  7. }
  8. }

代码示例来源:origin: geotools/geotools

  1. public static Envelope reprojectEnvelopeByEpsg(int srcEpsg, int destEpsg, Envelope srcEnvelope)
  2. throws FactoryException, TransformException {
  3. CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:" + srcEpsg); // $NON-NLS-1$
  4. CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:" + destEpsg); // $NON-NLS-1$
  5. MathTransform tr = CRS.findMathTransform(sourceCRS, targetCRS);
  6. // From that point, I'm not sure which kind of object is returned by
  7. // getLatLonBoundingBox(). But there is some convenience methods if CRS
  8. // like:
  9. return JTS.transform(srcEnvelope, tr);
  10. }

代码示例来源:origin: geotools/geotools

  1. public static MathTransform getMathTransform(
  2. CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem destCRS) {
  3. try {
  4. return CRS.findMathTransform(sourceCRS, destCRS, true);
  5. } catch (OperationNotFoundException e) {
  6. LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
  7. } catch (FactoryException e) {
  8. LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
  9. }
  10. return null;
  11. }

代码示例来源:origin: geotools/geotools

  1. static Geometry reprojectAndDensify(
  2. Geometry first,
  3. CoordinateReferenceSystem sourceCRS,
  4. CoordinateReferenceSystem targetCRS)
  5. throws FactoryException, TransformException {
  6. if (targetCRS == null) {
  7. targetCRS = CRS.parseWKT(ECKERT_IV_WKT);
  8. }
  9. MathTransform firstTransform = CRS.findMathTransform(sourceCRS, targetCRS);
  10. Geometry geometry = JTS.transform(densify(first, sourceCRS, 0.01d), firstTransform);
  11. return geometry;
  12. }

代码示例来源:origin: geotools/geotools

  1. /** Makes sure that the transform between two EPSG:4326 is the identity transform. */
  2. public void testFindMathTransformIdentity() throws FactoryException {
  3. CoordinateReferenceSystem crs1default = CRS.decode("EPSG:4326");
  4. CoordinateReferenceSystem crs2default = CRS.decode("EPSG:4326");
  5. MathTransform tDefault = CRS.findMathTransform(crs1default, crs2default);
  6. assertTrue("WSG84 transformed to WSG84 should be Identity", tDefault.isIdentity());
  7. CoordinateReferenceSystem crs1force = CRS.decode("EPSG:4326", true);
  8. CoordinateReferenceSystem crs2force = CRS.decode("EPSG:4326", true);
  9. MathTransform tForce = CRS.findMathTransform(crs1force, crs2force);
  10. assertTrue("WSG84 transformed to WSG84 should be Identity", tForce.isIdentity());
  11. }

代码示例来源:origin: geotools/geotools

  1. @Test
  2. public void testTransform() throws NoSuchAuthorityCodeException, FactoryException {
  3. CoordinateReferenceSystem epsg0 = CRS.decode("EPSG:" + CODE);
  4. CoordinateReferenceSystem epsg42101 = CRS.decode("EPSG:42101");
  5. assertTrue(CRS.findMathTransform(DefaultEngineeringCRS.GENERIC_2D, epsg42101).isIdentity());
  6. assertTrue(CRS.findMathTransform(epsg42101, DefaultEngineeringCRS.GENERIC_2D).isIdentity());
  7. assertTrue(CRS.findMathTransform(epsg0, epsg42101).isIdentity());
  8. assertTrue(CRS.findMathTransform(epsg42101, epsg0).isIdentity());
  9. }

代码示例来源:origin: geotools/geotools

  1. public void testNadCon() throws Exception {
  2. CoordinateReferenceSystem crs4138 = CRS.decode("EPSG:4138");
  3. CoordinateReferenceSystem crs4326 = CRS.decode("EPSG:4326");
  4. MathTransform mt = CRS.findMathTransform(crs4138, crs4326);
  5. assertTrue(mt.toWKT().contains("NADCON"));
  6. double[] src = new double[] {56.575, -169.625};
  7. double[] expected = new double[] {56.576034, -169.62744};
  8. double[] p = new double[2];
  9. mt.transform(src, 0, p, 0, 1);
  10. assertEquals(expected[0], p[0], 1e-6);
  11. assertEquals(expected[1], p[1], 1e-6);
  12. }

代码示例来源:origin: geotools/geotools

  1. @BeforeClass
  2. public static void setupClass() throws FactoryException, TransformException {
  3. sphericalGeosCRS = CRS.parseWKT(sphericalGeosWKT);
  4. sphericalGeosToGeog =
  5. CRS.findMathTransform(
  6. sphericalGeosCRS, CRS.getProjectedCRS(sphericalGeosCRS).getBaseCRS(), true);
  7. geogToSphericalGeos = sphericalGeosToGeog.inverse();
  8. ellipsoidalGeosCRS = CRS.parseWKT(ellipsoidalGeosWKT);
  9. ellipsoidalGeosToGeog =
  10. CRS.findMathTransform(
  11. ellipsoidalGeosCRS,
  12. CRS.getProjectedCRS(ellipsoidalGeosCRS).getBaseCRS(),
  13. true);
  14. geogToEllipsoidalGeos = ellipsoidalGeosToGeog.inverse();
  15. }

代码示例来源:origin: geotools/geotools

  1. @Test
  2. public void testTransformExtraMZ() throws Exception {
  3. LiteCoordinateSequence cs = new LiteCoordinateSequence(1, 4);
  4. cs.setArray(new double[] {1000000, 4000000, 25, 48});
  5. CoordinateReferenceSystem sourceCrs = CRS.parseWKT(JTSTest.UTM_ZONE_10N);
  6. CoordinateReferenceSystem destCrs = DefaultGeographicCRS.WGS84;
  7. DefaultCoordinateSequenceTransformer cst;
  8. cst = new DefaultCoordinateSequenceTransformer(new LiteCoordinateSequenceFactory());
  9. MathTransform tx = CRS.findMathTransform(sourceCrs, destCrs, true);
  10. LiteCoordinateSequence transformed = (LiteCoordinateSequence) cst.transform(cs, tx);
  11. assertEquals(25.0, transformed.getOrdinate(0, 2), 0.0);
  12. assertEquals(48.0, transformed.getOrdinate(0, 3), 0.0);
  13. }

代码示例来源:origin: geotools/geotools

  1. @Test
  2. public void testLiteToStandard() throws Exception {
  3. LiteCoordinateSequence cs = new LiteCoordinateSequence(1, 2);
  4. cs.setArray(new double[] {1000000, 4000000});
  5. CoordinateReferenceSystem sourceCrs = CRS.parseWKT(JTSTest.UTM_ZONE_10N);
  6. CoordinateReferenceSystem destCrs = DefaultGeographicCRS.WGS84;
  7. DefaultCoordinateSequenceTransformer cst;
  8. cst = new DefaultCoordinateSequenceTransformer(/* standard cs factory */ );
  9. MathTransform tx = CRS.findMathTransform(sourceCrs, destCrs, true);
  10. CoordinateSequence transformed = cst.transform(cs, tx);
  11. CoordinateSequence reference = transform(cs, tx);
  12. assertEquals(reference.getOrdinate(0, 0), transformed.getOrdinate(0, 0), 0.0);
  13. assertEquals(reference.getOrdinate(0, 1), transformed.getOrdinate(0, 1), 0.0);
  14. }

相关文章