/** 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); }
return ((Datum) info).getScope(); } else if (info instanceof CoordinateOperation) { return ((CoordinateOperation) info).getScope(); return ((Datum) info).getDomainOfValidity(); } else if (info instanceof CoordinateOperation) { return ((CoordinateOperation) info).getDomainOfValidity(); return ((CoordinateOperation) info).getOperationVersion(); .getCoordinateOperationAccuracy() .toArray(AbstractCoordinateOperation.EMPTY_ACCURACY_ARRAY);
final CoordinateReferenceSystem sourceCRS = operation.getSourceCRS(); final CoordinateReferenceSystem targetCRS = operation.getTargetCRS(); final Map<String, Object> properties = AbstractIdentifiedObject.getProperties(operation, null); properties, inverted.toArray(new CoordinateOperation[inverted.size()])); final MathTransform transform = operation.getMathTransform().inverse(); final Class<? extends CoordinateOperation> type = AbstractCoordinateOperation.getType(operation);
if (step2 == null) return concatenate(step1, step3); if (step3 == null) return concatenate(step1, step2); assert equalsIgnoreMetadata(step1.getTargetCRS(), step2.getSourceCRS()) : step1; assert equalsIgnoreMetadata(step2.getTargetCRS(), step3.getSourceCRS()) : step3; if (step1.getName() == AXIS_CHANGES) return concatenate(concatenate(step1, step2), step3); if (step3.getName() == AXIS_CHANGES) return concatenate(step1, concatenate(step2, step3)); final CoordinateReferenceSystem sourceCRS = step1.getSourceCRS(); final CoordinateReferenceSystem targetCRS = step3.getTargetCRS(); return createConcatenatedOperation( getTemporaryName(sourceCRS, targetCRS),
return null; final CoordinateReferenceSystem sourceCRS = operation.getSourceCRS(); if (sourceCRS != null) { final CoordinateReferenceSystem crs = envelope.getCoordinateReferenceSystem(); if (crs != null && !equalsIgnoreMetadata(crs, sourceCRS)) { throw new MismatchedReferenceSystemException( Errors.format(ErrorKeys.MISMATCHED_COORDINATE_REFERENCE_SYSTEM)); MathTransform mt = operation.getMathTransform(); final GeneralDirectPosition centerPt = new GeneralDirectPosition(mt.getTargetDimensions()); final GeneralEnvelope transformed = transform(mt, envelope, centerPt); final CoordinateSystem cs = sourceCRS.getCoordinateSystem(); if (cs != null) { // Should never be null, but check as a paranoiac safety. DirectPosition sourcePt = null; transformed.add(targetPt = mt.transform(sourcePt, targetPt)); transformed.add(targetPt = mt.transform(sourcePt, targetPt)); final CoordinateReferenceSystem targetCRS = operation.getTargetCRS(); if (targetCRS == null) { return transformed; final CoordinateSystem targetCS = targetCRS.getCoordinateSystem(); if (targetCS == null) {
CoordinateReferenceSystem crs = CRS.decode(SOURCE_CRS); assertSame(crs, co.getSourceCRS()); crs = CRS.decode(TARGET_CRS); assertSame(crs, co.getTargetCRS()); assertTrue(co.getMathTransform() instanceof MathTransform); double[] p = new double[2]; co.getMathTransform().transform(SRC_TEST_POINT, 0, p, 0, 1); assertEquals(p[0], DST_TEST_POINT[0], 1e-8); assertEquals(p[1], DST_TEST_POINT[1], 1e-8);
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); 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)) .getName() .getCode(), .getName() .getCode(),
assertTrue(operation.getSourceCRS() instanceof ProjectedCRS); assertTrue(operation.getTargetCRS() instanceof GeocentricCRS); assertTrue(operation.getTargetCRS().getCoordinateSystem() instanceof CartesianCS); final MathTransform mt = operation.getMathTransform(); final double[] output = new double[input.length * 2]; mt.transform(input, 0, output, 0, 1); mt.transform(input, 0, output, input.length, 1);
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); }
if (getDimension() != targetCRS.getCoordinateSystem().getDimension()) { if (lenient) { return JTS.transformTo3D(this, targetCRS, lenient, numPointsForTransformation); Errors.format( ErrorKeys.MISMATCHED_DIMENSION_$3, crs.getName().getCode(), Integer.valueOf(getDimension()), Integer.valueOf(targetCRS.getCoordinateSystem().getDimension()))); 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 static Coordinate eastNorthToLatLong(double x, double y, String sourceCrs, String targetCrs) throws FactoryException, MismatchedDimensionException, TransformException { CoordinateReferenceSystem targetCrsDecoded = CRS.decode(targetCrs); CoordinateReferenceSystem sourceCrsDecoded = CRS.decode(sourceCrs); CoordinateOperation op = new DefaultCoordinateOperationFactory().createOperation(sourceCrsDecoded, targetCrsDecoded); DirectPosition source = new GeneralDirectPosition(x, y); DirectPosition target = op.getMathTransform().transform(source, null); Double targetX = target.getOrdinate(0); Double targetY = target.getOrdinate(1); return new Coordinate(targetY, targetX); }
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); .append(state.getRequestedEnvelope().toString()) .append(" crs ") .append(crs.toWKT()) .toString());
boolean lenient) throws FactoryException { if (equalsIgnoreMetadata(sourceCRS, targetCRS)) { return IdentityTransform.create(sourceCRS.getCoordinateSystem().getDimension()); CoordinateOperationFactory operationFactory = getCoordinateOperationFactory(lenient); return operationFactory.createOperation(sourceCRS, targetCRS).getMathTransform();
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()); }
final CoordinateReferenceSystem next = op.getSourceCRS(); if (previous != null && next != null) { final int dim1 = previous.getCoordinateSystem().getDimension(); final int dim2 = next.getCoordinateSystem().getDimension(); if (dim1 != dim2) { throw new IllegalArgumentException(Errors.getResources(properties).getString( previous = op.getTargetCRS(); // For next iteration cycle. MathTransform step = op.getMathTransform(); if (op instanceof ConcatenatedOperation) { final List<? extends CoordinateOperation> children = ((ConcatenatedOperation) op).getOperations(); final CoordinateOperation[] asArray = children.toArray(new CoordinateOperation[children.size()]); initialize(properties, asArray, flattened, (step == null) ? mtFactory : null, false, setAccuracy, setDomain); } else if (!step.isIdentity()) { flattened.add(op); coordinateOperationAccuracy = op.getCoordinateOperationAccuracy(); } else { coordinateOperationAccuracy = null; final Extent domain = op.getDomainOfValidity(); if (domain != null) { if (domainOfValidity == null) {
final int dimension = operation.getSourceCRS().getCoordinateSystem().getDimension(); final MathTransform mt = operation.getMathTransform(); final double[] result = new double[mt.getTargetDimensions()]; final double[] domainCoordinate; final DirectPositionView positionInDomain; if (toDomainOfValidity != null && (bbox = CRS.getGeographicBoundingBox(operation)) != null) { domainOfValidity = new ImmutableEnvelope(bbox); domainCoordinate = new double[toDomainOfValidity.getTargetDimensions()]; positionInDomain = new DirectPositionView.Double(domainCoordinate); } else { if (coordinates.length != dimension) { throw new MismatchedDimensionException(Errors.format(Errors.Keys.MismatchedDimensionForCRS_3, operation.getSourceCRS().getName().getCode(), dimension, coordinates.length)); mt.transform(coordinates, 0, result, 0, 1); for (int i=0; i<result.length; i++) { if (i != 0) {
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)) {
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);
/** 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); }
final CoordinateReferenceSystem targetCRS) throws FactoryException { if ((prepend == null || prepend.isIdentity()) && (append == null || append.isIdentity())) { if (!CRS.equalsIgnoreMetadata(sourceCRS, operation.getSourceCRS()) || !CRS.equalsIgnoreMetadata(targetCRS, operation.getTargetCRS())) { return new ForcedCRSOperation(operation, sourceCRS, targetCRS); } else { } else { final CoordinateOperation last = op[op.length - 1]; op[0] = transform(sourceCRS, prepend, first, null, first.getTargetCRS()); op[op.length - 1] = transform(last.getSourceCRS(), null, last, append, targetCRS); MathTransform transform = operation.getMathTransform(); final MathTransformFactory mtFactory = getMathTransformFactory(); if (prepend != null) { transform = mtFactory.createConcatenatedTransform(transform, append); assert !transform.equals(operation.getMathTransform()) : transform; final Class<? extends CoordinateOperation> type = AbstractCoordinateOperation.getType(operation);