congrats Icon
New! Announcing our next generation AI code completions
Read here
Tabnine Logo
CRS.transform
Code IndexAdd Tabnine to your IDE (free)

How to use
transform
method
in
org.geotools.referencing.CRS

Best Java code snippets using org.geotools.referencing.CRS.transform (Showing top 20 results out of 324)

origin: geoserver/geoserver

  envelope = CRS.transform(envelope, destCRS);
} catch (TransformException e) {
  throw (IOException)
origin: geoserver/geoserver

GridGeometry2D gg = coverage.getGridGeometry();
GeneralEnvelope padRange =
    CRS.transform(gg.getCRSToGrid2D(PixelOrientation.UPPER_LEFT), bounds);
GridEnvelope2D targetRange =
    new GridEnvelope2D(
origin: geoserver/geoserver

final GeneralEnvelope targetEnvelope;
if (!CRS.equalsIgnoreMetadata(sourceCRS, targetCRS)) {
  targetEnvelope = CRS.transform(envelope, targetCRS);
} else {
  targetEnvelope = new GeneralEnvelope(envelope);
origin: geoserver/geoserver

    CRS.transform(gridToWorldCorner, new GeneralEnvelope(testRange.getBounds()));
testEnvelope.setCoordinateReferenceSystem(reader.getCoordinateReferenceSystem());
origin: geotools/geotools

/**
 * Transforms an envelope using the given {@linkplain MathTransform math transform}. The
 * transformation is only approximative. Note that the returned envelope may not have the same
 * number of dimensions than the original envelope.
 *
 * <p>Note that this method can not handle the case where the envelope contains the North or
 * South pole, or when it cross the &plusmn;180° longitude, because {@linkplain MathTransform
 * math transforms} do not carry suffisient informations. For a more robust envelope
 * transformation, use {@link #transform(CoordinateOperation, Envelope)} instead.
 *
 * @param transform The transform to use.
 * @param envelope Envelope to transform, or {@code null}. This envelope will not be modified.
 * @return The transformed envelope, or {@code null} if {@code envelope} was null.
 * @throws TransformException if a transform failed.
 * @since 2.4
 * @see #transform(CoordinateOperation, Envelope)
 */
public static GeneralEnvelope transform(final MathTransform transform, final Envelope envelope)
    throws TransformException {
  return transform(transform, envelope, null);
}
origin: geoserver/geoserver

final CoordinateReferenceSystem nativeCRS = reader.getCoordinateReferenceSystem();
if (!CRS.equalsIgnoreMetadata(requestCRS, nativeCRS)) {
  requestedEnvelope = CRS.transform(requestedEnvelope, nativeCRS);
  GeneralEnvelope requestedGrid = CRS.transform(crsToGrid, requestedEnvelope);
  double[] spans = new double[requestedGrid.getDimension()];
  double[] resolutions = new double[requestedGrid.getDimension()];
origin: geotools/geotools

/**
 * Returns the pixel coordinate of a rectangle containing the specified geographic area. If the
 * rectangle can't be computed, then this method returns {@code null}.
 */
final Rectangle inverseTransform(Rectangle2D bounds) {
  if (bounds != null && gridFromCRS2D != null) {
    try {
      bounds = org.geotools.referencing.CRS.transform(gridFromCRS2D, bounds, null);
      final int xmin = (int) Math.floor(bounds.getMinX() - 0.5);
      final int ymin = (int) Math.floor(bounds.getMinY() - 0.5);
      final int xmax = (int) Math.ceil(bounds.getMaxX() - 0.5);
      final int ymax = (int) Math.ceil(bounds.getMaxY() - 0.5);
      return new Rectangle(xmin, ymin, xmax - xmin, ymax - ymin);
    } catch (TransformException exception) {
      // Ignore, since this method is invoked from 'GridCoverage.prefetch' only.
      // It doesn't matter if the transformation failed; 'prefetch' is just a hint.
    }
  }
  return null;
}
origin: geotools/geotools

/**
 * @see org.geotools.coverage.io.CoverageReadRequest#setDomainSubset(java.awt.Rectangle,
 *     org.opengis.referencing.operation.MathTransform2D,
 *     org.opengis.referencing.crs.CoordinateReferenceSystem)
 */
public void setDomainSubset(
    final Rectangle rasterArea,
    final MathTransform2D gridToWorldTrasform,
    final CoordinateReferenceSystem crs)
    throws MismatchedDimensionException, TransformException {
  // get input elements
  this.rasterArea = (Rectangle) rasterArea.clone();
  this.gridToWorldTransform = gridToWorldTrasform;
  // create a bbox
  GeneralEnvelope env =
      CRS.transform(
          gridToWorldTrasform, new ReferencedEnvelope(rasterArea.getBounds2D(), crs));
  this.geographicArea = new ReferencedEnvelope(new ReferencedEnvelope(env), crs);
}
origin: geotools/geotools

public BoundingBox toBounds(CoordinateReferenceSystem targetCRS) throws TransformException {
  Envelope transformed = new GeneralEnvelope((BoundingBox) this);
  transformed = CRS.transform(transformed, targetCRS);
  return new Envelope2D(transformed);
}
origin: geotools/geotools

/** Sets BBOX and SRS using the provided Envelope. */
public void setBBox(Envelope envelope) {
  String version = properties.getProperty(VERSION);
  boolean forceXY = version == null || !version.startsWith("1.3");
  String srsName = CRS.toSRS(envelope.getCoordinateReferenceSystem());
  CoordinateReferenceSystem crs = toServerCRS(srsName, forceXY);
  Envelope bbox;
  try {
    bbox = CRS.transform(envelope, crs);
  } catch (TransformException e) {
    bbox = envelope;
  }
  StringBuffer sb = new StringBuffer();
  sb.append(bbox.getMinimum(0));
  sb.append(",");
  sb.append(bbox.getMinimum(1) + ",");
  sb.append(bbox.getMaximum(0) + ",");
  sb.append(bbox.getMaximum(1));
  setBBox(sb.toString());
}
/**
origin: geotools/geotools

private void setEnvelopeFromTransform(AffineTransform tempTransform) throws TransformException {
  final GeneralEnvelope envelope =
      CRS.transform(
          ProjectiveTransform.create(tempTransform),
          new GeneralEnvelope(nativeGridRange));
  envelope.setCoordinateReferenceSystem(crs);
  setCoverageEnvelope(envelope);
}
origin: geotools/geotools

/**
 * Return a crop region from a specified envelope, leveraging on the grid to world
 * transformation.
 *
 * @param refinedRequestedBBox the crop envelope
 * @return a {@code Rectangle} representing the crop region.
 * @throws TransformException in case a problem occurs when going back to raster space.
 */
private Rectangle getCropRegion() throws TransformException {
  final MathTransform gridToWorldTransform = getOriginalGridToWorld(PixelInCell.CELL_CORNER);
  final MathTransform worldToGridTransform = gridToWorldTransform.inverse();
  final GeneralEnvelope rasterArea = CRS.transform(worldToGridTransform, requestedBBox);
  final Rectangle2D ordinates = rasterArea.toRectangle2D();
  // THIS IS FUNDAMENTAL IN ORDER TO AVOID PROBLEMS WHEN DOING TILING
  return ordinates.getBounds();
}
origin: geotools/geotools

private Rectangle computeRasterArea(
    ReferencedEnvelope computedBBox, MathTransform2D requestedWorldToGrid)
    throws TransformException, FactoryException {
  final ReferencedEnvelope cropBBOXInRequestCRS =
      Utils.reprojectEnvelope(computedBBox, requestCRS, requestedBBox);
  // make sure it falls within the requested envelope
  cropBBOXInRequestCRS.intersection((org.locationtech.jts.geom.Envelope) requestedBBox);
  // now go back to raster space
  Rectangle computedRasterArea =
      new GeneralGridEnvelope(
              CRS.transform(requestedWorldToGrid, cropBBOXInRequestCRS),
              PixelInCell.CELL_CORNER,
              false)
          .toRectangle();
  // intersect with the original requested raster space to be sure that we stay within
  // the requested raster area
  XRectangle2D.intersect(computedRasterArea, requestedRasterArea, computedRasterArea);
  return computedRasterArea;
}
origin: geotools/geotools

public void testTransformLambertAzimuthalEqualAreaWgs84NonPolar() throws Exception {
  CoordinateReferenceSystem crs = CRS.decode("EPSG:3035", true);
  // a bbox that does _not_ include the pole
  Envelope2D envelope = new Envelope2D(crs);
  envelope.setFrameFromDiagonal(4029000, 2676000, 4696500, 3567700);
  Envelope transformed = CRS.transform(envelope, DefaultGeographicCRS.WGS84);
  // check we did _not_ get the whole range of longitudes
  assertEquals(5.42, transformed.getMinimum(0), 1e-2);
  assertEquals(15.88, transformed.getMaximum(0), 1e-2);
}
origin: geotools/geotools

public void testTransformPolarStereographicToOther() throws Exception {
  CoordinateReferenceSystem antarcticPs = CRS.decode("EPSG:3031", true);
  CoordinateReferenceSystem australianPs = CRS.decode("EPSG:3032", true);
  Envelope2D envelope = new Envelope2D(antarcticPs);
  envelope.add(-4223632.8125, -559082.03125);
  envelope.add(5053710.9375, 3347167.96875);
  Envelope transformed = CRS.transform(envelope, australianPs);
  // has a false easting and northing, we can only check the spans are equal
  assertEquals(transformed.getSpan(0), transformed.getSpan(1), 1d);
  assertEquals(transformed.getMaximum(0), 1.2309982175378662E7, 1d);
}
origin: geotools/geotools

public void testTransformLambertAzimuthalEqualAreaWgs84() throws Exception {
  CoordinateReferenceSystem crs = CRS.decode("EPSG:3574", true);
  Envelope2D envelope = new Envelope2D(crs);
  // random bbox that does include the pole
  envelope.add(-3142000, -3142000);
  envelope.add(3142000, 3142000);
  Envelope transformed = CRS.transform(envelope, DefaultGeographicCRS.WGS84);
  // check we got the whole range of longitudes, since the original bbox contains the pole
  assertEquals(-180d, transformed.getMinimum(0), 0d);
  assertEquals(180d, transformed.getMaximum(0), 0d);
}
origin: geotools/geotools

public void testTransformPolarStereographicWgs84FalseOrigin() throws Exception {
  // this one has false origins at 6000000/6000000
  CoordinateReferenceSystem crs = CRS.decode("EPSG:3032", true);
  Envelope2D envelope = new Envelope2D(crs);
  envelope.add(5900000, 5900000);
  envelope.add(6100000, 6100000);
  Envelope transformed = CRS.transform(envelope, DefaultGeographicCRS.WGS84);
  // check we got the whole range of longitudes, since the original bbox contains the pole
  assertEquals(-180d, transformed.getMinimum(0), 0d);
  assertEquals(180d, transformed.getMaximum(0), 0d);
}
origin: geotools/geotools

public void testTransformPolarStereographicWgs84() throws Exception {
  CoordinateReferenceSystem crs = CRS.decode("EPSG:3031", true);
  Envelope2D envelope = new Envelope2D(crs);
  // random bbox that does include the pole
  envelope.add(-4223632.8125, -559082.03125);
  envelope.add(5053710.9375, 3347167.96875);
  Envelope transformed = CRS.transform(envelope, DefaultGeographicCRS.WGS84);
  // check we got the whole range of longitudes, since the original bbox contains the pole
  assertEquals(-180d, transformed.getMinimum(0), 0d);
  assertEquals(180d, transformed.getMaximum(0), 0d);
  // another bbox
  envelope = new Envelope2D(crs);
  // random bbox that does not include the pole, but it's really just slightly off it
  envelope.add(-10718812.640513, -10006238.053703);
  envelope.add(12228504.561708, -344209.75803081);
  transformed = CRS.transform(envelope, DefaultGeographicCRS.WGS84);
  assertEquals(-90, transformed.getMinimum(1), 0.1d);
}
origin: geotools/geotools

public void testTransformWgs84PolarStereographic() throws Exception {
  CoordinateReferenceSystem crs = CRS.decode("EPSG:3031", true);
  Envelope2D envelope = new Envelope2D(DefaultGeographicCRS.WGS84);
  envelope.add(-180, -90);
  envelope.add(180, 0);
  Envelope transformed = CRS.transform(envelope, crs);
  // the result is a square
  assertEquals(transformed.getMaximum(0), transformed.getMaximum(1), 1d);
  assertEquals(transformed.getMinimum(0), transformed.getMinimum(1), 1d);
  assertEquals(Math.abs(transformed.getMinimum(0)), transformed.getMaximum(0), 1d);
  assertEquals(transformed.getMaximum(0), 1.236739621845986E7, 1d);
}
origin: geotools/geotools

/** Tests the transformations of an envelope. */
@Test
public void testEnvelopeTransformation() throws FactoryException, TransformException {
  final CoordinateReferenceSystem mapCRS = CRS.parseWKT(WKT.UTM_10N);
  final CoordinateReferenceSystem WGS84 = DefaultGeographicCRS.WGS84;
  final MathTransform crsTransform = CRS.findMathTransform(WGS84, mapCRS, true);
  assertFalse(crsTransform.isIdentity());
  final GeneralEnvelope firstEnvelope, transformedEnvelope, oldEnvelope;
  firstEnvelope = new GeneralEnvelope(new double[] {-124, 42}, new double[] {-122, 43});
  firstEnvelope.setCoordinateReferenceSystem(WGS84);
  transformedEnvelope = CRS.transform(crsTransform, firstEnvelope);
  transformedEnvelope.setCoordinateReferenceSystem(mapCRS);
  oldEnvelope = CRS.transform(crsTransform.inverse(), transformedEnvelope);
  oldEnvelope.setCoordinateReferenceSystem(WGS84);
  assertTrue(oldEnvelope.contains(firstEnvelope, true));
  assertTrue(oldEnvelope.equals(firstEnvelope, 0.02, true));
}
org.geotools.referencingCRStransform

Javadoc

Transforms the given envelope to the specified CRS. If the given envelope is null, or the Envelope#getCoordinateReferenceSystem is null, or the given target CRS is null, or the transform MathTransform#isIdentity, then the envelope is returned unchanged. Otherwise a new transformed envelope is returned.

Don't use this method if there is many envelopes to transform. This method is provided as a convenience when there is only one envelope to transform between CRS that can't be known in advance. If there is many of them or if the CRS are restricted to known values, get the CoordinateOperation or MathTransform once for ever and invoke one of the methods below instead (unless if performance is not a concern).

Popular methods of CRS

  • decode
  • findMathTransform
  • equalsIgnoreMetadata
  • parseWKT
  • lookupEpsgCode
  • getAxisOrder
  • lookupIdentifier
  • toSRS
  • getHorizontalCRS
  • getEnvelope
  • getCoordinateOperationFactory
  • getAuthorityFactory
  • getCoordinateOperationFactory,
  • getAuthorityFactory,
  • getMapProjection,
  • getSupportedCodes,
  • getGeographicBoundingBox,
  • reset,
  • getEllipsoid,
  • getProjectedCRS,
  • getTemporalCRS

Popular in Java

  • Making http post requests using okhttp
  • getSystemService (Context)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • getApplicationContext (Context)
  • BorderLayout (java.awt)
    A border layout lays out a container, arranging and resizing its components to fit in five regions:
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • GridLayout (java.awt)
    The GridLayout class is a layout manager that lays out a container's components in a rectangular gri
  • ByteBuffer (java.nio)
    A buffer for bytes. A byte buffer can be created in either one of the following ways: * #allocate
  • StringTokenizer (java.util)
    Breaks a string into tokens; new code should probably use String#split.> // Legacy code: StringTo
  • BlockingQueue (java.util.concurrent)
    A java.util.Queue that additionally supports operations that wait for the queue to become non-empty
  • 14 Best Plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now