use of org.opengis.referencing.operation.SingleOperation in project sis by apache.
the class EPSGFactoryTest method testConversion.
/**
* Tests the "UTM zone 10N" conversion (EPSG:16010).
*
* @throws FactoryException if an error occurred while querying the factory.
*/
@Test
@DependsOnMethod("testProjectedWithSharedConversion")
public void testConversion() throws FactoryException {
final EPSGFactory factory = TestFactorySource.factory;
assumeNotNull(factory);
/*
* Fetch directly the "UTM zone 10N" operation. Because this operation was not obtained in
* the context of a projected CRS, the source and target CRS shall be unspecified (i.e. null).
*/
final CoordinateOperation operation = factory.createCoordinateOperation("16010");
assertEpsgNameAndIdentifierEqual("UTM zone 10N", 16010, operation);
assertInstanceOf("EPSG::16010", Conversion.class, operation);
assertNull("sourceCRS", operation.getSourceCRS());
assertNull("targetCRS", operation.getTargetCRS());
assertNull("transform", operation.getMathTransform());
/*
* Fetch the "WGS 72 / UTM zone 10N" projected CRS.
* The operation associated to this CRS should now define the source and target CRS.
*/
final ProjectedCRS crs = factory.createProjectedCRS("32210");
final CoordinateOperation projection = crs.getConversionFromBase();
assertEpsgNameAndIdentifierEqual("WGS 72 / UTM zone 10N", 32210, crs);
assertEpsgNameAndIdentifierEqual("UTM zone 10N", 16010, projection);
assertNotSame("The defining conversion and the actual conversion should differ since the " + "actual conversion should have semi-axis length values.", projection, operation);
assertInstanceOf("EPSG::16010", CylindricalProjection.class, projection);
assertNotNull("sourceCRS", projection.getSourceCRS());
assertNotNull("targetCRS", projection.getTargetCRS());
assertNotNull("transform", projection.getMathTransform());
/*
* Compare the conversion obtained directly with the conversion obtained
* indirectly through a projected CRS. Both should use the same method.
*/
final OperationMethod copMethod = ((SingleOperation) operation).getMethod();
final OperationMethod crsMethod = ((SingleOperation) projection).getMethod();
assertEpsgNameAndIdentifierEqual("Transverse Mercator", 9807, copMethod);
assertEpsgNameAndIdentifierEqual("Transverse Mercator", 9807, crsMethod);
try {
assertSame("Conversion method", copMethod, crsMethod);
assertSame("Conversion method", copMethod, factory.createOperationMethod("9807"));
} catch (AssertionError error) {
out.println("The following contains more information about a JUnit test failure.");
out.println("See the JUnit report for the stack trace. Below is a cache dump.");
out.println("See the operation method EPSG:9807 and compare with:");
out.print(" - Method obtained directly: ");
out.println(System.identityHashCode(copMethod));
out.print(" - Method obtained indirectly: ");
out.println(System.identityHashCode(crsMethod));
out.println("Content of EPSGFactory cache:");
factory.printCacheContent(out);
throw error;
}
}
use of org.opengis.referencing.operation.SingleOperation in project sis by apache.
the class CoordinateOperationFinderTest method testGeographic2D_to_3D.
/**
* Tests the conversion from a two-dimensional geographic CRS to a three-dimensional geographic CRS.
* Ordinate values of the vertical dimension should be set to zero.
*
* @throws FactoryException if the operation can not be created.
* @throws TransformException if an error occurred while converting the test points.
*/
@Test
@DependsOnMethod("testGeographic3D_to_2D")
public void testGeographic2D_to_3D() throws FactoryException, TransformException {
final GeographicCRS sourceCRS = CommonCRS.WGS84.geographic();
final GeographicCRS targetCRS = CommonCRS.WGS84.geographic3D();
final CoordinateOperation operation = finder.createOperation(sourceCRS, targetCRS);
assertSame("sourceCRS", sourceCRS, operation.getSourceCRS());
assertSame("targetCRS", targetCRS, operation.getTargetCRS());
assertEquals("name", "Axis changes", operation.getName().getCode());
assertInstanceOf("operation", Conversion.class, operation);
final ParameterValueGroup parameters = ((SingleOperation) operation).getParameterValues();
assertEquals("parameters.descriptor", "Geographic2D to 3D conversion", parameters.getDescriptor().getName().getCode());
assertEquals("parameters.height", 0, parameters.parameter("height").doubleValue(), STRICT);
transform = operation.getMathTransform();
assertInstanceOf("transform", LinearTransform.class, transform);
assertEquals("sourceDimensions", 2, transform.getSourceDimensions());
assertEquals("targetDimensions", 3, transform.getTargetDimensions());
Assert.assertMatrixEquals("transform.matrix", Matrices.create(4, 3, new double[] { 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1 }), ((LinearTransform) transform).getMatrix(), STRICT);
verifyTransform(new double[] { 30, 10, 20, 30 }, new double[] { 30, 10, 0, 20, 30, 0 });
validate();
}
use of org.opengis.referencing.operation.SingleOperation in project sis by apache.
the class CoordinateOperationFinderTest method testGeographicToProjected.
/**
* Tests conversion from a geographic to a projected CRS without datum of axis changes.
*
* @throws ParseException if a CRS used in this test can not be parsed.
* @throws FactoryException if the operation can not be created.
* @throws TransformException if an error occurred while converting the test points.
*/
@Test
@DependsOnMethod("testIdentityTransform")
public void testGeographicToProjected() throws ParseException, FactoryException, TransformException {
final CoordinateReferenceSystem sourceCRS = parse("$Sphere");
final CoordinateReferenceSystem targetCRS = parse("ProjectedCRS[“TM”,\n" + " $Sphere,\n" + " Conversion[“TM”,\n" + " Method[“Transverse Mercator”],\n" + " Parameter[“Longitude of natural origin”, 170],\n" + " Parameter[“Latitude of natural origin”, 50],\n" + " Parameter[“Scale factor at natural origin”, 0.95]],\n" + " CS[Cartesian, 2],\n" + " Axis[“x”, EAST],\n" + " Axis[“y”, NORTH],\n" + " Unit[“US survey foot”, 0.304800609601219]]");
final CoordinateOperation operation = finder.createOperation(sourceCRS, targetCRS);
assertSame("sourceCRS", sourceCRS, operation.getSourceCRS());
assertSame("targetCRS", targetCRS, operation.getTargetCRS());
assertEquals("name", "TM", operation.getName().getCode());
assertInstanceOf("operation", Projection.class, operation);
final ParameterValueGroup param = ((SingleOperation) operation).getParameterValues();
assertEquals("semi_major", 6370997, param.parameter("semi_major").doubleValue(), STRICT);
assertEquals("semi_minor", 6370997, param.parameter("semi_minor").doubleValue(), STRICT);
assertEquals("latitude_of_origin", 50, param.parameter("latitude_of_origin").doubleValue(), STRICT);
assertEquals("central_meridian", 170, param.parameter("central_meridian").doubleValue(), STRICT);
assertEquals("scale_factor", 0.95, param.parameter("scale_factor").doubleValue(), STRICT);
assertEquals("false_easting", 0, param.parameter("false_easting").doubleValue(), STRICT);
assertEquals("false_northing", 0, param.parameter("false_northing").doubleValue(), STRICT);
transform = operation.getMathTransform();
tolerance = ANGULAR_TOLERANCE;
verifyTransform(new double[] { 170, 50 }, new double[] { 0, 0 });
validate();
transform = transform.inverse();
tolerance = LINEAR_TOLERANCE;
λDimension = new int[] { 0 };
verifyTransform(new double[] { 0, 0 }, new double[] { 170, 50 });
validate();
}
Aggregations