use of org.opengis.referencing.operation.OperationMethod in project sis by apache.
the class DefaultOperationMethodTest method testConstruction.
/**
* Tests the {@link DefaultOperationMethod#DefaultOperationMethod(Map, Integer, Integer, ParameterDescriptorGroup)}
* constructor.
*/
@Test
public void testConstruction() {
final OperationMethod method = create("Mercator (variant A)", "9804", "EPSG guidance note #7-2", 2);
assertEpsgNameAndIdentifierEqual("Mercator (variant A)", 9804, method);
assertTitleEquals("formula", "EPSG guidance note #7-2", method.getFormula().getCitation());
assertEquals("sourceDimensions", Integer.valueOf(2), method.getSourceDimensions());
assertEquals("targetDimensions", Integer.valueOf(2), method.getTargetDimensions());
}
use of org.opengis.referencing.operation.OperationMethod in project sis by apache.
the class SingleOperationMarshallingTest method testTransformationUnmarshalling.
/**
* Tests unmarshalling of a transformation.
*
* @throws JAXBException if an error occurred during marshalling or unmarshalling.
*/
@Test
@DependsOnMethod("testConversionUnmarshalling")
public void testTransformationUnmarshalling() throws JAXBException {
final DefaultTransformation c = unmarshalFile(DefaultTransformation.class, "Transformation.xml");
assertEquals("name", "NTF (Paris) to NTF (1)", c.getName().getCode());
assertEquals("identifier", "1763", getSingleton(c.getIdentifiers()).getCode());
assertEquals("scope", "Change of prime meridian.", String.valueOf(c.getScope()));
assertEquals("operationVersion", "IGN-Fra", c.getOperationVersion());
final OperationMethod method = c.getMethod();
assertNotNull("method", method);
assertEquals("method.name", "Longitude rotation", method.getName().getCode());
assertEquals("method.identifier", "9601", getSingleton(method.getIdentifiers()).getCode());
assertEquals("method.formula", "Target_longitude = Source_longitude + longitude_offset.", method.getFormula().getFormula().toString());
final ParameterDescriptor<?> descriptor = (ParameterDescriptor<?>) getSingleton(method.getParameters().descriptors());
assertEquals("descriptor.name", "Longitude offset", descriptor.getName().getCode());
assertEquals("descriptor.identifier", "8602", getSingleton(descriptor.getIdentifiers()).getCode());
assertEquals("descriptor.valueClass", Double.class, descriptor.getValueClass());
final ParameterValueGroup parameters = c.getParameterValues();
assertNotNull("parameters", parameters);
assertSame("parameters.descriptors", method.getParameters(), parameters.getDescriptor());
final ParameterValue<?> parameter = (ParameterValue<?>) getSingleton(parameters.values());
assertSame("parameters.descriptor", descriptor, parameter.getDescriptor());
assertEquals("parameters.unit", Units.GRAD, parameter.getUnit());
assertEquals("parameters.value", 2.5969213, parameter.getValue());
final CoordinateReferenceSystem sourceCRS = c.getSourceCRS();
assertInstanceOf("sourceCRS", GeodeticCRS.class, sourceCRS);
assertEquals("sourceCRS.name", "NTF (Paris)", sourceCRS.getName().getCode());
assertEquals("sourceCRS.scope", "Geodetic survey.", sourceCRS.getScope().toString());
assertEquals("sourceCRS.identifier", "4807", getSingleton(sourceCRS.getIdentifiers()).getCode());
final CoordinateReferenceSystem targetCRS = c.getTargetCRS();
assertInstanceOf("targetCRS", GeodeticCRS.class, targetCRS);
assertEquals("targetCRS.name", "NTF", targetCRS.getName().getCode());
assertEquals("targetCRS.scope", "Geodetic survey.", targetCRS.getScope().toString());
assertEquals("targetCRS.identifier", "4275", getSingleton(targetCRS.getIdentifiers()).getCode());
final MathTransform tr = c.getMathTransform();
assertInstanceOf("mathTransform", LinearTransform.class, tr);
assertMatrixEquals("mathTransform.matrix", new Matrix3(1, 0, 0, 0, 1, 2.33722917, 0, 0, 1), ((LinearTransform) tr).getMatrix(), STRICT);
Validators.validate(c);
}
use of org.opengis.referencing.operation.OperationMethod in project sis by apache.
the class DefaultMathTransformFactoryTest method testAllMapProjections.
/**
* Tests the creation of all registered map projections.
* Only the semi-axis lengths are specified. For the rest, we rely on default values.
*
* @throws FactoryException if the construction of a map projection failed.
*
* @since 0.7
*/
@Test
public void testAllMapProjections() throws FactoryException {
/*
* Gets all map projections and creates a projection using the WGS84 ellipsoid
* and default parameter values.
*/
final Map<String, ?> dummyName = Collections.singletonMap(DefaultProjectedCRS.NAME_KEY, "Test");
final MathTransformFactory mtFactory = DefaultFactories.forBuildin(MathTransformFactory.class);
final Collection<OperationMethod> methods = mtFactory.getAvailableMethods(Projection.class);
for (final OperationMethod method : methods) {
final String classification = method.getName().getCode();
ParameterValueGroup param = mtFactory.getDefaultParameters(classification);
param.parameter("semi_major").setValue(6377563.396);
param.parameter("semi_minor").setValue(6356256.909237285);
final MathTransform mt;
try {
mt = mtFactory.createParameterizedTransform(param);
} catch (InvalidGeodeticParameterException e) {
/*
* Some map projections have mandatory parameters which we ignore for now
* except for a few well-known projection that we know should not fail.
*/
if (classification.contains("Mercator")) {
throw e;
}
out.print(classification);
out.print(CharSequences.spaces(42 - classification.length()));
out.print(": ");
out.println(e.getLocalizedMessage());
continue;
}
/*
* Verifies that the map projection properties are the ones that we specified.
* Note that the Equirectangular projection has been optimized as an affine transform, which we skip.
*/
if (mt instanceof LinearTransform) {
continue;
}
assertInstanceOf(classification, Parameterized.class, mt);
param = ((Parameterized) mt).getParameterValues();
assertEquals(classification, param.getDescriptor().getName().getCode());
assertEquals(classification, 6377563.396, param.parameter("semi_major").doubleValue(), 1E-4);
assertEquals(classification, 6356256.909237285, param.parameter("semi_minor").doubleValue(), 1E-4);
/*
* Creates a ProjectedCRS from the map projection. This part is more an integration test than
* a DefaultMathTransformFactory test. Again, the intent is to verify that the properties are
* the one that we specified.
*/
final DefaultProjectedCRS crs = new DefaultProjectedCRS(dummyName, CommonCRS.WGS84.normalizedGeographic(), new DefaultConversion(dummyName, method, mt, null), HardCodedCS.PROJECTED);
final Conversion projection = crs.getConversionFromBase();
assertSame(classification, mt, projection.getMathTransform());
assertEquals(classification, projection.getMethod().getName().getCode());
}
}
use of org.opengis.referencing.operation.OperationMethod in project sis by apache.
the class DefaultMathTransformFactoryTest method testDuplicatedNames.
/**
* Asks for names which are known to be duplicated. One of the duplicated elements is deprecated.
* However Apache SIS uses the same implementation.
*
* @throws NoSuchIdentifierException if the operation was not found.
*/
@Test
public void testDuplicatedNames() throws NoSuchIdentifierException {
final DefaultMathTransformFactory factory = factory();
final OperationMethod current = factory.getOperationMethod("EPSG:1029");
final OperationMethod deprecated = factory.getOperationMethod("EPSG:9823");
assertSame(current, factory.getOperationMethod("Equidistant Cylindrical (Spherical)"));
assertSame("Should share the non-deprecated implementation.", current, deprecated);
}
use of org.opengis.referencing.operation.OperationMethod in project sis by apache.
the class ObliqueStereographicTest method createNormalizedProjection.
/**
* Creates a new instance of {@link ObliqueStereographic} for a sphere or an ellipsoid.
* The new instance is stored in the inherited {@link #transform} field.
*
* @param ellipse {@code false} for the spherical case, or {@code true} for the ellipsoidal case.
*/
private void createNormalizedProjection(final boolean ellipse) {
final OperationMethod op = new org.apache.sis.internal.referencing.provider.ObliqueStereographic();
final ParameterValueGroup p = op.getParameters().createValue();
/*
* Following parameters are not given explicitely by EPSG definitions since they are
* usually inferred from the datum. However in the particular case of this test, we
* need to provide them. The names used below are either OGC names or SIS extensions.
*/
if (!ellipse) {
p.parameter("semi_major").setValue(R);
p.parameter("semi_minor").setValue(R);
} else {
p.parameter("semi_major").setValue(a);
p.parameter("inverse_flattening").setValue(ivf);
}
/*
* Following parameters are reproduced verbatim from EPSG registry and EPSG guide.
*/
p.parameter("Latitude of natural origin").setValue(φ0, Units.RADIAN);
p.parameter("Longitude of natural origin").setValue(λ0, Units.RADIAN);
p.parameter("Scale factor at natural origin").setValue(k0);
p.parameter("False easting").setValue(FE, Units.METRE);
p.parameter("False northing").setValue(FN, Units.METRE);
transform = new ObliqueStereographic(op, (Parameters) p);
}
Aggregations