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

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

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

/**
 * Computes the geographic bounds of a {@link ResourceInfo} by reprojecting the available native
 * bounds
 *
 * @param rinfo
 * @return the geographic bounds, or null if the native bounds are not available
 * @throws IOException
 */
public ReferencedEnvelope getLatLonBounds(
    ReferencedEnvelope nativeBounds, CoordinateReferenceSystem declaredCRS)
    throws IOException {
  if (nativeBounds != null && declaredCRS != null) {
    // make sure we use the declared CRS, not the native one, the may differ
    if (!CRS.equalsIgnoreMetadata(DefaultGeographicCRS.WGS84, declaredCRS)) {
      // transform
      try {
        ReferencedEnvelope bounds =
            new ReferencedEnvelope(nativeBounds, CRS.getHorizontalCRS(declaredCRS));
        return bounds.transform(DefaultGeographicCRS.WGS84, true);
      } catch (Exception e) {
        throw (IOException) new IOException("transform error").initCause(e);
      }
    } else {
      return new ReferencedEnvelope(nativeBounds, DefaultGeographicCRS.WGS84);
    }
  }
  return null;
}

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

private void checkReprojection() throws FactoryException {
  geometryCRS = CRS.getHorizontalCRS(sourceCRS);
  CoordinateReferenceSystem renderingCRS = renderingEnvelope.getCoordinateReferenceSystem();
  try {
    noReprojection = !CRS.isTransformationRequired(geometryCRS, renderingCRS);
  } catch (Exception e) {
    LOGGER.log(
        Level.FINE,
        "Failed to determine is reprojection is required, assumming it is",
        e);
    noReprojection = false;
  }
}

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

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

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

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

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

/**
 * Initializes a projection handler
 *
 * @param sourceCRS The source CRS
 * @param validAreaBounds The valid area (used to cut geometries that go beyond it)
 * @param renderingEnvelope The target rendering area and target CRS
 * @throws FactoryException
 */
public ProjectionHandler(
    CoordinateReferenceSystem sourceCRS,
    Envelope validAreaBounds,
    ReferencedEnvelope renderingEnvelope)
    throws FactoryException {
  this.renderingEnvelope = renderingEnvelope;
  this.sourceCRS = CRS.getHorizontalCRS(sourceCRS);
  this.targetCRS = renderingEnvelope.getCoordinateReferenceSystem();
  this.validAreaBounds =
      validAreaBounds != null
          ? new ReferencedEnvelope(validAreaBounds, DefaultGeographicCRS.WGS84)
          : null;
  this.validArea = null;
  this.validaAreaTester = null;
  // query across dateline only in case of reprojection, Oracle won't use the spatial index
  // with two or-ed bboxes and fixing the issue at the store level requires more
  // time/resources than we presently have
  this.queryAcrossDateline =
      !CRS.equalsIgnoreMetadata(
          sourceCRS, renderingEnvelope.getCoordinateReferenceSystem());
  checkReprojection();
}

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

@Test
public void testGetHorizontalCrs() {
  assertEquals(
      DefaultEngineeringCRS.GENERIC_2D,
      CRS.getHorizontalCRS(DefaultEngineeringCRS.GENERIC_2D));
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

public Object visit(BBOX filter, Object extraData) {
  // if no srs is specified we can't transform anyways
  String srs = filter.getSRS();
  if (srs != null && !"".equals(srs.trim())) return super.visit(filter, extraData);
  if (defaultCrs == null
      || filter.getBounds() == null
      || defaultCrs.getCoordinateSystem().getDimension()
          == filter.getBounds().getDimension()) {
    return getFactory(extraData)
        .bbox(
            filter.getExpression1(),
            ReferencedEnvelope.create(filter.getBounds(), defaultCrs));
  } else {
    try {
      SingleCRS horizontalCRS = CRS.getHorizontalCRS(defaultCrs);
      ReferencedEnvelope bounds =
          ReferencedEnvelope.create(filter.getBounds(), horizontalCRS);
      return getFactory(extraData).bbox(filter.getExpression1(), bounds);
    } catch (Exception e) {
      throw new RuntimeException("Could not decode srs '" + srs + "'", e);
    }
  }
}

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

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

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

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

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

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

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

@Test
  public void force3DCRS3DEnvelope() throws Exception {
    CoordinateReferenceSystem crs = CRS.decode("EPSG:4939", true);
    CoordinateReferenceSystem hcrs = CRS.getHorizontalCRS(crs);
    BBOX bbox =
        ff.bbox(
            ff.property("the_geom"),
            new ReferencedEnvelope3D(-180, 180, -90, 90, 0, 100, null));
    DefaultCRSFilterVisitor visitor = new DefaultCRSFilterVisitor(ff, crs);
    BBOX filtered = (BBOX) bbox.accept(visitor, null);
    Literal box = (Literal) filtered.getExpression2();
    Geometry g = (Geometry) box.evaluate(null);
    assertEquals(crs, g.getUserData());
  }
}

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

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

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

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

相关文章