final CoordinateReferenceSystem sourceCRS = envelope.getCoordinateReferenceSystem(); if (sourceCRS != null) { if (!equalsIgnoreMetadata(sourceCRS, targetCRS)) { final CoordinateOperationFactory factory = getCoordinateOperationFactory(true); final CoordinateOperation operation; try { operation = factory.createOperation(sourceCRS, targetCRS); } catch (FactoryException exception) { throw new TransformException( Errors.format(ErrorKeys.CANT_TRANSFORM_ENVELOPE), exception); if (!operation.getMathTransform().isIdentity()) { envelope = transform(operation, envelope); } else if (!equalsIgnoreMetadata( envelope.getCoordinateReferenceSystem(), targetCRS)) { GeneralEnvelope tx = new GeneralEnvelope(envelope); tx.setCoordinateReferenceSystem(targetCRS); envelope = tx; return GeneralEnvelope.toGeneralEnvelope(envelope);
requestCRS = CRS.getHorizontalCRS(requestedBBox.getCoordinateReferenceSystem()); try { && !destinationToSourceTransform.isIdentity()) { final GeneralEnvelope temp = new GeneralEnvelope(CRS.transform(requestedBBox, coverageProperties.crs2D)); temp.setCoordinateReferenceSystem(coverageProperties.crs2D); cropBBox = new ReferencedEnvelope(temp); needsReprojection = true; if (LOGGER.isLoggable(Level.FINE)) LOGGER.log(Level.FINE, te.getLocalizedMessage(), te); if (!CRS.equalsIgnoreMetadata(coverageProperties.geographicCRS2D, requestCRS)) { CRS.findMathTransform( requestCRS, coverageProperties.geographicCRS2D, true); if (!requestCRSToCoverageGeographicCRS2D.isIdentity()) { requestedBBOXInCoverageGeographicCRS = CRS.transform(requestedBBox, coverageProperties.geographicCRS2D); requestedBBOXInCoverageGeographicCRS.setCoordinateReferenceSystem( coverageProperties.geographicCRS2D); if (LOGGER.isLoggable(Level.FINE)) LOGGER.log(Level.FINE, te.getLocalizedMessage(), te); } catch (FactoryException fe) { if (LOGGER.isLoggable(Level.FINE)) LOGGER.log(Level.FINE, fe.getLocalizedMessage(), fe);
final CoordinateReferenceSystem targetGGCRS = targetGG.getCoordinateReferenceSystem(); if (!CRS.equalsIgnoreMetadata(targetCRS, targetGGCRS) && !CRS.findMathTransform(targetCRS, targetGGCRS).isIdentity()) { throw new IllegalArgumentException( Errors.format( if (CRS.equalsIgnoreMetadata(sourceCRS, targetCRS)) { step2 = IdentityTransform.create(step1.getTargetDimensions()); step3 = step1.inverse(); allSteps = IdentityTransform.create(step1.getSourceDimensions()); targetGG = new GridGeometry2D(targetGG.getGridRange(), step1, targetCRS); sourceEnvelope = sourceCoverage.getEnvelope(); // Don't force this one to 2D. targetEnvelope = CRS.transform(operation, sourceEnvelope); targetEnvelope.setCoordinateReferenceSystem(targetCRS); throw new TransformException(Errors.format(ErrorKeys.NO_TRANSFORM2D_AVAILABLE)); source = targetGG.reduce(source); target = targetGG.reduce(target); if (!(new GeneralEnvelope(source).contains(target, true))) { if (interpolation != null && !(interpolation instanceof InterpolationNearest)) {
public static <T extends Geometry> T Transform(String sourceEpsgCRSCode, String targetEpsgCRSCode, T sourceObject) { try { CoordinateReferenceSystem sourceCRS = CRS.decode(sourceEpsgCRSCode); CoordinateReferenceSystem targetCRS = CRS.decode(targetEpsgCRSCode); final MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS, false); return (T) JTS.transform(sourceObject, transform); } catch (FactoryException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } catch (MismatchedDimensionException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } catch (TransformException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } } }
this.crs = CRS.parseWKT(wkt); final Integer epsgCode = CRS.lookupEpsgCode(this.crs, true); this.crs = CRS.decode("EPSG:" + epsgCode); CRS.transform( ProjectiveTransform.create(tempTransform), new GeneralEnvelope( ((GridEnvelope2D) this.originalGridRange))); } catch (IllegalStateException e) { LOGGER.log(Level.WARNING, e.getLocalizedMessage(), e);
sameCRS = CRS.equalsIgnoreMetadata(targetCRS, sourceCRS); if (sameGG && sameCRS) { return sourceCoverage; step2 = IdentityTransform.create(step1.getTargetDimensions()); step3 = step1.inverse(); allSteps = IdentityTransform.create(step1.getSourceDimensions()); targetGG = new GridGeometry2D(targetGG.getGridRange(), step1, targetCRS); } else { gridRange = CRS.transform(allSteps.inverse(), gridRange); targetGG = new GridGeometry2D(new GeneralGridRange(gridRange), step1, targetCRS); throw new CannotReprojectException(Errors.format(ErrorKeys.UNSPECIFIED_CRS)); step3 = sourceGG.getGridToCRS().inverse(); sourceEnvelope = sourceCoverage.getEnvelope(); targetEnvelope = CRS.transform(step2.inverse(), sourceEnvelope); targetEnvelope.setCoordinateReferenceSystem(targetCRS); final GeneralEnvelope gridRange; gridRange = CRS.transform(step1.inverse(), targetEnvelope); for (int i=gridRange.getDimension(); --i>=0;) { gridRange.setRange(i, gridRange.getMinimum(i) + 0.5, gridRange.getMaximum(i) + 0.5); throw new TransformException(Errors.format(ErrorKeys.NO_TRANSFORM2D_AVAILABLE));
if (LOGGER.isLoggable(Level.FINE)) LOGGER.log(Level.FINE, te.getLocalizedMessage(), te); if (!CRS.equalsIgnoreMetadata(coverageProperties.geographicCRS, requestCRS)) { CRS.transform(requestedBBox, coverageProperties.geographicCRS); requestedBBOXInCoverageGeographicCRS.setCoordinateReferenceSystem( coverageProperties.geographicCRS); requestedBBOXInCoverageGeographicCRS = new GeneralEnvelope(requestCRS); if (!requestedBBOXInCoverageGeographicCRS.intersects( coverageProperties.geographicBBox, true)) { computedBBox = null; CRS.transform( requestedBBOXInCoverageGeographicCRS, coverageProperties.crs2D); approximateRequestedBBoInNativeCRS.setCoordinateReferenceSystem(
throws TransformException, FactoryException { final CoordinateReferenceSystem tempCRS = CRS.getHorizontalCRS(coordinateReferenceSystem); if (tempCRS == null) throw new TransformException( Errors.format( ErrorKeys.CANT_REDUCE_TO_TWO_DIMENSIONS_$1, coordinateReferenceSystem)); CRS.findMathTransform(tempCRS, DefaultGeographicCRS.WGS84, true); transform.transform(cs, 0, csLatLong, 0, 2); transform.transform(newCsLatLong, 0, origProject, 0, 2);
dataCRS = CRS.decode( fsd.getSRS() ); MathTransform toDataCRS = CRS.findMathTransform(DefaultGeographicCRS.WGS84, dataCRS); maxbbox = JTS.transform(fsd.getLatLongBoundingBox(), null, toDataCRS, 10); } catch (FactoryException e) { WFS_1_0_0_DataStore.LOGGER.warning(e.getMessage()); maxbbox = null; } catch (MismatchedDimensionException e) { maxbbox = null; } catch (TransformException e) { WFS_1_0_0_DataStore.LOGGER.warning(e.getMessage()); maxbbox = null;
final CoordinateReferenceSystem crs2D = CRS.getHorizontalCRS(destinationCrs); if (crs2D == null) throw new TransformException( Errors.format(ErrorKeys.CANT_REDUCE_TO_TWO_DIMENSIONS_$1, destinationCrs)); final boolean lonFirst = final GeneralEnvelope newEnvelope = lonFirst ? new GeneralEnvelope( new double[] {mapExtent.getMinX(), mapExtent.getMinY()}, new double[] {mapExtent.getMaxX(), mapExtent.getMaxY()}) : new GeneralEnvelope( new double[] {mapExtent.getMinY(), mapExtent.getMinX()}, new double[] {mapExtent.getMaxY(), mapExtent.getMaxX()}); newEnvelope.setCoordinateReferenceSystem(destinationCrs); m.setGridRange(new GridEnvelope2D(paintArea)); m.setEnvelope(newEnvelope); return (AffineTransform) (m.createTransform().inverse());
MathTransform transform = CRS.findMathTransform(crs, DefaultGeographicCRS.WGS84_3D); Geometry geometry = transform(geom, transform); throw new TransformException(Errors.format(ErrorKeys.CANT_REPROJECT_$1, crs)); } else if (CRS.equalsIgnoreMetadata(crs, DefaultGeographicCRS.WGS84)) { return geom; } else { try { MathTransform transform = CRS.findMathTransform(crs, DefaultGeographicCRS.WGS84); return transform(geom, transform); } catch (FactoryException exception) { throw new TransformException(Errors.format(ErrorKeys.CANT_REPROJECT_$1, crs));
public CrsGeoCoding getCrsGeoCoding () { Coordinate2D coordUpperLeft = getUpperLeft(); CrsGeoCoding crsGeoCoding = null; String EPSG = getEPSG(); try { crsGeoCoding = new CrsGeoCoding(CRS.decode("EPSG:" + EPSG), getRasterWidth(), getRasterHeight(), coordUpperLeft.x, coordUpperLeft.y, getBestResolution(), getBestResolution(), 0.0, 0.0); } catch (FactoryException e) { e.printStackTrace(); } catch (TransformException e) { e.printStackTrace(); } return crsGeoCoding; }
PixelTranslation.translate( raster2Model, PixelInCell.CELL_CENTER, PixelInCell.CELL_CORNER); final Envelope gridRange = new GeneralEnvelope((GridEnvelope2D) originalGridRange); final GeneralEnvelope coverageEnvelope = CRS.transform(tempTransform, gridRange); originalEnvelope = coverageEnvelope; return; } catch (TransformException e) { if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.log(Level.WARNING, e.getLocalizedMessage(), e);
private CoordinateSequence transformInternal( PackedCoordinateSequence sequence, MathTransform transform) throws TransformException { start.setSequence(sequence); for (int i = 0; i < sequence.size(); i++) { start.setOffset(i); try { transform.transform(start, start); } catch (MismatchedDimensionException e) { throw new TransformException("", e); } } return sequence; }
if (!CRS.equalsIgnoreMetadata(requestedBBoxCRS2D, coverageCRS2D)) { final GeneralEnvelope temp = CRS.transform(requestedBBox, coverageCRS2D); temp.setCoordinateReferenceSystem(coverageCRS2D); requestedBBox = new ReferencedEnvelope(temp); } else if (LOGGER.isLoggable(Level.FINE)) LOGGER.log(Level.FINE, te.getLocalizedMessage(), te); DefaultGeographicCRS.WGS84); final GeneralEnvelope approximateRequestedBBoInNativeCRS = CRS.transform(approximateWGS84requestedBBox, coverageCRS2D); approximateRequestedBBoInNativeCRS.setCoordinateReferenceSystem(coverageCRS2D); requestedBBox = new ReferencedEnvelope(approximateRequestedBBoInNativeCRS);
private GridCoverage2D preProcess(GridCoverage2D inputCoverage, Geometry cropShape) { if (cropShape == null) { return inputCoverage; } Object userData = cropShape.getUserData(); CoordinateReferenceSystem tCrs = inputCoverage.getCoordinateReferenceSystem(); if (userData == null) { cropShape.setUserData(tCrs); } else if (userData instanceof CoordinateReferenceSystem) { CoordinateReferenceSystem sCrs = (CoordinateReferenceSystem) userData; if (!CRS.equalsIgnoreMetadata(sCrs, tCrs)) { try { MathTransform transform = CRS.findMathTransform(sCrs, tCrs, true); cropShape = JTS.transform(cropShape, transform); cropShape.setUserData(tCrs); } catch (FactoryException e) { throw new IllegalArgumentException("Could not create math transform"); } catch (MismatchedDimensionException e) { LOGGER.log(Level.FINER, e.getMessage(), e); } catch (TransformException e) { LOGGER.log(Level.FINER, e.getMessage(), e); } } } RasterClipOperation cropOperation = new RasterClipOperation(); return cropOperation.execute(inputCoverage, cropShape); }
protected void safeTransform(MathTransform trs, double[] in, double[] out) { try { trs.transform(in, 0, out, 0, 1); } catch (TransformException ex) { LOGGER.log(Level.WARNING, ex.getMessage(),ex); Arrays.fill(out, Double.NaN); } }
public static void transformCoordinate(Coordinate coord, MathTransform transform) { double[] points = new double[] { coord.x, coord.y }; try { transform.transform(points, 0, points, 0, 1); } catch (TransformException e) { e.printStackTrace(); } coord.x = points[0]; coord.y = points[1]; } }
this.destinationCRS = CRS.getHorizontalCRS(destinationCRS); if (this.destinationCRS == null) throw new TransformException(Errors.format( ErrorKeys.CANT_SEPARATE_CRS_$1, destinationCRS)); destinationEnvelope = new GeneralEnvelope(new ReferencedEnvelope(envelope, destinationCRS));
/** * Gets the derivative of this function at a value. * * @param value The value where to evaluate the derivative. * @return The derivative at the specified point. * @throws TransformException if the derivative can't be evaluated at the specified point. */ public final double derivative(final double value) throws TransformException { Category category = last; if (!(value >= category.minimum && value <= category.maximum) && Double.doubleToRawLongBits(value) != Double.doubleToRawLongBits(category.minimum)) { category = getCategory(value); if (category == null) { throw new TransformException(Errors.format(ErrorKeys.NO_CATEGORY_FOR_VALUE_$1, new Double(value))); } last = category; } return category.transform.derivative(value); }