Search in sources :

Example 26 with ParameterValueGroup

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

the class Proj4ParserTest method testKilometres.

/**
 * Tests parsing a definition string with axes in kilometres.
 *
 * @throws FactoryException if the parsing failed.
 */
@Test
public void testKilometres() throws FactoryException {
    final Proj4Parser parser = new Proj4Parser("+proj=merc +to_meter=0.001");
    assertInstanceOf("method", Mercator1SP.class, parser.method(opFactory));
    final ParameterValueGroup pg = parser.parameters();
    assertEquals("scale_factor", pg.parameter("scale_factor").getValue(), 1.0);
    assertEquals(Units.KILOMETRE, parser.unit(false));
}
Also used : ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) Test(org.junit.Test)

Example 27 with ParameterValueGroup

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

the class CRSBuilder method verify.

/**
 * Verifies if the user-defined conversion created from GeoTIFF values
 * matches the given conversion created from the EPSG geodetic dataset.
 * This method does not verify the EPSG code of the given conversion.
 *
 * @param  projection  the conversion created from the EPSG geodetic dataset.
 */
private void verify(final Conversion projection, final Unit<Angle> angularUnit, final Unit<Length> linearUnit) throws FactoryException {
    final Unit<Angle> azimuthUnit = createUnit(GeoKeys.AzimuthUnits, (short) 0, Angle.class, Units.DEGREE);
    final String type = getAsString(GeoKeys.CoordTrans);
    if (type != null) {
        /*
             * Compare the name of the map projection declared in the GeoTIFF file with the name
             * of the projection used by the EPSG geodetic dataset.
             */
        final OperationMethod method = projection.getMethod();
        if (!IdentifiedObjects.isHeuristicMatchForName(method, type)) {
            Identifier expected = IdentifiedObjects.getIdentifier(method, Citations.GEOTIFF);
            if (expected == null) {
                expected = IdentifiedObjects.getIdentifier(method, null);
            }
            warning(Resources.Keys.NotTheEpsgValue_5, IdentifiedObjects.getIdentifierOrName(projection), expected.getCode(), GeoKeys.name(GeoKeys.CoordTrans), type, "");
        }
        /*
             * Compare the parameter values with the ones declared in the EPSG geodetic dataset.
             */
        final ParameterValueGroup parameters = projection.getParameterValues();
        for (final short key : remainingKeys()) {
            final Unit<?> unit;
            switch(GeoKeys.unitOf(key)) {
                case GeoKeys.RATIO:
                    unit = Units.UNITY;
                    break;
                case GeoKeys.LINEAR:
                    unit = linearUnit;
                    break;
                case GeoKeys.ANGULAR:
                    unit = angularUnit;
                    break;
                case GeoKeys.AZIMUTH:
                    unit = azimuthUnit;
                    break;
                default:
                    continue;
            }
            try {
                verify(projection, parameters.parameter("GeoTIFF:" + key).doubleValue(unit), key, unit);
            } catch (ParameterNotFoundException e) {
                warning(Resources.Keys.UnexpectedParameter_2, type, GeoKeys.name(key));
            }
        }
    }
}
Also used : Identifier(org.opengis.metadata.Identifier) Angle(javax.measure.quantity.Angle) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) ParameterNotFoundException(org.opengis.parameter.ParameterNotFoundException) OperationMethod(org.opengis.referencing.operation.OperationMethod)

Example 28 with ParameterValueGroup

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

the class CoordinateOperationFinderTest method testGeographic3D_to_2D.

/**
 * Tests the conversion from a three-dimensional geographic CRS to a two-dimensional geographic CRS.
 * The vertical dimension is simply dropped.
 *
 * @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 testGeographic3D_to_2D() throws FactoryException, TransformException {
    final GeographicCRS sourceCRS = CommonCRS.WGS84.geographic3D();
    final GeographicCRS targetCRS = CommonCRS.WGS84.geographic();
    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", "Geographic3D to 2D conversion", parameters.getDescriptor().getName().getCode());
    assertTrue("parameters.isEmpty", parameters.values().isEmpty());
    transform = operation.getMathTransform();
    assertInstanceOf("transform", LinearTransform.class, transform);
    assertEquals("sourceDimensions", 3, transform.getSourceDimensions());
    assertEquals("targetDimensions", 2, transform.getTargetDimensions());
    Assert.assertMatrixEquals("transform.matrix", Matrices.create(3, 4, new double[] { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 }), ((LinearTransform) transform).getMatrix(), STRICT);
    isInverseTransformSupported = false;
    verifyTransform(new double[] { 30, 10, 20, 20, 30, -10 }, new double[] { 30, 10, 20, 30 });
    validate();
}
Also used : ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) CoordinateOperation(org.opengis.referencing.operation.CoordinateOperation) GeographicCRS(org.opengis.referencing.crs.GeographicCRS) SingleOperation(org.opengis.referencing.operation.SingleOperation) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 29 with ParameterValueGroup

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

the class CoordinateOperationRegistryTest method verifyNTF.

/**
 * Verifies a coordinate operation which is expected to be <cite>"NTF (Paris) to WGS 84 (1)"</cite> (EPSG:8094).
 *
 * @param  domain  either {@code "geog2D domain"} or either {@code "geog3D domain"}.
 * @param  isEPSG  {@code true} if the coordinate operation is expected to contain EPSG identifiers.
 */
private static void verifyNTF(final CoordinateOperation operation, final String domain, final boolean isEPSG) {
    assertInstanceOf("Operation should have two steps.", ConcatenatedOperation.class, operation);
    final List<? extends CoordinateOperation> steps = ((ConcatenatedOperation) operation).getOperations();
    assertEquals("Operation should have two steps.", 2, steps.size());
    final SingleOperation step1 = (SingleOperation) steps.get(0);
    final SingleOperation step2 = (SingleOperation) steps.get(1);
    if (isEPSG) {
        assertEpsgNameAndIdentifierEqual("NTF (Paris) to WGS 84 (1)", 8094, operation);
        assertEpsgNameAndIdentifierEqual("NTF (Paris)", 4807, operation.getSourceCRS());
        assertEpsgNameAndIdentifierEqual("WGS 84", 4326, operation.getTargetCRS());
        assertEpsgNameAndIdentifierEqual("NTF (Paris) to NTF (1)", 1763, step1);
        assertEpsgNameAndIdentifierEqual("NTF to WGS 84 (1)", 1193, step2);
    } else {
        assertEpsgNameWithoutIdentifierEqual("NTF (Paris) to WGS 84 (1)", operation);
        assertEpsgNameWithoutIdentifierEqual("NTF (Paris)", operation.getSourceCRS());
        assertEquals("name", "WGS 84", operation.getTargetCRS().getName().getCode());
        assertEpsgNameWithoutIdentifierEqual("NTF (Paris) to NTF (1)", step1);
        assertEpsgNameWithoutIdentifierEqual("NTF to WGS 84 (1)", step2);
    }
    assertSame("SourceCRS shall be the targetCRS of previous step.", step1.getTargetCRS(), step2.getSourceCRS());
    assertEquals("Method 1", "Longitude rotation", step1.getMethod().getName().getCode());
    assertEquals("Method 2", "Geocentric translations (" + domain + ')', step2.getMethod().getName().getCode());
    final ParameterValueGroup p1 = step1.getParameterValues();
    final ParameterValueGroup p2 = step2.getParameterValues();
    assertEquals("Longitude offset", 2.5969213, p1.parameter("Longitude offset").doubleValue(), STRICT);
    assertEquals("X-axis translation", -168, p2.parameter("X-axis translation").doubleValue(), STRICT);
    assertEquals("Y-axis translation", -60, p2.parameter("Y-axis translation").doubleValue(), STRICT);
    assertEquals("Z-axis translation", 320, p2.parameter("Z-axis translation").doubleValue(), STRICT);
    assertEquals("linearAccuracy", 2, CRS.getLinearAccuracy(operation), STRICT);
}
Also used : ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) ConcatenatedOperation(org.opengis.referencing.operation.ConcatenatedOperation) SingleOperation(org.opengis.referencing.operation.SingleOperation)

Example 30 with ParameterValueGroup

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

the class CoordinateOperationRegistryTest method testFindDespiteDifferentAxisOrder.

/**
 * Tests <cite>"Martinique 1938 to RGAF09 (1)"</cite> operation with a target CRS fixed to EPSG:7086
 * instead of EPSG:5489. Both are <cite>"RGAF09"</cite>, but the former use (longitude, latitude) axis
 * order instead than the usual (latitude, longitude) order. The source CRS stay fixed to EPSG:4625.
 *
 * @throws FactoryException if an error occurred while creating a CRS or operation.
 */
@Test
public void testFindDespiteDifferentAxisOrder() throws FactoryException {
    CoordinateReferenceSystem sourceCRS = crsFactory.createGeographicCRS("EPSG:4625");
    CoordinateReferenceSystem targetCRS = crsFactory.createGeographicCRS("EPSG:5489");
    CoordinateOperation operation = createOperation(sourceCRS, targetCRS);
    assertEpsgNameAndIdentifierEqual("Martinique 1938 to RGAF09 (1)", 5491, operation);
    /*
         * Above was only a verification using the source and target CRS expected by EPSG dataset.
         * Now the interesting test: use a target CRS with different axis order.
         */
    targetCRS = crsFactory.createGeographicCRS("EPSG:7086");
    operation = createOperation(sourceCRS, targetCRS);
    assertEpsgNameWithoutIdentifierEqual("Martinique 1938 to RGAF09 (1)", operation);
    final ParameterValueGroup p = ((SingleOperation) operation).getParameterValues();
    /*
         * Values below are copied from EPSG geodetic dataset 9.1. They may need
         * to be adjusted if a future version of EPSG dataset modify those values.
         */
    assertEquals("X-axis translation", 127.744, p.parameter("X-axis translation").doubleValue(), STRICT);
    assertEquals("Y-axis translation", 547.069, p.parameter("Y-axis translation").doubleValue(), STRICT);
    assertEquals("Z-axis translation", 118.359, p.parameter("Z-axis translation").doubleValue(), STRICT);
    assertEquals("X-axis rotation", -3.1116, p.parameter("X-axis rotation").doubleValue(), STRICT);
    assertEquals("Y-axis rotation", 4.9509, p.parameter("Y-axis rotation").doubleValue(), STRICT);
    assertEquals("Z-axis rotation", -0.8837, p.parameter("Z-axis rotation").doubleValue(), STRICT);
    assertEquals("Scale difference", 14.1012, p.parameter("Scale difference").doubleValue(), STRICT);
    assertEquals("linearAccuracy", 0.1, CRS.getLinearAccuracy(operation), STRICT);
}
Also used : ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) CoordinateOperation(org.opengis.referencing.operation.CoordinateOperation) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) SingleOperation(org.opengis.referencing.operation.SingleOperation) Test(org.junit.Test)

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