Search in sources :

Example 21 with OperationMethod

use of org.opengis.referencing.operation.OperationMethod in project sis by apache.

the class DefaultConversionTest method createLongitudeRotation.

/**
 * Creates a very simple conversion performing a longitude rotation.
 * The source CRS shall use the Paris prime meridian and the target CRS the Greenwich prime meridian,
 * at least conceptually. See {@link #createLongitudeRotation(boolean)} for an explanation about why
 * this is not really a valid conversion.
 *
 * @param  sourceCRS         a CRS using the Paris prime meridian.
 * @param  targetCRS         a CRS using the Greenwich prime meridian.
 * @param  interpolationCRS  a dummy interpolation CRS, or {@code null} if none.
 */
private static DefaultConversion createLongitudeRotation(final GeographicCRS sourceCRS, final GeographicCRS targetCRS, final TemporalCRS interpolationCRS) {
    /*
         * The following code fills the parameter values AND creates itself the MathTransform instance
         * (indirectly, through the matrix). The later step is normally not our business, since we are
         * supposed to only fill the parameter values and let MathTransformFactory creates the transform
         * from the parameters. But we don't do the normal steps here because this class is a unit test:
         * we want to test DefaultConversion in isolation of MathTransformFactory.
         */
    final int interpDim = ReferencingUtilities.getDimension(interpolationCRS);
    final int sourceDim = sourceCRS.getCoordinateSystem().getDimension();
    final int targetDim = targetCRS.getCoordinateSystem().getDimension();
    final OperationMethod method = DefaultOperationMethodTest.create("Longitude rotation", "9601", "EPSG guidance note #7-2", sourceDim, DefaultParameterDescriptorTest.createEPSG("Longitude offset", (short) 8602));
    final ParameterValueGroup pg = method.getParameters().createValue();
    pg.parameter("Longitude offset").setValue(OFFSET);
    final Matrix rotation = Matrices.createDiagonal(// Number of rows.
    targetDim + interpDim + 1, // Number of columns.
    sourceDim + interpDim + 1);
    rotation.setElement(interpDim, interpDim + sourceDim, OFFSET);
    /*
         * In theory we should not need to provide the parameters explicitly to the constructor since
         * we are supposed to be able to find them from the MathTransform. But in this simple test we
         * did not bothered to define a specialized MathTransform class for our case. So we will help
         * a little bit DefaultConversion by telling it the parameters that we used.
         */
    final Map<String, Object> properties = new HashMap<>(4);
    properties.put(DefaultTransformation.NAME_KEY, "Paris to Greenwich");
    properties.put(ReferencingServices.PARAMETERS_KEY, pg);
    return new DefaultConversion(properties, sourceCRS, targetCRS, interpolationCRS, method, MathTransforms.linear(rotation));
}
Also used : Matrix(org.opengis.referencing.operation.Matrix) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) HashMap(java.util.HashMap) OperationMethod(org.opengis.referencing.operation.OperationMethod)

Example 22 with OperationMethod

use of org.opengis.referencing.operation.OperationMethod in project sis by apache.

the class DefaultOperationMethodTest method testRedimension.

/**
 * Tests {@link DefaultOperationMethod#redimension(OperationMethod, int, int)}.
 */
@Test
@DependsOnMethod({ "testConstruction", "testEquals" })
public void testRedimension() {
    final OperationMethod method = create("Affine geometric transformation", "9623", "EPSG guidance note #7-2", null);
    OperationMethod other = DefaultOperationMethod.redimension(method, 2, 2);
    assertSame(other, DefaultOperationMethod.redimension(other, 2, 2));
    assertNotSame(method, other);
    assertFalse(method.equals(other));
    assertEquals("sourceDimensions", Integer.valueOf(2), other.getSourceDimensions());
    assertEquals("targetDimensions", Integer.valueOf(2), other.getTargetDimensions());
    other = DefaultOperationMethod.redimension(method, 2, 3);
    assertSame(other, DefaultOperationMethod.redimension(other, 2, 3));
    assertNotSame(method, other);
    assertFalse(method.equals(other));
    assertEquals("sourceDimensions", Integer.valueOf(2), other.getSourceDimensions());
    assertEquals("targetDimensions", Integer.valueOf(3), other.getTargetDimensions());
    other = DefaultOperationMethod.redimension(method, 3, 2);
    assertSame(other, DefaultOperationMethod.redimension(other, 3, 2));
    assertNotSame(method, other);
    assertFalse(method.equals(other));
    assertEquals("sourceDimensions", Integer.valueOf(3), other.getSourceDimensions());
    assertEquals("targetDimensions", Integer.valueOf(2), other.getTargetDimensions());
    try {
        DefaultOperationMethod.redimension(other, 3, 3);
        fail("Should not have accepted to change non-null dimensions.");
    } catch (IllegalArgumentException e) {
        final String message = e.getLocalizedMessage();
        assertTrue(message, message.contains("Affine geometric transformation"));
    }
}
Also used : OperationMethod(org.opengis.referencing.operation.OperationMethod) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 23 with OperationMethod

use of org.opengis.referencing.operation.OperationMethod in project sis by apache.

the class DefaultOperationMethodTest method testWKT.

/**
 * Tests {@link DefaultOperationMethod#toWKT()}.
 * Since the WKT format of {@code OperationMethod} does not include parameters,
 * we do not bother specifying the parameters in the object created here.
 */
@Test
@DependsOnMethod("testConstruction")
public void testWKT() {
    final OperationMethod method = create("Mercator (variant A)", "9804", "EPSG guidance note #7-2", 2);
    assertWktEquals("METHOD[“Mercator (variant A)”, ID[“EPSG”, 9804, URI[“urn:ogc:def:method:EPSG::9804”]]]", method);
    assertWktEquals(Convention.WKT1, "PROJECTION[“Mercator (variant A)”, AUTHORITY[“EPSG”, “9804”]]", method);
}
Also used : OperationMethod(org.opengis.referencing.operation.OperationMethod) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 24 with OperationMethod

use of org.opengis.referencing.operation.OperationMethod in project sis by apache.

the class DefaultTransformationTest method createGeocentricTranslation.

/**
 * Creates a “Tokyo to JGD2000 (GSI)” transformation.
 */
static DefaultTransformation createGeocentricTranslation() {
    /*
         * The following code fills the parameter values AND creates itself the MathTransform instance
         * (indirectly, through the matrix). The later step is normally not our business, since we are
         * supposed to only fill the parameter values and let MathTransformFactory creates the transform
         * from the parameters. But we don't do the normal steps here because this class is a unit test:
         * we want to test DefaultTransformation in isolation of MathTransformFactory.
         */
    final Matrix4 translation = new Matrix4();
    final OperationMethod method = DefaultOperationMethodTest.create("Geocentric translations", "1031", "EPSG guidance note #7-2", 3, DefaultParameterDescriptorTest.createEPSG("X-axis translation", (short) 8605), DefaultParameterDescriptorTest.createEPSG("Y-axis translation", (short) 8606), DefaultParameterDescriptorTest.createEPSG("Z-axis translation", (short) 8607));
    final ParameterValueGroup pg = method.getParameters().createValue();
    pg.parameter("X-axis translation").setValue(translation.m02 = -146.414);
    pg.parameter("Y-axis translation").setValue(translation.m12 = 507.337);
    pg.parameter("Z-axis translation").setValue(translation.m22 = 680.507);
    /*
         * In theory we should not need to provide the parameters explicitly to the constructor since
         * we are supposed to be able to find them from the MathTransform. But in this simple test we
         * did not bothered to define a specialized MathTransform class for our case. So we will help
         * a little bit DefaultTransformation by telling it the parameters that we used.
         */
    final Map<String, Object> properties = new HashMap<>(4);
    properties.put(DefaultTransformation.NAME_KEY, "Tokyo to JGD2000 (GSI)");
    properties.put(ReferencingServices.PARAMETERS_KEY, pg);
    return new DefaultTransformation(properties, // SourceCRS
    createCRS(null, HardCodedDatum.TOKYO), // TargetCRS
    createCRS("JGD2000", HardCodedDatum.JGD2000), // InterpolationCRS
    null, method, MathTransforms.linear(translation));
}
Also used : ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) HashMap(java.util.HashMap) Matrix4(org.apache.sis.referencing.operation.matrix.Matrix4) OperationMethod(org.opengis.referencing.operation.OperationMethod)

Example 25 with OperationMethod

use of org.opengis.referencing.operation.OperationMethod in project sis by apache.

the class SingleOperationMarshallingTest method testOperationMethod.

/**
 * Tests (un)marshalling of an operation method.
 *
 * @throws JAXBException if an error occurred during marshalling or unmarshalling.
 */
@Test
public void testOperationMethod() throws JAXBException {
    final String xml = XML.marshal(createMercatorMethod());
    assertXmlEquals("<gml:OperationMethod xmlns:gml=\"" + Namespaces.GML + "\">\n" + "  <gml:name>Mercator (1SP)</gml:name>\n" + "  <gml:formula>See EPSG guide.</gml:formula>\n" + "  <gml:sourceDimensions>2</gml:sourceDimensions>\n" + "  <gml:targetDimensions>2</gml:targetDimensions>\n" + "  <gml:parameter>\n" + "    <gml:OperationParameter gml:id=\"epsg-parameter-8801\">\n" + "      <gml:identifier codeSpace=\"IOGP\">urn:ogc:def:parameter:EPSG::8801</gml:identifier>\n" + "      <gml:name codeSpace=\"EPSG\">Latitude of natural origin</gml:name>\n" + "    </gml:OperationParameter>\n" + "  </gml:parameter>\n" + "  <gml:parameter>\n" + "    <gml:OperationParameter gml:id=\"epsg-parameter-8802\">\n" + "      <gml:identifier codeSpace=\"IOGP\">urn:ogc:def:parameter:EPSG::8802</gml:identifier>\n" + "      <gml:name codeSpace=\"EPSG\">Longitude of natural origin</gml:name>\n" + "    </gml:OperationParameter>\n" + "  </gml:parameter>\n" + "</gml:OperationMethod>", xml, "xmlns:*");
    final OperationMethod method = (OperationMethod) XML.unmarshal(xml);
    verifyMethod(method);
    Validators.validate(method);
}
Also used : OperationMethod(org.opengis.referencing.operation.OperationMethod) CC_OperationParameterGroupTest(org.apache.sis.internal.jaxb.referencing.CC_OperationParameterGroupTest) Test(org.junit.Test)

Aggregations

OperationMethod (org.opengis.referencing.operation.OperationMethod)29 Test (org.junit.Test)17 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)11 DependsOnMethod (org.apache.sis.test.DependsOnMethod)8 DefaultOperationMethod (org.apache.sis.referencing.operation.DefaultOperationMethod)6 Identifier (org.opengis.metadata.Identifier)5 HashMap (java.util.HashMap)4 GeneralParameterDescriptor (org.opengis.parameter.GeneralParameterDescriptor)4 CC_OperationParameterGroupTest (org.apache.sis.internal.jaxb.referencing.CC_OperationParameterGroupTest)3 GeneralParameterValue (org.opengis.parameter.GeneralParameterValue)3 ParameterDescriptorGroup (org.opengis.parameter.ParameterDescriptorGroup)3 IdentifiedObject (org.opengis.referencing.IdentifiedObject)3 MathTransform (org.opengis.referencing.operation.MathTransform)3 MathTransformFactory (org.opengis.referencing.operation.MathTransformFactory)3 NoSuchIdentifierException (org.opengis.util.NoSuchIdentifierException)3 IdentityHashMap (java.util.IdentityHashMap)2 DefaultProjectedCRS (org.apache.sis.referencing.crs.DefaultProjectedCRS)2 InvalidGeodeticParameterException (org.apache.sis.referencing.factory.InvalidGeodeticParameterException)2 DefaultConversion (org.apache.sis.referencing.operation.DefaultConversion)2 ParameterDescriptor (org.opengis.parameter.ParameterDescriptor)2