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

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

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

CRS.decode介绍

[英]Return a Coordinate Reference System for the specified code. Note that the code needs to mention the authority. Examples:

EPSG:1234 
AUTO:42001, ..., ..., ...

If there is more than one factory implementation for the same authority, then all additional factories are org.geotools.referencing.factory.FallbackAuthorityFactory to be used only when the first acceptable factory failed to create the requested CRS object.

CRS objects created by previous calls to this method are org.geotools.referencing.factory.BufferedAuthorityFactory using java.lang.ref.WeakReference. Subsequent calls to this method with the same authority code should be fast, unless the CRS object has been garbage collected.
[中]返回指定代码的坐标参考系。请注意,代码需要提及权限。示例:

EPSG:1234 
AUTO:42001, ..., ..., ...

如果同一权限有多个工厂实施,则所有其他工厂都是组织的。地理工具。参考。工厂FallbackAuthorityFactory仅在第一个可接受工厂未能创建请求的CRS对象时使用。
以前调用此方法创建的CRS对象是org。地理工具。参考。工厂BufferedAuthorityFactory使用java。参考文献:WeakReference。除非CRS对象已被垃圾收集,否则使用相同的授权代码对该方法的后续调用应该是快速的。

代码示例

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

@Override
public BoundingBox getBoundingBox(CoordinateReferenceSystem crs) {
  try {
    Envelope bounds = (Envelope) pedestrianIndex.getRoot().getBounds();
    ReferencedEnvelope refEnv = new ReferencedEnvelope(bounds, CRS.decode("EPSG:4326", true));
    return refEnv.toBounds(crs);
  } catch (Exception e) {
    LOG.error("error transforming graph bounding box to request CRS : {}", crs);
    return null;
  }
}

代码示例来源: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: geoserver/geoserver

@Test
public void testLatLonBounds() throws Exception {
  ReferencedEnvelope nativeBounds =
      new ReferencedEnvelope(700000, 800000, 4000000, 4100000, null);
  CoordinateReferenceSystem crs = CRS.decode("EPSG:32632", true);
  CatalogBuilder cb = new CatalogBuilder(getCatalog());
  ReferencedEnvelope re = cb.getLatLonBounds(nativeBounds, crs);
  assertEquals(DefaultGeographicCRS.WGS84, re.getCoordinateReferenceSystem());
  assertEquals(11.22, re.getMinX(), 0.01);
  assertEquals(36.1, re.getMinY(), 0.01);
}

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

@Test
public void testWgs84BoundsFromCompoundCRS() throws Exception {
  try {
    MapProjection.SKIP_SANITY_CHECKS = true;
    CatalogBuilder cb = new CatalogBuilder(getCatalog());
    ReferencedEnvelope3D bounds =
        new ReferencedEnvelope3D(
            142892, 470783, 16, 142900, 470790, 20, CRS.decode("EPSG:7415"));
    // used to throw an exception here
    ReferencedEnvelope latLonBounds =
        cb.getLatLonBounds(bounds, bounds.getCoordinateReferenceSystem());
    assertTrue(
        CRS.equalsIgnoreMetadata(
            CRS.decode("EPSG:4326"), latLonBounds.getCoordinateReferenceSystem()));
    // System.out.println(latLonBounds);
  } finally {
    MapProjection.SKIP_SANITY_CHECKS = false;
  }
}

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

/**
 * Test custom PADDING is being used when provided as Hint
 *
 * @throws Exception
 */
@Test
public void testPadding() throws Exception {
  CoordinateReferenceSystem wgs84 = CRS.decode("EPSG:4326", true);
  final double envWidth = 30;
  final double envHeight = 30;
  ReferencedEnvelope mapExtent = new ReferencedEnvelope(0, envWidth, 0, envHeight, wgs84);
  Rectangle screenSize = new Rectangle((int) envWidth, (int) envHeight);
  checkPadding(screenSize, mapExtent, 4);
  checkPadding(screenSize, mapExtent, 12);
}

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

void assertWMSLayer(WMSLayerInfo wmsLayer) throws Exception {
  assertEquals("states", wmsLayer.getName());
  assertEquals("topp:states", wmsLayer.getNativeName());
  assertEquals("EPSG:4326", wmsLayer.getSRS());
  assertEquals("USA Population", wmsLayer.getTitle());
  assertEquals("2000 census data for United States.", wmsLayer.getAbstract());
  assertEquals(CRS.decode("EPSG:4326"), wmsLayer.getNativeCRS());
  assertNotNull(wmsLayer.getNativeBoundingBox());
  assertNotNull(wmsLayer.getLatLonBoundingBox());
  assertFalse(wmsLayer.getKeywords().isEmpty());
}

代码示例来源: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

@Test
public void testUseCRSBounds() throws NoSuchAuthorityCodeException, FactoryException {
  // this test is almost trivial since the code itself is trivial
  CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326");
  LayerGroupHelper helper = new LayerGroupHelper(nested);
  helper.calculateBoundsFromCRS(targetCRS);
  // layer group bounds should now match target CRS bounds
  assertEquals(nested.getBounds(), new ReferencedEnvelope(CRS.getEnvelope(targetCRS)));
  // null CRS should get null bounds
  helper.calculateBoundsFromCRS(null);
  assertEquals(nested.getBounds(), null);
}

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

@Test
public void testCRSConverterInvalidWKT() throws Exception {
  CoordinateReferenceSystem crs = CRS.decode("EPSG:3575");
  try {
    ((Formattable) crs).toWKT(2, true);
    fail("expected exception");
  } catch (UnformattableObjectException e) {
  }
  String wkt = null;
  try {
    wkt = new CRSConverter().toString(crs);
  } catch (UnformattableObjectException e) {
    fail("Should have thrown exception");
  }
  CoordinateReferenceSystem crs2 =
      (CoordinateReferenceSystem) new CRSConverter().fromString(wkt);
  assertTrue(CRS.equalsIgnoreMetadata(crs, crs2));
}

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

@Test
public void testOutsideDefinitionArea() throws Exception {
  // setup a request that is outside of the coverage
  CoordinateReferenceSystem crs = CRS.decode("EPSG:3031", true);
  ReferencedEnvelope mapExtent =
      new ReferencedEnvelope(-1250000, 0, -13750000, -12500000, crs);
  // System.out.println(mapExtent.transform(DefaultGeographicCRS.WGS84, true));
  GridCoverageReaderHelper helper =
      new GridCoverageReaderHelper(
          reader,
          new Rectangle(400, 200),
          mapExtent,
          Interpolation.getInstance(Interpolation.INTERP_NEAREST));
  // read, nothing should come out
  ProjectionHandler handler =
      ProjectionHandlerFinder.getHandler(
          mapExtent, reader.getCoordinateReferenceSystem(), true);
  List<GridCoverage2D> coverages = helper.readCoverages(null, handler);
  assertTrue(coverages.isEmpty());
}

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

@BeforeClass
public static void setupCRS() throws FactoryException {
  CRS.reset("all");
  Hints.putSystemDefault(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE);
  // the following is only to make the test work in Eclipse, where the test
  // classpath is tainted by the test classpath of dependent modules (whilst in Maven it's
  // not)
  Set<CRSAuthorityFactory> factories =
      ReferencingFactoryFinder.getCRSAuthorityFactories(null);
  for (CRSAuthorityFactory factory : factories) {
    if (factory.getClass().getSimpleName().equals("EPSGCRSAuthorityFactory")) {
      ReferencingFactoryFinder.removeAuthorityFactory(factory);
    }
  }
  assertEquals(
      AxisOrder.NORTH_EAST, CRS.getAxisOrder(CRS.decode("urn:ogc:def:crs:EPSG::4326")));
}

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

@Override
public void createIndividuals() {
  try {
    coverageCRS = CRS.decode(crsCode, true);
  } catch (Exception e) {
    LOG.error("error decoding coordinate reference system code.", e);
    return;
  }
  if (boundsFromGraph) {
    // autowire graph service or pass in
  }
  gridEnvelope = new GridEnvelope2D(0, 0, cols, rows);
  refEnvelope = new ReferencedEnvelope(left, right, bottom, top, coverageCRS);
  gridGeometry = new GridGeometry2D(gridEnvelope, refEnvelope);
  super.createIndividuals0();
}

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

/**
 * Check we are actually using the EPSG database for anything not in override
 *
 * @throws TransformException
 */
@Test
public void testFallbackOnEPSGDatabaseStd() throws Exception {
  // Test CRSs
  CoordinateReferenceSystem source = CRS.decode("EPSG:3002");
  CoordinateReferenceSystem target = CRS.decode("EPSG:4326");
  CoordinateOperation co =
      CRS.getCoordinateOperationFactory(true).createOperation(source, target);
  ConcatenatedOperation cco = (ConcatenatedOperation) co;
  // the EPSG one only has two steps, the non EPSG one 4
  assertEquals(2, cco.getOperations().size());
}

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

@Test
public void testGetBoundsFromCRS() throws Exception {
  Catalog cat = getCatalog();
  CatalogBuilder cb = new CatalogBuilder(cat);
  cb.setStore(cat.getDataStoreByName(MockData.LINES.getPrefix()));
  FeatureTypeInfo fti = cb.buildFeatureType(toName(MockData.LINES));
  CoordinateReferenceSystem resourceCRS = fti.getCRS();
  assertNotNull(resourceCRS);
  // make sure the srs is as expected, otherwise the rest of the tests don't make sense
  assertEquals("EPSG:32615", fti.getSRS());
  ReferencedEnvelope crsBounds = cb.getBoundsFromCRS(fti);
  assertNotNull(crsBounds);
  CoordinateReferenceSystem exptectedCRS = CRS.decode("EPSG:32615");
  assertEquals(new ReferencedEnvelope(CRS.getEnvelope(exptectedCRS)), crsBounds);
  // if we change the srs when there's no reproject policy, should still be the same bounding
  // box
  fti.setSRS("EPSG:4326");
  fti.setProjectionPolicy(ProjectionPolicy.NONE);
  crsBounds = cb.getBoundsFromCRS(fti);
  assertEquals(new ReferencedEnvelope(CRS.getEnvelope(exptectedCRS)), crsBounds);
  // if we use reproject policy, bounds should now be different
  fti.setProjectionPolicy(ProjectionPolicy.FORCE_DECLARED);
  crsBounds = cb.getBoundsFromCRS(fti);
  assertNotEquals(new ReferencedEnvelope(CRS.getEnvelope(exptectedCRS)), crsBounds);
  // should now be 4326 bounds
  CoordinateReferenceSystem crs4326 = CRS.decode("EPSG:4326");
  assertEquals(new ReferencedEnvelope(CRS.getEnvelope(crs4326)), crsBounds);
  fti.setProjectionPolicy(ProjectionPolicy.REPROJECT_TO_DECLARED);
  assertEquals(new ReferencedEnvelope(CRS.getEnvelope(crs4326)), crsBounds);
}

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

@Test
public void testReprojectLayerGroup()
    throws NoSuchAuthorityCodeException, FactoryException, Exception {
  Catalog catalog = getCatalog();
  CatalogBuilder cb = new CatalogBuilder(catalog);
  LayerGroupInfo lg = catalog.getFactory().createLayerGroup();
  LayerInfo l = catalog.getLayerByName(getLayerId(MockData.ROAD_SEGMENTS));
  lg.getLayers().add(l);
  lg.getStyles().add(null);
  lg.setName("test-reproject");
  // EPSG:4901 "equivalent" but different uom
  String wkt =
      "GEOGCS[\"GCS_ATF_Paris\",DATUM[\"D_ATF\",SPHEROID[\"Plessis_1817\",6376523.0,308.64]],PRIMEM[\"Paris\",2.337229166666667],UNIT[\"Grad\",0.01570796326794897]]";
  CoordinateReferenceSystem lCrs = CRS.parseWKT(wkt);
  ((FeatureTypeInfo) l.getResource()).setSRS(null);
  ((FeatureTypeInfo) l.getResource()).setNativeCRS(lCrs);
  assertNull(CRS.lookupEpsgCode(lCrs, false));
  // Use the real thing now
  CoordinateReferenceSystem lgCrs = CRS.decode("EPSG:4901");
  assertNotNull(CRS.lookupEpsgCode(lgCrs, false));
  // Reproject our layer group to EPSG:4901. We expect it to have an EPSG code.
  cb.calculateLayerGroupBounds(lg, lgCrs);
  assertNotNull(CRS.lookupEpsgCode(lg.getBounds().getCoordinateReferenceSystem(), false));
}

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

@Test
public void testCutGeometryLambertConformal() throws Exception {
  // get a lambert conformal conic with
  ReferencedEnvelope wgs84South = new ReferencedEnvelope(-180, -90, -40, 0, WGS84);
  ReferencedEnvelope laeSouth = wgs84South.transform(CRS.decode("EPSG:2194"), true);
  ProjectionHandler handler = ProjectionHandlerFinder.getHandler(laeSouth, WGS84, true);
  // a Geometry that crosses the opposite of the central meridian
  Polygon geometry = JTS.toGeometry(new Envelope(5, 15, 0, 10));
  Geometry preProcessed = handler.preProcess(geometry);
  assertTrue(
      "Should have sliced the geometry in two parts",
      preProcessed instanceof MultiPolygon);
}

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

CoordinateReferenceSystem crs = srs != null ? CRS.decode(srs) : null;
baseMap.put("baseMapEnvelope", new ReferencedEnvelope(x1, x2, y1, y2, crs));

代码示例来源: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: geotools/geotools

@Test
public void testQueryEnvelopeOnInvalidArea2() throws Exception {
  // and Envelope that does not make sense for EPSG:3003, too far away from central meridian
  ReferencedEnvelope re =
      new ReferencedEnvelope(-130, -120, -40, 30, DefaultGeographicCRS.WGS84);
  ReferencedEnvelope re3857 = re.transform(CRS.decode("EPSG:3857", true), true);
  ProjectionHandler ph =
      ProjectionHandlerFinder.getHandler(re3857, CRS.decode("EPSG:3003", true), true);
  List<ReferencedEnvelope> queryEnvelopes = ph.getQueryEnvelopes();
  assertEquals(0, queryEnvelopes.size());
}

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

/**
 * Tests the {@code 42101} code. The purpose of this test is mostly to make sure that {@link
 * FactoryUsingWKT} is in the chain.
 *
 * @throws FactoryException If the CRS can't be created.
 */
@Test
public void test42101() throws FactoryException {
  assertTrue(CRS.decode("EPSG:42101") instanceof ProjectedCRS);
}

相关文章