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

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

本文整理了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

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

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

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

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

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

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

/**
 * 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);
}

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

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

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

/**
 * 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);
}

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

/** 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);
  }
}

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

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);

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

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

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

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;
  }
}

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

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);
  }
}

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

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);
}

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

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;
}

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

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;
}

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

/** 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());
}

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

@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());
}

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

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);
}

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

@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();
}

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

@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);
}

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

@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);
}

相关文章