本文整理了Java中org.geotools.referencing.CRS.transform()
方法的一些代码示例,展示了CRS.transform()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CRS.transform()
方法的具体详情如下:
包路径:org.geotools.referencing.CRS
类名称:CRS
方法名:transform
[英]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).
[中]将给定信封转换为指定的CRS。如果给定的信封为空,或者信封#getCoordinateReferenceSystem为空,或者给定的目标CRS为空,或者transform MathTransform#isIdentity,则返回的信封将保持不变。否则将返回一个新的转换信封。
如果有许多封套要转换,请不要使用此方法。当在CRS之间只有一个不能预先知道的包络进行变换时,提供这种方法是为了方便。如果有许多方法,或者如果CRS限制为已知值,则永远获取CoordinationOperation或MathTransform,并调用以下方法之一(除非性能不是问题)。
代码示例来源: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 ±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));
}
内容来源于网络,如有侵权,请联系作者删除!