/** * @see * org.geotools.geometry.jts.CoordinateSequenceTransformer#transform(org.locationtech.jts.geom.CoordinateSequence, * org.opengis.referencing.operation.MathTransform) */ public CoordinateSequence transform(CoordinateSequence cs, MathTransform transform) throws TransformException { if (cs instanceof PackedCoordinateSequence) { return transformInternal((PackedCoordinateSequence) cs, transform); } throw new TransformException( cs.getClass().getName() + " is not a implementation that is known to be transformable in place"); }
/** * Returns a new bounding box which contains the transformed shape of this bounding box. This is * a convenience method that delegate its work to the {@link #transform transform} method. */ public BoundingBox toBounds(final CoordinateReferenceSystem targetCRS) throws TransformException { try { return transform(targetCRS, true); } catch (FactoryException e) { throw new TransformException(e.getLocalizedMessage(), e); } }
/** * Returns a new bounding box which contains the transformed shape of this bounding box. This is * a convenience method that delegate its work to the {@link #transform transform} method. * * @since 2.4 */ public BoundingBox toBounds(final CoordinateReferenceSystem targetCRS) throws TransformException { try { return transform(targetCRS, true); } catch (FactoryException e) { throw new TransformException(e.getLocalizedMessage(), e); } }
/** * Search the TIN for the triangle that contains p * * @param p Point of interest * @return Triangle containing p * @throws TransformException if points are outside the area of TIN. */ private TINTriangle searchTriangle(DirectPosition p) throws TransformException { /* Optimization for finding triangles. * Assuming the point are close to each other - * so why not to check if next point is in the same triangle as previous one. */ // Take a reference to the previous triangle to avoid reentrancy // problems. TINTriangle potentialTriangle = previousTriangle; if (potentialTriangle != null && potentialTriangle.containsOrIsVertex(p)) { return potentialTriangle; } for (Iterator i = trianglesToKeysMap.keySet().iterator(); i.hasNext(); ) { TINTriangle triangle = (TINTriangle) i.next(); if (triangle.containsOrIsVertex(p)) { previousTriangle = triangle; return triangle; } } throw (new TransformException("Points are outside the scope")); }
throw new TransformException(Errors.format(ErrorKeys.NO_CONVERGENCE));
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; }
/** * Gets the derivative of this transform at a point. The default implementation always throw an * exception. Subclasses that implement the {@link MathTransform2D} interface should override * this method. Other subclasses should override {@link #derivative(DirectPosition)} instead. * * @param point The coordinate point where to evaluate the derivative. * @return The derivative at the specified point as a 2×2 matrix. * @throws MismatchedDimensionException if the input dimension is not 2. * @throws TransformException if the derivative can't be evaluated at the specified point. * @see MathTransform2D#derivative(Point2D) */ public Matrix derivative(final Point2D point) throws TransformException { final int dimSource = getSourceDimensions(); if (dimSource != 2) { throw new MismatchedDimensionException(constructMessage("point", 2, dimSource)); } throw new TransformException(Errors.format(ErrorKeys.CANT_COMPUTE_DERIVATIVE)); }
/** * Sets the {@link #sourceCRS} field and create the associated {@link #forward} transform. This * method do not create yet the {@link #inverse} transform, since it may not be needed. */ private void setSourceCRS(final CoordinateReferenceSystem crs) throws TransformException { final CoordinateReferenceSystem targetCRS = getCoordinateReferenceSystem(); final CoordinateOperation operation; try { operation = factory.createOperation(crs, targetCRS); } catch (FactoryException exception) { throw new TransformException(exception.getLocalizedMessage(), exception); } /* * Note: 'sourceCRS' must be set last, when we are sure that all other fields * are set to their correct value. This is in order to keep this instance in * a consistent state in case an exception is thrown. */ forward = operation.getMathTransform(); inverse = null; sourceCRS = crs; }
gridShift = FACTORY.createNTv2Grid(gridLocation); } catch (FactoryException e) { throw new TransformException( "NTv2 Grid " + gridLocation + " Could not be created", e); throw new TransformException(e.getLocalizedMessage(), e);
/** * Returns a two-dimensional coordinate reference system representing the two first dimensions * of the specified coordinate reference system. If {@code crs} is already a two-dimensional * CRS, then it is returned unchanged. Otherwise, if it is a {@link CompoundCRS}, then the head * coordinate reference system is examined. * * @param crs The coordinate system, or {@code null}. * @return A two-dimensional coordinate reference system that represents the two first * dimensions of {@code crs}, or {@code null} if {@code crs} was {@code null}. * @throws TransformException if {@code crs} can't be reduced to a two-coordinate system. We use * this exception class since this method is usually invoked in the context of a * transformation process. */ public static CoordinateReferenceSystem getCRS2D(CoordinateReferenceSystem crs) throws TransformException { if (crs != null) { while (crs.getCoordinateSystem().getDimension() != 2) { final List<CoordinateReferenceSystem> c = getComponents(crs); if (c == null) { throw new TransformException( Errors.format( ErrorKeys.CANT_REDUCE_TO_TWO_DIMENSIONS_$1, crs.getName())); } crs = c.get(0); } } return crs; }
/** * Invoked automatically when the {@code target pt} instruction were executed and a {@code test * tolerance} were previously set. The default implementation compares the transformed source * point with the expected target point. If a mismatch greater than the tolerance error is * found, an exception is thrown. Subclasses may overrides this method in order to performs more * tests. * * @throws TransformException if the source point can't be transformed, or a mistmatch is found. * @throws MismatchedDimensionException if the transformed source point doesn't have the * expected dimension. */ protected void test() throws TransformException, MismatchedDimensionException { final DirectPosition transformedSource = transform.transform(sourcePosition, null); final int sourceDim = transformedSource.getDimension(); final int targetDim = targetPosition.getDimension(); if (sourceDim != targetDim) { throw new MismatchedDimensionException( Errors.format(ErrorKeys.MISMATCHED_DIMENSION_$2, sourceDim, targetDim)); } for (int i = 0; i < sourceDim; i++) { // Use '!' for catching NaN. if (!(Math.abs(transformedSource.getOrdinate(i) - targetPosition.getOrdinate(i)) <= tolerance[Math.min(i, tolerance.length - 1)])) { throw new TransformException( "Expected " + targetPosition + " but got " + transformedSource); } } }
throw new TransformException(Errors.format(ErrorKeys.CANT_REPROJECT_$1, crs)); return transform(geom, transform); } catch (FactoryException exception) { throw new TransformException(Errors.format(ErrorKeys.CANT_REPROJECT_$1, crs));
throw new TransformException( "Unable to transform features into output coordinate reference system", ex);
this.destinationCRS = destinationCRS; if (this.destinationCRS == null) { throw new TransformException( Errors.format(ErrorKeys.CANT_SEPARATE_CRS_$1, this.destinationCRS));
CRS.getHorizontalCRS(envelope.getCoordinateReferenceSystem()); if (tempCRS == null) { throw new TransformException( Errors.format( ErrorKeys.CANT_REDUCE_TO_TWO_DIMENSIONS_$1,
throw new TransformException(Errors.format(ErrorKeys.CANT_COMPUTE_DERIVATIVE));
returnedCRS = CRS.getHorizontalCRS(coverage.getCoordinateReferenceSystem()); if (returnedCRS == null) throw new TransformException( Errors.format(ErrorKeys.CANT_REDUCE_TO_TWO_DIMENSIONS_$1, returnedCRS)); return returnedCRS;
throw new TransformException( "All attemptsto reproject the envelope " + envelope
operation = factory.createOperation(sourceCRS, targetCRS); } catch (FactoryException exception) { throw new TransformException( Errors.format(ErrorKeys.CANT_TRANSFORM_ENVELOPE), exception);
throw new TransformException( Errors.format(ErrorKeys.CANT_REDUCE_TO_TWO_DIMENSIONS_$1, destinationCrs)); final boolean lonFirst =