throws DataSourceException { if (CRS.equalsIgnoreMetadata( state.getRequestedEnvelope().getCoordinateReferenceSystem(), this.crs)) { state.setRequestEnvelopeTransformed(state.getRequestedEnvelope()); operationFactory.createOperation( state.getRequestedEnvelope().getCoordinateReferenceSystem(), crs); if (op.getMathTransform().isIdentity()) { // Identity Transform ? state.setRequestEnvelopeTransformed(state.getRequestedEnvelope()); return; // and finish state.setRequestEnvelopeTransformed(CRS.transform(op, state.getRequestedEnvelope())); state.getRequestEnvelopeTransformed().setCoordinateReferenceSystem(crs);
/** * Returns all available operations for conversion or transformation between two coordinate * reference systems. The operation creation is delegated to the {@linkplain * CoordinateOperationFactory coordinate operation factory} specified at construction time and * the result is not cached. * * @param sourceCRS Input coordinate reference system. * @param targetCRS Output coordinate reference system. * @return A Set of coordinate operations from {@code sourceCRS} to {@code targetCRS}. * @throws FactoryException if there was a failure retrieving or creating the operations. */ @Override public Set<CoordinateOperation> findOperations( final CoordinateReferenceSystem sourceCRS, final CoordinateReferenceSystem targetCRS) throws FactoryException { ensureNonNull("sourceCRS", sourceCRS); ensureNonNull("targetCRS", targetCRS); return getBackingFactory().findOperations(sourceCRS, targetCRS); }
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); final CoordinateOperation operation = factory.createOperation(sourceCRS, targetCRS); final boolean force2D = (sourceCRS != compatibleSourceCRS); step2 = factory.createOperation(targetCRS, compatibleSourceCRS).getMathTransform(); step3 = (force2D ? sourceGG.getGridToCRS2D(CORNER) : sourceGG.getGridToCRS(CORNER)) sourceEnvelope = sourceCoverage.getEnvelope(); // Don't force this one to 2D. targetEnvelope = CRS.transform(operation, sourceEnvelope); targetEnvelope.setCoordinateReferenceSystem(targetCRS); source = targetGG.reduce(source); target = targetGG.reduce(target); if (!(new GeneralEnvelope(source).contains(target, true))) { if (interpolation != null && !(interpolation instanceof InterpolationNearest)) {
final BoundingBoxType bbox = request.getDomainSubset().getBoundingBox(); final CoordinateReferenceSystem nativeCRS = originalEnvelope.getCoordinateReferenceSystem(); final GeneralEnvelope requestedEnvelopeInNativeCRS; final GeneralEnvelope requestedEnvelope; upperCorner[i] = (Double) bbox.getUpperCorner().get(i); requestedEnvelope = new GeneralEnvelope(lowerCorner, upperCorner); requestedEnvelope.setCoordinateReferenceSystem(nativeCRS); requestedEnvelopeInNativeCRS = requestedEnvelope; } else { final CoordinateReferenceSystem bboxCRS = CRS.decode(bbox.getCrs()); requestedEnvelope.setCoordinateReferenceSystem(bboxCRS); if (!CRS.equalsIgnoreMetadata(bboxCRS, nativeCRS)) { CoordinateOperationFactory of = CRS.getCoordinateOperationFactory(true); CoordinateOperation co = of.createOperation(bboxCRS, nativeCRS); requestedEnvelopeInNativeCRS = CRS.transform(co, requestedEnvelope); } else { if (reprojectionNeeded) { CoordinateOperationFactory of = CRS.getCoordinateOperationFactory(true); CoordinateOperation co = of.createOperation(nativeCRS, targetCRS); intersectionEnvelope = CRS.transform(co, intersectionEnvelopeInSourceCRS); } else {
/** Should fails unless GEOT-352 has been fixed. */ @Test(expected = OperationNotFoundException.class) public void testHtoH() throws Exception { final CoordinateReferenceSystem sourceCRS = crsFactory.createFromWKT(NAD27_H); final CoordinateReferenceSystem targetCRS = crsFactory.createFromWKT(WGS84_H); final CoordinateOperation op = opFactory.createOperation(sourceCRS, targetCRS); final MathTransform mt = op.getMathTransform(); assertNotSame(sourceCRS, op.getSourceCRS()); assertNotSame(targetCRS, op.getTargetCRS()); assertFalse(mt.isIdentity()); assertInterfaced(mt); }
requestCRS = CRS.getHorizontalCRS(requestedBBox.getCoordinateReferenceSystem()); try { if (!CRS.equalsIgnoreMetadata( requestCRS, rasterManager.spatialDomainManager.coverageCRS2D)) destinationToSourceTransform = CRS.findMathTransform( requestCRS, rasterManager.spatialDomainManager.coverageCRS2D, true); && !destinationToSourceTransform.isIdentity()) { final GeneralEnvelope temp = CRS.transform( requestedBBox, rasterManager.spatialDomainManager.coverageCRS2D); temp.setCoordinateReferenceSystem(rasterManager.spatialDomainManager.coverageCRS2D); cropBBox = new ReferencedEnvelope(temp); CoordinateOperationFactory factory = CRS.getCoordinateOperationFactory(true); CoordinateOperation op = factory.createOperation( requestCRS, rasterManager.spatialDomainManager.coverageGeographicCRS2D); requestedBBOXInCoverageGeographicCRS = CRS.transform(op, requestedBBox); requestedBBOXInCoverageGeographicCRS.setCoordinateReferenceSystem( rasterManager.spatialDomainManager.coverageGeographicCRS2D); requestedBBOXInCoverageGeographicCRS = new GeneralEnvelope(requestCRS);
protected void setUp() throws Exception { super.setUp(); target = CRS.decode("EPSG:3005"); MathTransform2D tx = (MathTransform2D) ReferencingFactoryFinder.getCoordinateOperationFactory(null) .createOperation(crs, target) .getMathTransform(); transformer = new GeometryCoordinateSequenceTransformer(); transformer.setMathTransform(tx); }
sameCRS = CRS.equalsIgnoreMetadata(targetCRS, sourceCRS); if (sameGG && sameCRS) { return sourceCoverage; ReferencingFactoryFinder.getCoordinateOperationFactory(hints); final MathTransformFactory mtFactory = ReferencingFactoryFinder.getMathTransformFactory(hints); gridRange = CRS.transform(allSteps.inverse(), gridRange); targetGG = new GridGeometry2D(new GeneralGridRange(gridRange), step1, targetCRS); step2 = factory.createOperation(targetCRS, sourceCRS).getMathTransform(); 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);
bbox.setCrs("EPSG:4326"); CoordinateReferenceSystem bboxCRs = CRS.decode(bbox.getCrs()); Envelope gridEnvelope = meta.getCoverage().getEnvelope(); GeneralEnvelope gridEnvelopeBboxCRS = null; if (bboxCRs instanceof GeographicCRS) { try { CoordinateOperationFactory cof = CRS.getCoordinateOperationFactory(true); final CoordinateOperation operation = cof.createOperation(gridEnvelope .getCoordinateReferenceSystem(), bboxCRs); gridEnvelopeBboxCRS = CRS.transform(operation, gridEnvelope); } catch (Exception e) { final double envMax = gridEnvelopeBboxCRS.getMaximum(i); if (envMax >= lower.get(i)) upper.set(i, upper.get(i) + (axis.getMaximumValue() - axis.getMinimumValue()));
final CoordinateOperationFactory factory = ReferencingFactoryFinder.getCoordinateOperationFactory(hints); final MathTransformFactory mtFactory; if (factory instanceof AbstractCoordinateOperationFactory) { mtFactory = ((AbstractCoordinateOperationFactory) factory).getMathTransformFactory(); } else { mtFactory = ReferencingFactoryFinder.getMathTransformFactory(hints); if (CRS.equalsIgnoreMetadata(sourceMapCrs, targetMapCrs)) { allSteps = mtFactory.createConcatenatedTransform(step1, step3); } else { CoordinateOperation step2Operation = factory.createOperation(targetMapCrs, sourceMapCrs); MathTransform step2 = step2Operation.getMathTransform(); if (step1.equals(step3.inverse())) { allSteps = step2; } else { if (allSteps.isIdentity() || (allSteps instanceof AffineTransform && XAffineTransform.isIdentity((AffineTransform) allSteps, EPS))) {
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);
/** * Check we are actually using the EPSG database for anything not in override * * @throws TransformException */ @Test public void testFallbackOnEPSGDatabaseStd() throws Exception { // Test CRSs CoordinateReferenceSystem source = CRS.decode("EPSG:3002"); CoordinateReferenceSystem target = CRS.decode("EPSG:4326"); CoordinateOperation co = CRS.getCoordinateOperationFactory(true).createOperation(source, target); ConcatenatedOperation cco = (ConcatenatedOperation) co; // the EPSG one only has two steps, the non EPSG one 4 assertEquals(2, cco.getOperations().size()); }
final CoordinateReferenceSystem sourceCRS = DefaultGeographicCRS.WGS84_3D; final CoordinateReferenceSystem targetCRS = DefaultGeocentricCRS.CARTESIAN; final CoordinateOperation operation = opFactory.createOperation(sourceCRS, targetCRS); final MathTransform transform = operation.getMathTransform(); final int dimension = transform.getSourceDimensions(); assertEquals("Source dimension", 3, dimension); assertEquals("Target dimension", 3, transform.getTargetDimensions()); assertSame("Inverse transform", transform, transform.inverse().inverse()); assertInterfaced(transform);
CRS.getHorizontalCRS(envelope.getCoordinateReferenceSystem()); if (envelopeCrs2D != null && !CRS.equalsIgnoreMetadata(crs, envelopeCrs2D)) { CoordinateOperationFactory operationFactory = CRS.getCoordinateOperationFactory(true); CoordinateOperation op = operationFactory.createOperation(envelopeCrs2D, crs); envelope = CRS.transform(op, envelope); envelope.setCoordinateReferenceSystem(crs); requestedRes[0] = envelope.getSpan(0) / dim.getWidth(); requestedRes[1] = envelope.getSpan(1) / dim.getHeight();
CRS.getCoordinateOperationFactory(lenient); coordinateOperationFactory.createOperation(crs, targetCRS); final GeneralEnvelope transformed = CRS.transform(operation, this); transformed.setCoordinateReferenceSystem(targetCRS); final MathTransform transform = operation.getMathTransform(); JTS.transform(this, target, transform, numPointsForTransformation);
public void testOperationSourceTarget() throws Exception { // flip one way CoordinateReferenceSystem source = CRS.decode("EPSG:32638", true); // lon/lat CoordinateReferenceSystem target = CRS.decode("EPSG:4326", false); // lat/lon CoordinateOperationFactory coordinateOperationFactory = CRS.getCoordinateOperationFactory(true); CoordinateOperation co = coordinateOperationFactory.createOperation(source, target); assertEquals(source, co.getSourceCRS()); assertEquals(target, co.getTargetCRS()); // flip the other source = CRS.decode("EPSG:32638", false); // lat/lon target = CRS.decode("EPSG:4326", true); // lon/lat co = coordinateOperationFactory.createOperation(source, target); assertEquals(source, co.getSourceCRS()); assertEquals(target, co.getTargetCRS()); }
.getCRS2D(envelope.getCoordinateReferenceSystem()); && !CRS.equalsIgnoreMetadata(crs, crs2D)) { final MathTransform tr = operationFactory.createOperation( crs2D, crs).getMathTransform(); if (!tr.isIdentity()) envelope = CRS.transform(tr, envelope); requestedRes[0] = envelope.getLength(0) / dim.getWidth(); requestedRes[1] = envelope.getLength(1) / dim.getHeight();
Exception exception; final StringBuffer buffer = new StringBuffer(); final CoordinateReferenceSystem crs2D = CRS.getHorizontalCRS(crs); if (crs2D == null) { exception = } else try { if (!CRS.equalsIgnoreMetadata(DefaultGeographicCRS.WGS84, crs2D)) { final CoordinateOperation op = ReferencingFactoryFinder.getCoordinateOperationFactory(null) .createOperation(crs2D, DefaultGeographicCRS.WGS84); bounds = CRS.transform(op, bounds, null);
/** Tests a transformation on a {@link DirectPosition} object. */ @Test public void testDirectPositionTransform() throws FactoryException, TransformException { CoordinateReferenceSystem crs = ReferencingFactoryFinder.getCRSFactory(null).createFromWKT(WKT.UTM_10N); MathTransform t = ReferencingFactoryFinder.getCoordinateOperationFactory(null) .createOperation(DefaultGeographicCRS.WGS84, crs) .getMathTransform(); DirectPosition position = new GeneralDirectPosition(-123, 55); position = t.transform(position, position); position = t.inverse().transform(position, position); assertEquals(-123, position.getOrdinate(0), 1E-6); assertEquals(55, position.getOrdinate(1), 1E-6); }
if (targetCRS == null || CRS.equalsIgnoreMetadata(reducedCRS, targetCRS)) { final GeneralEnvelope transformed; transformed = CRS.transform( CRS.getCoordinateOperationFactory(true) .createOperation(targetCRS, reducedCRS), target); final Envelope reduced; gridToCRS = GridGeometry2D.wrap(gridGeometry).getGridToCRS2D(); transformed.intersect(reduced); gridGeometry = new GridGeometry2D(PixelInCell.CELL_CENTER, gridToCRS, transformed, null);