Search in sources :

Example 1 with Parameterized

use of org.apache.sis.parameter.Parameterized in project sis by apache.

the class ZonedGridSystemTest method testUTM.

/**
 * 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″W
    -79 - (23 - 13.70 / 60) / 60, // 43°38′33.24″N
    43 + (38 + 33.24 / 60) / 60 }, new double[] { 17630698.19, 4833450.51 });
}
Also used : Parameterized(org.apache.sis.parameter.Parameterized) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) Test(org.junit.Test)

Example 2 with Parameterized

use of org.apache.sis.parameter.Parameterized in project sis by apache.

the class ServicesForMetadata method toFormattableObject.

/**
 * 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}.
 *
 * @since 0.6
 */
@Override
public FormattableObject toFormattableObject(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;
        }
    };
}
Also used : Parameterized(org.apache.sis.parameter.Parameterized) Matrix(org.opengis.referencing.operation.Matrix) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) Formatter(org.apache.sis.io.wkt.Formatter) FormattableObject(org.apache.sis.io.wkt.FormattableObject)

Example 3 with Parameterized

use of org.apache.sis.parameter.Parameterized in project sis by apache.

the class ConcatenatedTransform method getParameterised.

/**
 * If there is exactly one transform step which is {@linkplain Parameterized parameterized},
 * returns that transform step. Otherwise returns {@code null}.
 *
 * <p>This method normally requires that there is exactly one transform step remaining after we
 * processed map projections in the special way described in {@link #getParameterValues()},
 * because if they were more than one remaining steps, the returned parameters would not be
 * sufficient for rebuilding the full concatenated transform. Returning parameters when there
 * is more than one remaining step, even if all other transform steps are not parameterizable,
 * would be a contract violation.</p>
 *
 * <p>However in the special case where we are getting the parameters of a {@code CoordinateOperation} instance
 * through {@link org.apache.sis.referencing.operation.AbstractCoordinateOperation#getParameterValues()} method
 * (often indirectly trough WKT formatting of a {@code "ProjectedCRS"} element), then the above rule is slightly
 * relaxed: we ignore affine transforms in order to accept axis swapping or unit conversions. We do that in that
 * particular case only because the coordinate systems given with the enclosing {@code CoordinateOperation} or
 * {@code GeneralDerivedCRS} specify the axis swapping and unit conversions.
 * This special case is internal to SIS implementation and should be unknown to users.</p>
 *
 * @return the parameterizable transform step, or {@code null} if none.
 */
private Parameterized getParameterised() {
    Parameterized param = null;
    final List<Object> transforms = getPseudoSteps();
    if (transforms.size() == 1 || Semaphores.query(Semaphores.ENCLOSED_IN_OPERATION)) {
        for (final Object candidate : transforms) {
            /*
                 * Search for non-linear parameters only, ignoring affine transforms and the matrices
                 * computed by ContextualParameters. Note that the 'transforms' list is guaranteed to
                 * contains at least one non-linear parameter, otherwise we would not have created a
                 * ConcatenatedTransform instance.
                 */
            if (!(candidate instanceof Matrix) && !(candidate instanceof LinearTransform)) {
                if ((param == null) && (candidate instanceof Parameterized)) {
                    param = (Parameterized) candidate;
                } else {
                    /*
                         * Found more than one group of non-linear parameters, or found an object
                         * that do not declare its parameters.  In the later case, conservatively
                         * returns 'null' because we do not know what the real parameters are.
                         */
                    return null;
                }
            }
        }
    }
    return param;
}
Also used : Parameterized(org.apache.sis.parameter.Parameterized) Matrix(org.opengis.referencing.operation.Matrix) FormattableObject(org.apache.sis.io.wkt.FormattableObject)

Example 4 with Parameterized

use of org.apache.sis.parameter.Parameterized in project sis by apache.

the class DefaultOperationMethod method formatTo.

/**
 * Formats this operation as a <cite>Well Known Text</cite> {@code Method[…]} element.
 *
 * @return {@code "Method"} (WKT 2) or {@code "Projection"} (WKT 1).
 *
 * @see <a href="http://docs.opengeospatial.org/is/12-063r5/12-063r5.html#118">WKT 2 specification §17.2.3</a>
 */
@Override
protected String formatTo(final Formatter formatter) {
    final boolean isWKT1 = formatter.getConvention().majorVersion() == 1;
    /*
         * The next few lines below are basically a copy of the work done by super.formatTo(formatter),
         * which search for the name to write inside METHOD["name"]. The difference is in the fallback
         * executed if we do not find a name for the given authority.
         */
    final Citation authority = formatter.getNameAuthority();
    String name = IdentifiedObjects.getName(this, authority);
    ElementKind kind = ElementKind.METHOD;
    if (name == null) {
        /*
             * No name found for the given authority. We may use the primary name as a fallback.
             * But before doing that, maybe we can find the name that we are looking for in the
             * hard-coded values in the 'org.apache.sis.internal.referencing.provider' package.
             * The typical use case is when this DefaultOperationMethod has been instantiated
             * by the EPSG factory using only the information found in the EPSG database.
             *
             * We can find the hard-coded names by looking at the ParameterDescriptorGroup of the
             * enclosing ProjectedCRS or DerivedCRS. This is because that parameter descriptor was
             * typically provided by the 'org.apache.sis.internal.referencing.provider' package in
             * order to create the MathTransform associated with the enclosing CRS.  The enclosing
             * CRS is either the immediate parent in WKT 1, or the parent of the parent in WKT 2.
             */
        final FormattableObject parent = formatter.getEnclosingElement(isWKT1 ? 1 : 2);
        if (parent instanceof GeneralDerivedCRS) {
            final Conversion conversion = ((GeneralDerivedCRS) parent).getConversionFromBase();
            if (conversion != null) {
                // Should never be null, but let be safe.
                final ParameterDescriptorGroup descriptor;
                if (conversion instanceof Parameterized) {
                    // Usual case in SIS implementation.
                    descriptor = ((Parameterized) conversion).getParameterDescriptors();
                } else {
                    descriptor = conversion.getParameterValues().getDescriptor();
                }
                name = IdentifiedObjects.getName(descriptor, authority);
            }
        }
        if (name == null) {
            name = IdentifiedObjects.getName(this, null);
            if (name == null) {
                name = Vocabulary.getResources(formatter.getLocale()).getString(Vocabulary.Keys.Unnamed);
                // Because the "Unnamed" string is not a real OperationMethod name.
                kind = ElementKind.NAME;
            }
        }
    }
    formatter.append(name, kind);
    if (isWKT1) {
        /*
             * The WKT 1 keyword is "PROJECTION", which imply that the operation method should be of type
             * org.opengis.referencing.operation.Projection. So strictly speaking only the first check in
             * the following 'if' statement is relevant.
             *
             * Unfortunately in many cases we do not know the operation type, because the method that we
             * invoked - getOperationType() - is not a standard OGC/ISO property, so this information is
             * usually not provided in XML documents for example.  The user could also have instantiated
             * DirectOperationMethod directly without creating a subclass. Consequently we also accept to
             * format the keyword as "PROJECTION" if the operation type *could* be a projection. This is
             * the second check in the following 'if' statement.
             *
             * In other words, the combination of those two checks exclude the following operation types:
             * Transformation, ConcatenatedOperation, PassThroughOperation, or any user-defined type that
             * do not extend Projection. All other operation types are accepted.
             */
        final Class<? extends SingleOperation> type = getOperationType();
        if (Projection.class.isAssignableFrom(type) || type.isAssignableFrom(Projection.class)) {
            return WKTKeywords.Projection;
        }
        formatter.setInvalidWKT(this, null);
    }
    return WKTKeywords.Method;
}
Also used : ElementKind(org.apache.sis.io.wkt.ElementKind) Parameterized(org.apache.sis.parameter.Parameterized) ParameterDescriptorGroup(org.opengis.parameter.ParameterDescriptorGroup) DefaultParameterDescriptorGroup(org.apache.sis.parameter.DefaultParameterDescriptorGroup) Projection(org.opengis.referencing.operation.Projection) GeneralDerivedCRS(org.opengis.referencing.crs.GeneralDerivedCRS) Citation(org.opengis.metadata.citation.Citation) InternationalString(org.opengis.util.InternationalString) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) FormattableObject(org.apache.sis.io.wkt.FormattableObject) Conversion(org.opengis.referencing.operation.Conversion)

Aggregations

Parameterized (org.apache.sis.parameter.Parameterized)4 FormattableObject (org.apache.sis.io.wkt.FormattableObject)3 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)2 Matrix (org.opengis.referencing.operation.Matrix)2 ElementKind (org.apache.sis.io.wkt.ElementKind)1 Formatter (org.apache.sis.io.wkt.Formatter)1 DefaultParameterDescriptorGroup (org.apache.sis.parameter.DefaultParameterDescriptorGroup)1 SimpleInternationalString (org.apache.sis.util.iso.SimpleInternationalString)1 Test (org.junit.Test)1 Citation (org.opengis.metadata.citation.Citation)1 ParameterDescriptorGroup (org.opengis.parameter.ParameterDescriptorGroup)1 GeneralDerivedCRS (org.opengis.referencing.crs.GeneralDerivedCRS)1 Conversion (org.opengis.referencing.operation.Conversion)1 Projection (org.opengis.referencing.operation.Projection)1 InternationalString (org.opengis.util.InternationalString)1