Search in sources :

Example 86 with ParameterValueGroup

use of org.opengis.parameter.ParameterValueGroup 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 87 with ParameterValueGroup

use of org.opengis.parameter.ParameterValueGroup 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 88 with ParameterValueGroup

use of org.opengis.parameter.ParameterValueGroup in project sis by apache.

the class SingleOperationMarshallingTest method testConversionUnmarshalling.

/**
 * Tests unmarshalling of a defining conversion.
 *
 * @throws JAXBException if an error occurred during marshalling or unmarshalling.
 */
@Test
@DependsOnMethod("testOperationMethod")
public void testConversionUnmarshalling() throws JAXBException {
    final DefaultConversion c = unmarshalFile(DefaultConversion.class, "Conversion.xml");
    assertEquals("name", "World Mercator", c.getName().getCode());
    assertEquals("identifier", "3395", getSingleton(c.getIdentifiers()).getCode());
    assertEquals("scope", "Very small scale mapping.", String.valueOf(c.getScope()));
    assertNull("operationVersion", c.getOperationVersion());
    final GeographicBoundingBox e = (GeographicBoundingBox) getSingleton(c.getDomainOfValidity().getGeographicElements());
    assertEquals("eastBoundLongitude", +180, e.getEastBoundLongitude(), STRICT);
    assertEquals("westBoundLongitude", -180, e.getWestBoundLongitude(), STRICT);
    assertEquals("northBoundLatitude", 84, e.getNorthBoundLatitude(), STRICT);
    assertEquals("southBoundLatitude", -80, e.getSouthBoundLatitude(), STRICT);
    // This is a defining conversion, so we do not expect CRS.
    assertNull("sourceCRS", c.getSourceCRS());
    assertNull("targetCRS", c.getTargetCRS());
    assertNull("interpolationCRS", c.getInterpolationCRS());
    assertNull("mathTransform", c.getMathTransform());
    // The most difficult part.
    final OperationMethod method = c.getMethod();
    assertNotNull("method", method);
    verifyMethod(method);
    final ParameterValueGroup parameters = c.getParameterValues();
    assertNotNull("parameters", parameters);
    final Iterator<GeneralParameterValue> it = parameters.values().iterator();
    verifyParameter(method, parameters, -0.0, (ParameterValue<?>) it.next());
    verifyParameter(method, parameters, -90.0, (ParameterValue<?>) it.next());
    assertFalse("Unexpected parameter.", it.hasNext());
    Validators.validate(c);
}
Also used : GeneralParameterValue(org.opengis.parameter.GeneralParameterValue) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) GeographicBoundingBox(org.opengis.metadata.extent.GeographicBoundingBox) OperationMethod(org.opengis.referencing.operation.OperationMethod) CC_OperationParameterGroupTest(org.apache.sis.internal.jaxb.referencing.CC_OperationParameterGroupTest) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 89 with ParameterValueGroup

use of org.opengis.parameter.ParameterValueGroup in project sis by apache.

the class CommonAuthorityFactoryTest method testAuto42005.

/**
 * Tests {@link CommonAuthorityFactory#createProjectedCRS(String)} with the {@code "AUTO:42005"} code.
 *
 * @throws FactoryException if an error occurred while creating a CRS.
 */
@Test
@DependsOnMethod("testAuto42001")
@Ignore("Pending implementation of Mollweide projection.")
public void testAuto42005() throws FactoryException {
    final ProjectedCRS crs = factory.createProjectedCRS("AUTO:42005,9001,10,45");
    final ParameterValueGroup p = crs.getConversionFromBase().getParameterValues();
    assertAxisDirectionsEqual("CS", crs.getCoordinateSystem(), AxisDirection.EAST, AxisDirection.NORTH);
    assertEquals(Constants.CENTRAL_MERIDIAN, 10, p.parameter(Constants.CENTRAL_MERIDIAN).doubleValue(), STRICT);
}
Also used : ProjectedCRS(org.opengis.referencing.crs.ProjectedCRS) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) Ignore(org.junit.Ignore) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 90 with ParameterValueGroup

use of org.opengis.parameter.ParameterValueGroup in project sis by apache.

the class CommonAuthorityFactoryTest method testAuto42002.

/**
 * Tests {@link CommonAuthorityFactory#createProjectedCRS(String)} with the {@code "AUTO:42002"} code.
 *
 * @throws FactoryException if an error occurred while creating a CRS.
 */
@Test
@DependsOnMethod("testAuto42001")
public void testAuto42002() throws FactoryException {
    final ProjectedCRS crs = factory.createProjectedCRS("AUTO:42002,-122,10");
    assertSame("Omitting namespace.", crs, factory.createProjectedCRS(" 42002, -122 , 10 "));
    assertSame("With explicit unit.", crs, factory.createProjectedCRS("AUTO2 :  42002, 1, -122 , 10 "));
    assertEquals("name", "Transverse Mercator", crs.getName().getCode());
    assertTrue("Expected no EPSG identifier.", crs.getIdentifiers().isEmpty());
    final ParameterValueGroup p = crs.getConversionFromBase().getParameterValues();
    assertEquals(TransverseMercator.NAME, crs.getConversionFromBase().getMethod().getName().getCode());
    assertAxisDirectionsEqual("CS", crs.getCoordinateSystem(), AxisDirection.EAST, AxisDirection.NORTH);
    assertEquals(Constants.CENTRAL_MERIDIAN, -122, p.parameter(Constants.CENTRAL_MERIDIAN).doubleValue(), STRICT);
    assertEquals(Constants.LATITUDE_OF_ORIGIN, 10, p.parameter(Constants.LATITUDE_OF_ORIGIN).doubleValue(), STRICT);
    assertEquals(Constants.FALSE_NORTHING, 0, p.parameter(Constants.FALSE_NORTHING).doubleValue(), STRICT);
}
Also used : ProjectedCRS(org.opengis.referencing.crs.ProjectedCRS) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Aggregations

ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)98 Test (org.junit.Test)54 DependsOnMethod (org.apache.sis.test.DependsOnMethod)27 GeneralParameterValue (org.opengis.parameter.GeneralParameterValue)12 ProjectedCRS (org.opengis.referencing.crs.ProjectedCRS)11 OperationMethod (org.opengis.referencing.operation.OperationMethod)11 ParameterValue (org.opengis.parameter.ParameterValue)8 GeneralParameterDescriptor (org.opengis.parameter.GeneralParameterDescriptor)7 ParameterNotFoundException (org.opengis.parameter.ParameterNotFoundException)7 SingleOperation (org.opengis.referencing.operation.SingleOperation)6 FactoryException (org.opengis.util.FactoryException)6 DefaultGeodeticDatum (org.apache.sis.referencing.datum.DefaultGeodeticDatum)5 IdentifiedObject (org.opengis.referencing.IdentifiedObject)5 Matrix (org.opengis.referencing.operation.Matrix)5 ArrayList (java.util.ArrayList)4 DefaultConversion (org.apache.sis.referencing.operation.DefaultConversion)4 ParameterDescriptorGroup (org.opengis.parameter.ParameterDescriptorGroup)4 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)4 CoordinateOperation (org.opengis.referencing.operation.CoordinateOperation)4 URL (java.net.URL)3