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

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

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

CRS.getHorizontalCRS介绍

[英]Returns the first horizontal coordinate reference system found in the given CRS, or null if there is none. A horizontal CRS is usually a two-dimensional GeographicCRS or ProjectedCRS CRS.
[中]返回给定CRS中找到的第一个水平坐标系,如果没有,则返回null。水平CRS通常是二维地理CRS或投影CRS。

代码示例

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

  1. /**
  2. * Computes the geographic bounds of a {@link ResourceInfo} by reprojecting the available native
  3. * bounds
  4. *
  5. * @param rinfo
  6. * @return the geographic bounds, or null if the native bounds are not available
  7. * @throws IOException
  8. */
  9. public ReferencedEnvelope getLatLonBounds(
  10. ReferencedEnvelope nativeBounds, CoordinateReferenceSystem declaredCRS)
  11. throws IOException {
  12. if (nativeBounds != null && declaredCRS != null) {
  13. // make sure we use the declared CRS, not the native one, the may differ
  14. if (!CRS.equalsIgnoreMetadata(DefaultGeographicCRS.WGS84, declaredCRS)) {
  15. // transform
  16. try {
  17. ReferencedEnvelope bounds =
  18. new ReferencedEnvelope(nativeBounds, CRS.getHorizontalCRS(declaredCRS));
  19. return bounds.transform(DefaultGeographicCRS.WGS84, true);
  20. } catch (Exception e) {
  21. throw (IOException) new IOException("transform error").initCause(e);
  22. }
  23. } else {
  24. return new ReferencedEnvelope(nativeBounds, DefaultGeographicCRS.WGS84);
  25. }
  26. }
  27. return null;
  28. }

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

  1. private void checkReprojection() throws FactoryException {
  2. geometryCRS = CRS.getHorizontalCRS(sourceCRS);
  3. CoordinateReferenceSystem renderingCRS = renderingEnvelope.getCoordinateReferenceSystem();
  4. try {
  5. noReprojection = !CRS.isTransformationRequired(geometryCRS, renderingCRS);
  6. } catch (Exception e) {
  7. LOGGER.log(
  8. Level.FINE,
  9. "Failed to determine is reprojection is required, assumming it is",
  10. e);
  11. noReprojection = false;
  12. }
  13. }

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

  1. SingleCRS horizontalCRS = CRS.getHorizontalCRS(crs);
  2. Unit targetUnit;
  3. if (horizontalCRS != null) {

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

  1. /** Tests {@link CRS#getHorizontalCRS} from a compound CRS. */
  2. public void testHorizontalFromCompound() throws FactoryException {
  3. // retrives "NTF (Paris) / France II + NGF Lallemand"
  4. CoordinateReferenceSystem compound = CRS.decode("EPSG:7401");
  5. CoordinateReferenceSystem horizontal = CRS.getHorizontalCRS(compound);
  6. // compares with "NTF (Paris) / France II"
  7. assertEquals(CRS.decode("EPSG:27582"), horizontal);
  8. }

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

  1. /**
  2. * Initializes a projection handler
  3. *
  4. * @param sourceCRS The source CRS
  5. * @param validAreaBounds The valid area (used to cut geometries that go beyond it)
  6. * @param renderingEnvelope The target rendering area and target CRS
  7. * @throws FactoryException
  8. */
  9. public ProjectionHandler(
  10. CoordinateReferenceSystem sourceCRS,
  11. Envelope validAreaBounds,
  12. ReferencedEnvelope renderingEnvelope)
  13. throws FactoryException {
  14. this.renderingEnvelope = renderingEnvelope;
  15. this.sourceCRS = CRS.getHorizontalCRS(sourceCRS);
  16. this.targetCRS = renderingEnvelope.getCoordinateReferenceSystem();
  17. this.validAreaBounds =
  18. validAreaBounds != null
  19. ? new ReferencedEnvelope(validAreaBounds, DefaultGeographicCRS.WGS84)
  20. : null;
  21. this.validArea = null;
  22. this.validaAreaTester = null;
  23. // query across dateline only in case of reprojection, Oracle won't use the spatial index
  24. // with two or-ed bboxes and fixing the issue at the store level requires more
  25. // time/resources than we presently have
  26. this.queryAcrossDateline =
  27. !CRS.equalsIgnoreMetadata(
  28. sourceCRS, renderingEnvelope.getCoordinateReferenceSystem());
  29. checkReprojection();
  30. }

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

  1. @Test
  2. public void testGetHorizontalCrs() {
  3. assertEquals(
  4. DefaultEngineeringCRS.GENERIC_2D,
  5. CRS.getHorizontalCRS(DefaultEngineeringCRS.GENERIC_2D));
  6. }

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

  1. CoordinateReferenceSystem crs = CRS.getHorizontalCRS(CRS.decode("EPSG:" + currentSRID));
  2. double distanceMeters = getDistanceInMeters(operator);
  3. if (crs instanceof GeographicCRS) {

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

  1. @Test
  2. public void testWrappingOn3DCRS() throws Exception {
  3. CoordinateReferenceSystem crs = CRS.decode("EPSG:4939", true);
  4. SingleCRS hcrs = CRS.getHorizontalCRS(crs);
  5. ReferencedEnvelope wgs84Envelope = new ReferencedEnvelope(-190, 60, -90, 45, hcrs);
  6. ProjectionHandler handler = ProjectionHandlerFinder.getHandler(wgs84Envelope, crs, true);
  7. assertNull(handler.validAreaBounds);
  8. List<ReferencedEnvelope> envelopes = handler.getQueryEnvelopes();
  9. assertEquals(2, envelopes.size());
  10. ReferencedEnvelope expected = new ReferencedEnvelope(170, 180, -90, 45, hcrs);
  11. assertTrue(envelopes.remove(wgs84Envelope));
  12. assertEquals(expected, envelopes.get(0));
  13. }

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

  1. transformTo2D =
  2. CRS.findMathTransform(
  3. requestedEnvelopeCRS2D, CRS.getHorizontalCRS(requestedEnvelopeCRS2D));
  4. requestedEnvelopeCRS2D = CRS.getHorizontalCRS(requestedEnvelopeCRS2D);
  5. } else transformTo2D = IdentityTransform.create(2);

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

  1. coverageCRS2D = CRS.getHorizontalCRS(coverageCRS);
  2. assert coverageCRS2D.getCoordinateSystem().getDimension() == 2;
  3. if (coverageCRS.getCoordinateSystem().getDimension() != 2) {

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

  1. final Rectangle2D rect = gridCoverageReader.getOriginalEnvelope().toRectangle2D();
  2. final CoordinateReferenceSystem sourceCrs =
  3. CRS.getHorizontalCRS(gridCoverageReader.getCoordinateReferenceSystem());
  4. if (sourceCrs == null)
  5. throw new UnsupportedOperationException(

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

  1. CRS.getHorizontalCRS(envelope.getCoordinateReferenceSystem());
  2. if (envelopeCrs2D != null && !CRS.equalsIgnoreMetadata(crs, envelopeCrs2D)) {
  3. CoordinateOperationFactory operationFactory =

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

  1. coverageCRS2D = CRS.getHorizontalCRS(coverageCRS);
  2. assert coverageCRS2D.getCoordinateSystem().getDimension() == 2;
  3. if (coverageCRS.getCoordinateSystem().getDimension() != 2) {

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

  1. public Object visit(BBOX filter, Object extraData) {
  2. // if no srs is specified we can't transform anyways
  3. String srs = filter.getSRS();
  4. if (srs != null && !"".equals(srs.trim())) return super.visit(filter, extraData);
  5. if (defaultCrs == null
  6. || filter.getBounds() == null
  7. || defaultCrs.getCoordinateSystem().getDimension()
  8. == filter.getBounds().getDimension()) {
  9. return getFactory(extraData)
  10. .bbox(
  11. filter.getExpression1(),
  12. ReferencedEnvelope.create(filter.getBounds(), defaultCrs));
  13. } else {
  14. try {
  15. SingleCRS horizontalCRS = CRS.getHorizontalCRS(defaultCrs);
  16. ReferencedEnvelope bounds =
  17. ReferencedEnvelope.create(filter.getBounds(), horizontalCRS);
  18. return getFactory(extraData).bbox(filter.getExpression1(), bounds);
  19. } catch (Exception e) {
  20. throw new RuntimeException("Could not decode srs '" + srs + "'", e);
  21. }
  22. }
  23. }

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

  1. @Test
  2. public void force3DCRS2DEnvelope() throws Exception {
  3. CoordinateReferenceSystem crs = CRS.decode("EPSG:4939", true);
  4. CoordinateReferenceSystem hcrs = CRS.getHorizontalCRS(crs);
  5. BBOX bbox = ff.bbox("the_geom", -180, -90, 180, 90, null);
  6. DefaultCRSFilterVisitor visitor = new DefaultCRSFilterVisitor(ff, crs);
  7. BBOX filtered = (BBOX) bbox.accept(visitor, null);
  8. Literal box = (Literal) filtered.getExpression2();
  9. Geometry g = (Geometry) box.evaluate(null);
  10. assertEquals(hcrs, g.getUserData());
  11. }

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

  1. /** Tests {@link CRS#getHorizontalCRS} from a Geographic 3D CR. */
  2. public void testHorizontalFromGeodetic() throws FactoryException {
  3. // retrives "WGS 84 (geographic 3D)"
  4. CoordinateReferenceSystem compound = CRS.decode("EPSG:4327");
  5. CoordinateReferenceSystem horizontal = CRS.getHorizontalCRS(compound);
  6. // the horizonal version is basically 4326, but it won't compare positively
  7. // with 4326, not even using CRS.equalsIgnoreMetadata(), so we check the axis directly
  8. CoordinateSystem cs = horizontal.getCoordinateSystem();
  9. assertEquals(2, cs.getDimension());
  10. assertEquals(AxisDirection.NORTH, cs.getAxis(0).getDirection());
  11. assertEquals(AxisDirection.EAST, cs.getAxis(1).getDirection());
  12. }

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

  1. returnedCRS = CRS.getHorizontalCRS(coverage.getCoordinateReferenceSystem());
  2. if (returnedCRS == null)
  3. throw new TransformException(

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

  1. @Test
  2. public void force3DCRS3DEnvelope() throws Exception {
  3. CoordinateReferenceSystem crs = CRS.decode("EPSG:4939", true);
  4. CoordinateReferenceSystem hcrs = CRS.getHorizontalCRS(crs);
  5. BBOX bbox =
  6. ff.bbox(
  7. ff.property("the_geom"),
  8. new ReferencedEnvelope3D(-180, 180, -90, 90, 0, 100, null));
  9. DefaultCRSFilterVisitor visitor = new DefaultCRSFilterVisitor(ff, crs);
  10. BBOX filtered = (BBOX) bbox.accept(visitor, null);
  11. Literal box = (Literal) filtered.getExpression2();
  12. Geometry g = (Geometry) box.evaluate(null);
  13. assertEquals(crs, g.getUserData());
  14. }
  15. }

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

  1. coverageCRS2D = CRS.getHorizontalCRS(coverageCRS);
  2. assert coverageCRS2D.getCoordinateSystem().getDimension() == 2;
  3. if (coverageCRS.getCoordinateSystem().getDimension() != 2) {

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

  1. /**
  2. * Make sure we can properly retrieve the bounds of 3d layers
  3. *
  4. * @throws Exception
  5. */
  6. public void testBounds() throws Exception {
  7. ReferencedEnvelope env = dataStore.getFeatureSource(tname(getLine3d())).getBounds();
  8. // check we got the right 2d component
  9. Envelope expected = new Envelope(1, 5, 0, 4);
  10. assertEquals(expected, env);
  11. // check the srs the expected one
  12. assertEquals(CRS.getHorizontalCRS(crs), env.getCoordinateReferenceSystem());
  13. }

相关文章