org.opengis.parameter.ParameterValueGroup Java Examples

The following examples show how to use org.opengis.parameter.ParameterValueGroup. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StandardDefinitions.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a Universal Transverse Mercator (UTM) or a Universal Polar Stereographic (UPS) projected CRS
 * using the Apache SIS factory implementation. This method restricts the factory to SIS implementation
 * instead than arbitrary factory in order to met the contract saying that {@link CommonCRS} methods
 * should never fail.
 *
 * @param code       the EPSG code, or 0 if none.
 * @param baseCRS    the geographic CRS on which the projected CRS is based.
 * @param isUTM      {@code true} for UTM or {@code false} for UPS. Note: redundant with the given latitude.
 * @param latitude   a latitude in the zone of the desired projection, to be snapped to 0°, 90°S or 90°N.
 * @param longitude  a longitude in the zone of the desired projection, to be snapped to UTM central meridian.
 * @param derivedCS  the projected coordinate system.
 */
static ProjectedCRS createUniversal(final int code, final GeographicCRS baseCRS, final boolean isUTM,
        final double latitude, final double longitude, final CartesianCS derivedCS)
{
    final OperationMethod method;
    try {
        method = DefaultFactories.forBuildin(MathTransformFactory.class, DefaultMathTransformFactory.class)
                        .getOperationMethod(isUTM ? TransverseMercator.NAME : PolarStereographicA.NAME);
    } catch (NoSuchIdentifierException e) {
        throw new IllegalStateException(e);                     // Should not happen with SIS implementation.
    }
    final ParameterValueGroup parameters = method.getParameters().createValue();
    String name = isUTM ? TransverseMercator.Zoner.UTM.setParameters(parameters, latitude, longitude)
                        : PolarStereographicA.setParameters(parameters, latitude >= 0);
    final DefaultConversion conversion = new DefaultConversion(properties(0, name, null, false), method, null, parameters);

    name = baseCRS.getName().getCode() + " / " + name;
    return new DefaultProjectedCRS(properties(code, name, null, false), baseCRS, conversion, derivedCS);
}
 
Example #2
Source File: DefaultParameterValueGroup.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Compares the specified object with this parameter for equality.
 * The strictness level is controlled by the second argument:
 *
 * <ul>
 *   <li>{@link ComparisonMode#STRICT} and {@link ComparisonMode#BY_CONTRACT BY_CONTRACT}
 *       take in account the parameter order.</li>
 *   <li>{@link ComparisonMode#IGNORE_METADATA} and {@link ComparisonMode#APPROXIMATE APPROXIMATE}
 *       ignore the order of parameter values (but not necessarily the order of parameter descriptors).</li>
 * </ul>
 *
 * @param  object  the object to compare to {@code this}.
 * @param  mode  the strictness level of the comparison.
 * @return {@code true} if both objects are equal according the given comparison mode.
 */
@Override
public boolean equals(final Object object, final ComparisonMode mode) {
    if (object == this) {
        // Slight optimization
        return true;
    }
    if (object != null) {
        if (mode == ComparisonMode.STRICT) {
            if (getClass() == object.getClass()) {
                final DefaultParameterValueGroup that = (DefaultParameterValueGroup) object;
                return Objects.equals(values.descriptor, that.values.descriptor) &&
                       Objects.equals(values, that.values);
            }
        } else if (object instanceof ParameterValueGroup) {
            return equals(this, (ParameterValueGroup) object, mode);
        }
    }
    return false;
}
 
Example #3
Source File: MapProjectionParametersTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the {@code "inverse_flattening"} dynamic parameter.
 */
@Test
public void testInverseFlattening() {
    final MapProjectionDescriptor descriptor = createDescriptor(0);
    final ParameterValueGroup parameters = descriptor.createValue();

    parameters.parameter(SEMI_MAJOR).setValue(6378206.4);  // Clarke 1866
    parameters.parameter(SEMI_MINOR).setValue(6356583.8);
    assertEquals(294.97870, parameters.parameter(INVERSE_FLATTENING).doubleValue(), 0.00001);
    assertEquals(6378206.4, parameters.parameter(SEMI_MAJOR)        .doubleValue(), 0.5);
    assertEquals(6356583.8, parameters.parameter(SEMI_MINOR)        .doubleValue(), 0.5);
    assertFalse("isIvfDefinitive", parameters.parameter(IS_IVF_DEFINITIVE).booleanValue());

    parameters.parameter(SEMI_MAJOR).setValue(6378137.0);  // WGS84
    parameters.parameter(INVERSE_FLATTENING).setValue(298.257223563);
    assertEquals(298.257, parameters.parameter(INVERSE_FLATTENING).doubleValue(), 0.001);
    assertEquals(6378137, parameters.parameter(SEMI_MAJOR)        .doubleValue(), 0.5);
    assertEquals(6356752, parameters.parameter(SEMI_MINOR)        .doubleValue(), 0.5);
    assertTrue("isIvfDefinitive", parameters.parameter(IS_IVF_DEFINITIVE).booleanValue());

    parameters.parameter(SEMI_MAJOR).setValue(6378350.9);  // Clarke 1858 (approximated)
    parameters.parameter(SEMI_MINOR).setValue(6356675.0);
    assertEquals(294.26, parameters.parameter(INVERSE_FLATTENING).doubleValue(), 0.001);
    assertFalse("isIvfDefinitive", parameters.parameter(IS_IVF_DEFINITIVE).booleanValue());
}
 
Example #4
Source File: WKTUtilities.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Converts the given object in a {@code FormattableObject} instance. Callers should verify that the
 * given object is not already an instance of {@code FormattableObject} before to invoke this method.
 * This method returns {@code null} if it can not convert the object.
 *
 * @param  object    the object to wrap.
 * @param  internal  {@code true} if the formatting convention is {@code Convention.INTERNAL}.
 * @return the given object converted to a {@code FormattableObject} instance, or {@code null}.
 */
public static FormattableObject toFormattable(final MathTransform object, boolean internal) {
    Matrix matrix;
    final ParameterValueGroup parameters;
    if (internal && (matrix = MathTransforms.getMatrix(object)) != null) {
        parameters = Affine.parameters(matrix);
    } else if (object instanceof Parameterized) {
        parameters = ((Parameterized) object).getParameterValues();
    } else {
        matrix = MathTransforms.getMatrix(object);
        if (matrix == null) {
            return null;
        }
        parameters = Affine.parameters(matrix);
    }
    return new FormattableObject() {
        @Override protected String formatTo(final Formatter formatter) {
            WKTUtilities.appendParamMT(parameters, formatter);
            return WKTKeywords.Param_MT;
        }
    };
}
 
Example #5
Source File: TransverseMercator.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the parameter values for a Transverse Mercator projection and returns a suggested conversion name.
 *
 * <blockquote><table class="sis">
 *   <caption>Transverse Mercator parameters</caption>
 *   <tr><th>Parameter name</th>                 <th>Value</th></tr>
 *   <tr><td>Latitude of natural origin</td>     <td>Given latitude, or 0° if zoned projection</td></tr>
 *   <tr><td>Longitude of natural origin</td>    <td>Given longitude, optionally snapped to a zone central meridian</td></tr>
 *   <tr><td>Scale factor at natural origin</td> <td>0.9996 for UTM or 0.9999 for MTM</td></tr>
 *   <tr><td>False easting</td>                  <td>500000 metres for UTM or 304800 metres for MTM</td></tr>
 *   <tr><td>False northing</td>                 <td>0 (North hemisphere) or 10000000 (South hemisphere) metres</td></tr>
 * </table></blockquote>
 *
 * @param  group      the parameters for which to set the values.
 * @param  latitude   the latitude in the center of the desired projection.
 * @param  longitude  the longitude in the center of the desired projection.
 * @return a name like <cite>"Transverse Mercator"</cite> or <cite>"UTM zone 10N"</cite>,
 *         depending on the arguments given to this method.
 */
public final String setParameters(final ParameterValueGroup group, double latitude, double longitude) {
    final boolean isSouth = MathFunctions.isNegative(latitude);
    int zone = zone(latitude, longitude);
    String name;
    if (this == ANY) {
        name = "UTM";
        if (latitude != 0 || longitude != centralMeridian(zone)) {
            name = NAME;
            zone = 0;
        }
    } else {
        name      = name();
        latitude  = 0;
        longitude = centralMeridian(zone);
    }
    if (zone != 0) {
        name = name + " zone " + zone + (isSouth ? 'S' : 'N');
    }
    group.parameter(Constants.LATITUDE_OF_ORIGIN).setValue(latitude,  Units.DEGREE);
    group.parameter(Constants.CENTRAL_MERIDIAN)  .setValue(longitude, Units.DEGREE);
    group.parameter(Constants.SCALE_FACTOR)      .setValue(scale,     Units.UNITY);
    group.parameter(Constants.FALSE_EASTING)     .setValue(easting,   Units.METRE);
    group.parameter(Constants.FALSE_NORTHING)    .setValue(isSouth ? northing : 0, Units.METRE);
    return name;
}
 
Example #6
Source File: LongitudeRotationTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests {@code LongitudeRotation.createMathTransform(…)}.
 */
@Test
public void testCreateMathTransform() {
    final LongitudeRotation provider = new LongitudeRotation();
    ParameterValueGroup p = provider.getParameters().createValue();
    p.parameter("Longitude offset").setValue(2.5969213, Units.GRAD);   // Paris meridian
    final MathTransform mt = provider.createMathTransform(null, p);
    /*
     * Verify the full matrix. Note that the longitude offset is expected to be in degrees.
     * This conversion from grad to degrees is specific to Apache SIS and may be revised in
     * future version. See org.apache.sis.referencing.operation package javadoc.
     */
    assertInstanceOf("Shall be an affine transform.", LinearTransform.class, mt);
    assertMatrixEquals("Expected a longitude rotation",
            new Matrix3(1, 0, 2.33722917,
                        0, 1, 0,
                        0, 0, 1), ((LinearTransform) mt).getMatrix(), 1E-16);
}
 
Example #7
Source File: ZonedGridSystemTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests converting a point using the <cite>Transverse Mercator Zoned Grid System</cite> projection.
 *
 * @throws FactoryException if an error occurred while creating the map projection.
 * @throws TransformException if an error occurred while transforming a coordinate.
 */
@Test
public void testUTM() throws FactoryException, TransformException {
    createProjection(true);
    /*
     * Verify parameters.
     */
    final ParameterValueGroup values = ((Parameterized) transform).getParameterValues();
    assertEquals(0.9996, values.parameter(Constants.SCALE_FACTOR) .doubleValue(Units.UNITY ), 0);
    assertEquals(500000, values.parameter(Constants.FALSE_EASTING).doubleValue(Units.METRE ), 0);
    assertEquals(  -180, values.parameter("Initial longitude")    .doubleValue(Units.DEGREE), 0);
    assertEquals(     6, values.parameter("Zone width")           .doubleValue(Units.DEGREE), 0);
    /*
     * Tests projection of CN Tower coordinate, which is in UTM zone 17.
     */
    verifyTransform(new double[] {
        -79 - (23 - 13.70/60)/60,   // 79°23′13.70″W
         43 + (38 + 33.24/60)/60    // 43°38′33.24″N
    }, new double[] {
        17630698.19, 4833450.51
    });
}
 
Example #8
Source File: UnmodifiableParameterValueGroup.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Compares the specified object with this parameter for equality.
 * The strictness level is controlled by the second argument:
 *
 * <ul>
 *   <li>{@link ComparisonMode#STRICT} and {@link ComparisonMode#BY_CONTRACT BY_CONTRACT}
 *       take in account the parameter order.</li>
 *   <li>{@link ComparisonMode#IGNORE_METADATA} and {@link ComparisonMode#APPROXIMATE APPROXIMATE}
 *       ignore the order of parameter values (but not necessarily the order of parameter descriptors).</li>
 * </ul>
 *
 * @param  object  the object to compare to {@code this}.
 * @param  mode    the strictness level of the comparison.
 * @return {@code true} if both objects are equal according the given comparison mode.
 */
@Override
public boolean equals(final Object object, final ComparisonMode mode) {
    if (object == this) {
        return true;                            // Slight optimization
    }
    if (object != null) {
        if (mode == ComparisonMode.STRICT) {
            if (getClass() == object.getClass()) {
                final UnmodifiableParameterValueGroup that = (UnmodifiableParameterValueGroup) object;
                return Objects.equals(descriptor, that.descriptor) &&
                       Objects.equals(values,     that.values);
            }
        } else if (object instanceof ParameterValueGroup) {
            return DefaultParameterValueGroup.equals(this, (ParameterValueGroup) object, mode);
        }
    }
    return false;
}
 
Example #9
Source File: MapProjectionParametersTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests the {@code "earth_radius"} dynamic parameter.
 */
@Test
public void testEarthRadius() {
    final MapProjectionDescriptor descriptor = createDescriptor(0);
    final ParameterValueGroup parameters = descriptor.createValue();

    parameters.parameter(SEMI_MAJOR).setValue(6378137.000); // WGS84
    parameters.parameter(SEMI_MINOR).setValue(6356752.314);
    assertEquals(6371007, parameters.parameter(EARTH_RADIUS).doubleValue(), 0.5); // Authalic radius.
    assertEquals(6378137, parameters.parameter(SEMI_MAJOR)  .doubleValue(), 0.5);
    assertEquals(6356752, parameters.parameter(SEMI_MINOR)  .doubleValue(), 0.5);

    parameters.parameter(EARTH_RADIUS).setValue(6371000);
    assertEquals(6371000, parameters.parameter(EARTH_RADIUS).doubleValue(), 0.0);
    assertEquals(6371000, parameters.parameter(SEMI_MAJOR)  .doubleValue(), 0.0);
    assertEquals(6371000, parameters.parameter(SEMI_MINOR)  .doubleValue(), 0.0);
}
 
Example #10
Source File: TensorValuesTest.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Tests {@link TensorParameters#WKT1} formatting.
 * <ul>
 *   <li>Group name shall be {@code "Affine"}.</li>
 *   <li>Parameters {@code "num_row"} and {@code "num_col"} are mandatory.</li>
 *   <li>Parameter names shall be of the form {@code "elt_0_0"}.</li>
 *   <li>No identifier.</li>
 * </ul>
 */
@Test
public void testWKT1() {
    final Matrix matrix = Matrices.createIdentity(3);
    matrix.setElement(0,2,  4);
    matrix.setElement(1,0, -2);
    matrix.setElement(2,2,  7);
    final ParameterValueGroup group = TensorParameters.WKT1.createValueGroup(
            singletonMap(TensorValues.NAME_KEY, Constants.AFFINE), matrix);
    validate(group);
    assertWktEquals(
            "PARAMETERGROUP[“Affine”,\n"      +
            "  PARAMETER[“num_row”, 3],\n"    +   // Shall be shown even if equals to the default value.
            "  PARAMETER[“num_col”, 3],\n"    +
            "  PARAMETER[“elt_0_2”, 4.0],\n"  +
            "  PARAMETER[“elt_1_0”, -2.0],\n" +
            "  PARAMETER[“elt_2_2”, 7.0]]", group);
}
 
Example #11
Source File: WKTUtilities.java    From sis with Apache License 2.0 6 votes vote down vote up
/**
 * Appends a {@linkplain ParameterValue parameter} in a {@code PARAMETER[…]} element.
 * If the supplied parameter is actually a {@linkplain ParameterValueGroup parameter group},
 * all contained parameters will be flattened in a single list.
 *
 * @param  parameter  the parameter to append to the WKT, or {@code null} if none.
 * @param  formatter  the formatter where to append the parameter.
 */
public static void append(GeneralParameterValue parameter, final Formatter formatter) {
    if (parameter instanceof ParameterValueGroup) {
        boolean first = true;
        for (final GeneralParameterValue param : ((ParameterValueGroup) parameter).values()) {
            if (first) {
                formatter.newLine();
                first = false;
            }
            append(param, formatter);
        }
    }
    if (parameter instanceof ParameterValue<?>) {
        if (!(parameter instanceof FormattableObject)) {
            parameter = new DefaultParameterValue<>((ParameterValue<?>) parameter);
        }
        formatter.append((FormattableObject) parameter);
        formatter.newLine();
    }
}
 
Example #12
Source File: NoOp.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Work around for RFE #4093999 in Sun's bug database
 * ("Relax constraint on placement of this()/super() call in constructors").
 */
@Workaround(library="JDK", version="1.7")
private static Parameters parameters(final double semiMajor, final double semiMinor) {
    final ParameterValueGroup group = new ParameterBuilder()
            .addName("No-operation").createGroupForMapProjection().createValue();
    group.parameter(Constants.SEMI_MAJOR).setValue(semiMajor);
    group.parameter(Constants.SEMI_MINOR).setValue(semiMinor);
    return (Parameters) group;
}
 
Example #13
Source File: AxisOrderReversal.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the transform.
 *
 * @param  factory  ignored (can be null).
 * @param  values   ignored.
 * @return the math transform.
 */
@Override
public synchronized MathTransform createMathTransform(MathTransformFactory factory, ParameterValueGroup values) {
    if (transform == null) {
        final MatrixSIS m = Matrices.createZero(getTargetDimensions() + 1, getSourceDimensions() + 1);
        m.setElement(0, 1, 1);
        m.setElement(1, 0, 1);
        transform = MathTransforms.linear(m);
    }
    return transform;
}
 
Example #14
Source File: EPSGFactoryTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies the parameter values of the given Universal Transverse Mercator projection.
 *
 * @param  parameters  the parameter value to verify.
 * @param  cm  the expected central meridian value.
 */
private static void verifyTransverseMercatorParmeters(final ParameterValueGroup parameters, final double cm) {
    assertEquals("Transverse Mercator",       parameters.getDescriptor().getName().getCode());
    assertEquals("central_meridian",      cm, parameters.parameter("central_meridian"  ).doubleValue(), STRICT);
    assertEquals("latitude_of_origin",     0, parameters.parameter("latitude_of_origin").doubleValue(), STRICT);
    assertEquals("scale_factor",      0.9996, parameters.parameter("scale_factor"      ).doubleValue(), STRICT);
    assertEquals("false_easting",     500000, parameters.parameter("false_easting"     ).doubleValue(), STRICT);
    assertEquals("false_northing",         0, parameters.parameter("false_northing"    ).doubleValue(), STRICT);
}
 
Example #15
Source File: MapProjectionParametersTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the standard parallel dynamic parameter.
 */
@Test
public void testStandardParallel() {
    final MapProjectionDescriptor descriptor = createDescriptor(2);
    final ParameterValueGroup parameters = descriptor.createValue();
    final ParameterValue<?> p  = parameters.parameter(STANDARD_PARALLEL);
    final ParameterValue<?> p1 = parameters.parameter(STANDARD_PARALLEL_1);
    final ParameterValue<?> p2 = parameters.parameter(STANDARD_PARALLEL_2);
    assertSame(p,  parameters.parameter(STANDARD_PARALLEL));
    assertSame(p1, parameters.parameter(STANDARD_PARALLEL_1));
    assertSame(p2, parameters.parameter(STANDARD_PARALLEL_2));
    assertNotSame(p1, p2);
    assertNotSame(p1, p);
    assertNotSame(p2, p);

    /* Empty */      assertArrayEquals(new double[] {     }, p.doubleValueList(), 0.0);
    p1.setValue(40); assertArrayEquals(new double[] {40   }, p.doubleValueList(), 0.0);
    p2.setValue(60); assertArrayEquals(new double[] {40,60}, p.doubleValueList(), 0.0);

    p.setValue(new double[] {30,40});
    assertEquals(30, p1.doubleValue(), 0.0);
    assertEquals(40, p2.doubleValue(), 0.0);

    p.setValue(new double[] {45});
    assertEquals(45,         p1.doubleValue(), 0.0);
    assertEquals(Double.NaN, p2.doubleValue(), 0.0);
}
 
Example #16
Source File: SatelliteTrackingTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance of {@link SatelliteTracking} concatenated with the (de)normalization matrices.
 * The new instance is stored in the inherited {@link #transform} field.
 * This methods uses projection parameters for Landsat 3 satellite, namely:
 *
 * <table class="sis">
 *   <caption>Hard-coded projection parameters</caption>
 *   <tr><th>Symbol</th> <th>Value</th>       <th>Meaning</th></tr>
 *   <tr><td>i</td>  <td>99.092°</td>         <td>Angle of inclination between the plane of the Earth's Equator and the plane of the satellite orbit.</td></tr>
 *   <tr><td>P1</td> <td>1440 minutes</td>    <td>Length of Earth's rotation with respect to the precessed ascending node.</td></tr>
 *   <tr><td>P2</td> <td>103.267 minutes</td> <td>Time required for revolution of the satellite.</td></tr>
 * </table>
 *
 * The Earth radius is set to 1.
 *
 * @param λ0  central meridian.
 * @param φ0  latitude crossing the central meridian at the desired origin of rectangular coordinates.
 * @param φ1  first parallel of conformality (with true scale).
 * @param φ2  second parallel of conformality (without true scale), or -φ1 for a cylindrical projection.
 */
private void createForLandsat(final double λ0, final double φ0, final double φ1, final double φ2)
        throws FactoryException
{
    final SatelliteTracking provider = new SatelliteTracking();
    final ParameterValueGroup values = provider.getParameters().createValue();
    final DefaultEllipsoid    sphere = DefaultEllipsoid.createEllipsoid(
            Collections.singletonMap(DefaultEllipsoid.NAME_KEY, NilReferencingObject.UNNAMED), 1, 1, Units.METRE);

    values.parameter("semi_major")                 .setValue(sphere.getSemiMajorAxis());
    values.parameter("semi_minor")                 .setValue(sphere.getSemiMinorAxis());
    values.parameter("central_meridian")           .setValue(λ0);
    values.parameter("latitude_of_origin")         .setValue(φ0);
    values.parameter("standard_parallel_1")        .setValue(φ1);
    values.parameter("standard_parallel_2")        .setValue(φ2);
    values.parameter("satellite_orbit_inclination").setValue(  99.092);
    values.parameter("satellite_orbital_period")   .setValue( 103.267, Units.MINUTE);
    values.parameter("ascending_node_period")      .setValue(1440.0,   Units.MINUTE);
    transform = new MathTransformFactoryMock(provider).createParameterizedTransform(values);
    validate();
    /*
     * Assuming that tolerance has been set to the number of fraction digits published in Snyder tables,
     * relax the tolerance during inverse transforms for taking in account the increase in magnitude of
     * coordinate values. The transform results are between 0 and 1, while the inverse transform results
     * are between -90° and 90°, which is an increase in magnitude close to ×100.
     */
    tolerance *= 50;    // Finer tolerance setting require GeoAPI 3.1.
}
 
Example #17
Source File: DefaultMathTransformFactory.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a math transform that represent a change of coordinate system. If exactly one argument is
 * an {@linkplain org.apache.sis.referencing.cs.DefaultEllipsoidalCS ellipsoidal coordinate systems},
 * then the {@code ellipsoid} argument is mandatory. In all other cases (including the case where both
 * coordinate systems are ellipsoidal), the ellipsoid argument is ignored and can be {@code null}.
 *
 * <div class="note"><b>Design note:</b>
 * this method does not accept separated ellipsoid arguments for {@code source} and {@code target} because
 * this method should not be used for datum shifts. If the two given coordinate systems are ellipsoidal,
 * then they are assumed to use the same ellipsoid. If different ellipsoids are desired, then a
 * {@linkplain #createParameterizedTransform parameterized transform} like <cite>"Molodensky"</cite>,
 * <cite>"Geocentric translations"</cite>, <cite>"Coordinate Frame Rotation"</cite> or
 * <cite>"Position Vector transformation"</cite> should be used instead.</div>
 *
 * @param  source     the source coordinate system.
 * @param  target     the target coordinate system.
 * @param  ellipsoid  the ellipsoid of {@code EllipsoidalCS}, or {@code null} if none.
 * @return a conversion from the given source to the given target coordinate system.
 * @throws FactoryException if the conversion can not be created.
 *
 * @since 0.8
 */
public MathTransform createCoordinateSystemChange(final CoordinateSystem source, final CoordinateSystem target,
        final Ellipsoid ellipsoid) throws FactoryException
{
    ArgumentChecks.ensureNonNull("source", source);
    ArgumentChecks.ensureNonNull("target", target);
    if (ellipsoid != null) {
        final boolean isEllipsoidalSource = (source instanceof EllipsoidalCS);
        if (isEllipsoidalSource != (target instanceof EllipsoidalCS)) {
            /*
             * For now we support only conversion between EllipsoidalCS and CartesianCS.
             * But future Apache SIS versions could add support for conversions between
             * EllipsoidalCS and SphericalCS or other coordinate systems.
             */
            if ((isEllipsoidalSource ? target : source) instanceof CartesianCS) {
                final Context context = new Context();
                final EllipsoidalCS cs;
                final String operation;
                if (isEllipsoidalSource) {
                    operation = GeographicToGeocentric.NAME;
                    context.setSource(cs = (EllipsoidalCS) source, ellipsoid);
                    context.setTarget(target);
                } else {
                    operation = GeocentricToGeographic.NAME;
                    context.setSource(source);
                    context.setTarget(cs = (EllipsoidalCS) target, ellipsoid);
                }
                final ParameterValueGroup pg = getDefaultParameters(operation);
                if (cs.getDimension() < 3) pg.parameter("dim").setValue(2);       // Apache SIS specific parameter.
                return createParameterizedTransform(pg, context);
            }
        }
    }
    return CoordinateSystemTransform.create(this, source, target);
    // No need to use unique(…) here.
}
 
Example #18
Source File: MTFactory.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Unsupported by the {@literal Proj.4} wrapper.
 */
@Override
public MathTransform createBaseToDerived(CoordinateReferenceSystem baseCRS, ParameterValueGroup parameters, CoordinateSystem derivedCS)
        throws NoSuchIdentifierException, FactoryException
{
    throw new UnsupportedOperationException();
}
 
Example #19
Source File: GeographicOffsetsTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the {@code createMathTransform(…)} method of the given provider.
 * This test uses the two-dimensional sample point given in §2.4.4.3 of EPSG guide (April 2015),
 * leaving the height (if any) to zero.
 */
private void testCreateMathTransform(final GeographicOffsets provider) throws FactoryException, TransformException {
    final ParameterValueGroup pv = provider.getParameters().createValue();
    pv.parameter("Latitude offset" ).setValue(-5.86 / 3600);
    pv.parameter("Longitude offset").setValue(+0.28 / 3600);
    transform = provider.createMathTransform(null, pv);
    tolerance = Formulas.ANGULAR_TOLERANCE;
    final double[] source = new double[transform.getSourceDimensions()];
    final double[] target = new double[transform.getTargetDimensions()];
    source[1] = 38 + ( 8 + 36.565 /60) /60;     // 38°08′36.565″N
    target[1] = 38 + ( 8 + 30.705 /60) /60;     // 38°08′30.705″N
    source[0] = 23 + (48 + 16.235 /60) /60;     // 23°48′16.235″E
    target[0] = 23 + (48 + 16.515 /60) /60;     // 23°48′16.515″E
    verifyTransform(source, target);
}
 
Example #20
Source File: Proj4FactoryTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link Proj4Factory#createParameterizedTransform(ParameterValueGroup)}.
 *
 * @throws FactoryException if an error occurred while creating the CRS objects.
 * @throws TransformException if an error occurred while projecting a test point.
 */
@Test
public void testParameterizedTransform() throws FactoryException, TransformException {
    final Proj4Factory factory   = Proj4Factory.INSTANCE;
    final ParameterValueGroup pg = factory.getDefaultParameters("merc");
    pg.parameter("a").setValue(6378137.0);
    pg.parameter("b").setValue(6356752.314245179);
    testMercatorProjection(factory.createParameterizedTransform(pg));
}
 
Example #21
Source File: CommonAuthorityFactoryTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #22
Source File: PolarStereographicA.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * If the given parameter values are those of a Universal Polar Stereographic projection,
 * returns -1 for South pole or +1 for North pole. Otherwise returns 0. It is caller's
 * responsibility to verify that the operation method is {@value #NAME}.
 *
 * @param  group  the Transverse Mercator projection parameters.
 * @return +1 if UPS north, -1 if UPS south, or 0 if the given parameters are not for a UPS projection.
 *
 * @since 0.8
 */
public static int isUPS(final ParameterValueGroup group) {
    if (Numerics.epsilonEqual(group.parameter(Constants.SCALE_FACTOR)    .doubleValue(Units.UNITY),     0.994, Numerics.COMPARISON_THRESHOLD) &&
        Numerics.epsilonEqual(group.parameter(Constants.FALSE_EASTING)   .doubleValue(Units.METRE), UPS_SHIFT, Formulas.LINEAR_TOLERANCE) &&
        Numerics.epsilonEqual(group.parameter(Constants.FALSE_NORTHING)  .doubleValue(Units.METRE), UPS_SHIFT, Formulas.LINEAR_TOLERANCE) &&
        Numerics.epsilonEqual(group.parameter(Constants.CENTRAL_MERIDIAN).doubleValue(Units.DEGREE),        0, Formulas.ANGULAR_TOLERANCE))
    {
        final double φ = group.parameter(Constants.LATITUDE_OF_ORIGIN).doubleValue(Units.DEGREE);
        if (Numerics.epsilonEqual(φ, Latitude.MAX_VALUE, Formulas.ANGULAR_TOLERANCE)) return +1;
        if (Numerics.epsilonEqual(φ, Latitude.MIN_VALUE, Formulas.ANGULAR_TOLERANCE)) return -1;
    }
    return 0;
}
 
Example #23
Source File: GeocentricToGeographic.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a transform from the specified group of parameter values.
 *
 * @param  factory  the factory to use for creating the transform.
 * @param  values   the parameter values that define the transform to create.
 * @return the conversion from geocentric to geographic coordinates.
 * @throws FactoryException if an error occurred while creating a transform.
 */
@Override
public MathTransform createMathTransform(final MathTransformFactory factory, final ParameterValueGroup values)
        throws FactoryException
{
    MathTransform tr = GeographicToGeocentric.create(factory, Parameters.castOrWrap(values));
    try {
        tr = tr.inverse();
    } catch (NoninvertibleTransformException e) {
        throw new FactoryException(e);                  // Should never happen with SIS implementation.
    }
    return tr;
}
 
Example #24
Source File: UnmodifiableParameterValueGroup.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new unmodifiable parameter group.
 *
 * @param  group  the group of values to copy, or {@code null}.
 * @return the unmodifiable parameter group, or {@code null} if the given argument was null.
 */
static UnmodifiableParameterValueGroup create(final ParameterValueGroup group) {
    if (group == null || group instanceof UnmodifiableParameterValueGroup) {
        return (UnmodifiableParameterValueGroup) group;
    }
    return new UnmodifiableParameterValueGroup(group, new IdentityHashMap<>(4));
}
 
Example #25
Source File: FolderStoreProvider.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a data store implementation associated with this provider for the given parameters.
 *
 * @return a folder data store implementation for the given parameters.
 * @throws DataStoreException if an error occurred while creating the data store instance.
 */
@Override
public DataStore open(final ParameterValueGroup parameters) throws DataStoreException {
    ArgumentChecks.ensureNonNull("parameter", parameters);
    final StorageConnector connector = URIDataStore.Provider.connector(this, parameters);
    final Parameters pg = Parameters.castOrWrap(parameters);
    connector.setOption(OptionKey.LOCALE,   pg.getValue(LOCALE));
    connector.setOption(OptionKey.TIMEZONE, pg.getValue(TIMEZONE));
    connector.setOption(OptionKey.ENCODING, pg.getValue(ENCODING));
    final EnumSet<StandardOpenOption> options = EnumSet.of(StandardOpenOption.WRITE);
    if (Boolean.TRUE.equals(pg.getValue(URIDataStore.Provider.CREATE_PARAM))) {
        options.add(StandardOpenOption.CREATE);
    }
    return open(connector, pg.getValue(FORMAT), options);
}
 
Example #26
Source File: GeocentricTranslationTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a transformation for the given method.
 *
 * @param method  the method to test.
 */
private void create(final GeocentricAffine method) throws FactoryException {
    final ParameterValueGroup values = method.getParameters().createValue();
    setTranslation(values);
    if (method instanceof GeocentricAffineBetweenGeographic) {
        setEllipsoids(values, CommonCRS.WGS84.ellipsoid(), CommonCRS.ED50.ellipsoid());
    }
    transform = method.createMathTransform(DefaultFactories.forBuildin(MathTransformFactory.class), values);
}
 
Example #27
Source File: StoreProvider.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a CSV {@link Store} implementation from the given parameters.
 *
 * @return a data store implementation associated with this provider for the given parameters.
 * @throws DataStoreException if an error occurred while creating the data store instance.
 */
@Override
public DataStore open(final ParameterValueGroup parameters) throws DataStoreException {
    ArgumentChecks.ensureNonNull("parameter", parameters);
    final StorageConnector connector = connector(this, parameters);
    final Parameters pg = Parameters.castOrWrap(parameters);
    connector.setOption(DataOptionKey.ENCODING, pg.getValue(ENCODING));
    connector.setOption(DataOptionKey.FOLIATION_REPRESENTATION, pg.getValue(FOLIATION));
    return new Store(this, connector);
}
 
Example #28
Source File: DefaultTransformationTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Asserts that at least some of the properties of the given {@code op} instance have the expected values
 * for an instance created by {@link #createGeocentricTranslation()}.
 */
@SuppressWarnings("SuspiciousToArrayCall")
private static void verifyProperties(final DefaultTransformation op) {
    assertEquals("name",       "Tokyo to JGD2000 (GSI)",  op.getName().getCode());
    assertEquals("sourceCRS",  "Tokyo 1918",              op.getSourceCRS().getName().getCode());
    assertEquals("targetCRS",  "JGD2000",                 op.getTargetCRS().getName().getCode());
    assertEquals("method",     "Geocentric translations", op.getMethod().getName().getCode());
    assertEquals("parameters", "Geocentric translations", op.getParameterDescriptors().getName().getCode());

    final ParameterValueGroup parameters = op.getParameterValues();
    final ParameterValue<?>[] values = parameters.values().toArray(new ParameterValue<?>[3]);
    assertEquals("parameters",    "Geocentric translations", parameters.getDescriptor().getName().getCode());
    assertEquals("parameters[0]", "X-axis translation",      values[0] .getDescriptor().getName().getCode());
    assertEquals("parameters[1]", "Y-axis translation",      values[1] .getDescriptor().getName().getCode());
    assertEquals("parameters[2]", "Z-axis translation",      values[2] .getDescriptor().getName().getCode());
    assertEquals("parameters[0]", -146.414, values[0].doubleValue(), STRICT);
    assertEquals("parameters[1]",  507.337, values[1].doubleValue(), STRICT);
    assertEquals("parameters[2]",  680.507, values[2].doubleValue(), STRICT);
    assertEquals(3, values.length);

    final Matrix m = MathTransforms.getMatrix(op.getMathTransform());
    assertNotNull("transform", m);
    for (int j=m.getNumRow(); --j >= 0;) {
        for (int i=m.getNumCol(); --i >= 0;) {
            double expected = (i == j) ? 1 : 0;
            if (i == 2) switch (j) {
                case 0: expected = -146.414; break;
                case 1: expected =  507.337; break;
                case 2: expected =  680.507; break;
            }
            assertEquals(expected, m.getElement(j,i), STRICT);
        }
    }
}
 
Example #29
Source File: MapProjectionParametersTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Tests the inverse flattening dynamic parameter set after the semi-major axis length.
 * This method tests actually the capability to compute the semi-minor axis length.
 */
@Test
public void testSemiMinor() {
    final MapProjectionDescriptor descriptor = createDescriptor(0);
    final ParameterValueGroup parameters = descriptor.createValue();

    parameters.parameter(SEMI_MAJOR).setValue(6378137.000); // WGS84
    parameters.parameter(INVERSE_FLATTENING).setValue(298.257223563);
    assertEquals(298.257, parameters.parameter(INVERSE_FLATTENING).doubleValue(), 0.001);
    assertEquals(6378137, parameters.parameter(SEMI_MAJOR)        .doubleValue(), 0.5);
    assertEquals(6356752, parameters.parameter(SEMI_MINOR)        .doubleValue(), 0.5);
}
 
Example #30
Source File: StoreTest.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Verifies that specifying a format effectively restricts the number of resources to be found.
 *
 * @throws URISyntaxException if the URL to test data can not be converted to a path of the file system.
 * @throws DataStoreException if an error occurred while reading the resources.
 * @throws IOException if an I/O error occurs.
 */
@Test
public void testSearchProviderParameter() throws URISyntaxException, DataStoreException, IOException {
    final Set<String> identifiers = new HashSet<>(Arrays.asList("Sample 1", "Sample 2", "Sample 3", "data4"));
    final ParameterValueGroup params = FolderStoreProvider.PARAMETERS.createValue();
    params.parameter("location").setValue(testDirectory());
    params.parameter("format").setValue("XML");
    try (Store store = (Store) FolderStoreProvider.INSTANCE.open(params)) {
        assertEquals("Expected one less data store.", 3, store.components().size());
        verifyContent(store, identifiers);
    }
    if (!identifiers.isEmpty()) {
        fail("Missing resources: " + identifiers);
    }
}