Search in sources :

Example 1 with Identifier

use of org.opengis.metadata.Identifier in project sis by apache.

the class BuilderTest method testAddIdentifiers.

/**
 * Tests {@link Builder#addIdentifier(Citation, String)} and {@link Builder#addIdentifier(String)} with code space.
 */
@Test
public void testAddIdentifiers() {
    // Expected values to be used later in the test.
    final Identifier id1 = new ImmutableIdentifier(Citations.EPSG, "EPSG", "9804");
    final Identifier id2 = new ImmutableIdentifier(Citations.GEOTIFF, "GeoTIFF", "7");
    assertEquals("EPSG:9804", IdentifiedObjects.toString(id1));
    assertEquals("GeoTIFF:7", IdentifiedObjects.toString(id2));
    // The test.
    final BuilderMock builder = createMercator(false, true);
    assertArrayEquals(new Identifier[] { id1, id2 }, builder.getIdentifiers());
}
Also used : ImmutableIdentifier(org.apache.sis.metadata.iso.ImmutableIdentifier) SimpleIdentifier(org.apache.sis.internal.simple.SimpleIdentifier) Identifier(org.opengis.metadata.Identifier) ReferenceIdentifier(org.opengis.referencing.ReferenceIdentifier) ImmutableIdentifier(org.apache.sis.metadata.iso.ImmutableIdentifier) Test(org.junit.Test)

Example 2 with Identifier

use of org.opengis.metadata.Identifier 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 3 with Identifier

use of org.opengis.metadata.Identifier in project sis by apache.

the class GeoKeysTest method verifyProjectionNames.

/**
 * Verifies that GeoTIFF projection aliases registered in the {@link org.apache.sis.internal.referencing.provider}
 * package match the name of fields listed in {@link GeoIdentifiers} and that GeoTIFF numerical codes correspond.
 * This method verifies only projection names and identifiers, not parameter names.
 */
@Test
@DependsOnMethod("testName")
public void verifyProjectionNames() {
    final MathTransformFactory factory = DefaultFactories.forBuildin(MathTransformFactory.class);
    for (final OperationMethod method : factory.getAvailableMethods(SingleOperation.class)) {
        final Identifier identifier = IdentifiedObjects.getIdentifier(method, Citations.GEOTIFF);
        final Set<String> names = IdentifiedObjects.getNames(method, Citations.GEOTIFF);
        /*
             * If there is no GeoTIFF identifiers, we should have no GeoTIFF name neither.
             * However we may have more than one name, since GeoTIFF defines also aliases.
             */
        assertEquals(method.getName().getCode(), identifier == null, names.isEmpty());
        if (identifier != null) {
            final int code = Short.parseShort(identifier.getCode());
            for (final String name : names) {
                assertEquals(name, code, GeoIdentifiers.code(name));
            }
        }
    }
}
Also used : Identifier(org.opengis.metadata.Identifier) MathTransformFactory(org.opengis.referencing.operation.MathTransformFactory) OperationMethod(org.opengis.referencing.operation.OperationMethod) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 4 with Identifier

use of org.opengis.metadata.Identifier in project sis by apache.

the class IdentifierCommand method run.

/**
 * Prints identifier information.
 *
 * @return 0 on success, or an exit code if the command failed for a reason other than an uncaught Java exception.
 */
@Override
public int run() throws Exception {
    /*
         * Read metadata from the data storage only after we verified that the arguments are valid.
         * The input can be a file given on the command line, or the standard input stream.
         */
    Object metadata = readMetadataOrCRS();
    if (hasUnexpectedFileCount) {
        return Command.INVALID_ARGUMENT_EXIT_CODE;
    }
    if (metadata != null) {
        final List<Row> rows;
        if (metadata instanceof DefaultMetadata) {
            rows = new ArrayList<>();
            final Identifier id = ((DefaultMetadata) metadata).getMetadataIdentifier();
            if (id instanceof DefaultIdentifier) {
                CharSequence desc = ((DefaultIdentifier) id).getDescription();
                if (desc != null && !files.isEmpty())
                    desc = files.get(0);
                rows.add(new Row(State.VALID, IdentifiedObjects.toString(id), desc));
            }
            for (final ReferenceSystem rs : ((Metadata) metadata).getReferenceSystemInfo()) {
                rows.add(create(rs));
            }
        } else {
            rows = Collections.singletonList(create((ReferenceSystem) metadata));
        }
        print(rows);
    }
    return 0;
}
Also used : Identifier(org.opengis.metadata.Identifier) DefaultIdentifier(org.apache.sis.metadata.iso.DefaultIdentifier) DefaultMetadata(org.apache.sis.metadata.iso.DefaultMetadata) DefaultMetadata(org.apache.sis.metadata.iso.DefaultMetadata) Metadata(org.opengis.metadata.Metadata) DefaultIdentifier(org.apache.sis.metadata.iso.DefaultIdentifier) ReferenceSystem(org.opengis.referencing.ReferenceSystem)

Example 5 with Identifier

use of org.opengis.metadata.Identifier in project sis by apache.

the class Builder method rename.

/**
 * Replaces the names associated to the given authority by the given new names.
 * More specifically:
 *
 * <ul>
 *   <li>The first occurrence of a name associated to {@code authority} will be replaced by a new name
 *       with the same authority and the local part defined by {@code replacements[0]}.</li>
 *   <li>The second occurrence of a name associated to {@code authority} will be replaced by a new name
 *       with the same authority and the local part defined by {@code replacements[1]}.</li>
 *   <li><i>etc.</i> until one of the following conditions is meet:
 *     <ul>
 *       <li>There is no more name associated to the given authority in this {@code Builder}, in which case
 *           new names are inserted for all remaining elements in the {@code replacements} array.</li>
 *       <li>There is no more elements in the {@code replacements} array, in which case all remaining
 *           names associated to the given authority in this {@code Builder} are removed.</li>
 *     </ul>
 *   </li>
 * </ul>
 *
 * This method could also be understood as a {@code setNames(Citation, ...)} method, except that it modifies
 * only the names associated to the given authority and preserves the same order than previous names.
 *
 * @param  authority     the authority of the names to replaces.
 * @param  replacements  the new local parts for the names to replace,
 *         or {@code null} or an empty array for removing all names associated to the given authority.
 * @return {@code this}, for method call chaining.
 *
 * @since 0.6
 */
public B rename(final Citation authority, final CharSequence... replacements) {
    ensureNonNull("authority", authority);
    final int length = (replacements != null) ? replacements.length : 0;
    /*
         * IdentifiedObjects store the "primary name" separately from aliases. Consequently we will start
         * the iteration at index -1 where i=-1 is used as a sentinel value meaning "primary name" before
         * to iterate over the aliases. Note that the type is not the same:
         *
         *   - Primary:   Identifier or String
         *   - Aliases:   Identifier or GenericName
         */
    int next = 0;
    int insertAt = aliases.size();
    for (int i = -1; i < aliases.size(); i++) {
        final Object old = (i < 0) ? properties.get(IdentifiedObject.NAME_KEY) : aliases.get(i);
        if (old == null) {
            // Actually only the primary name can be null.
            continue;
        }
        // Usually true even for aliases.
        final boolean wasID = (old instanceof Identifier);
        if (!authority.equals(wasID ? ((Identifier) old).getAuthority() : getAuthority())) {
            // Current name is not for the authority we are looking for.
            continue;
        }
        /*
             * Found a name associated to the given authority. Process to the replacement if we still
             * have some elements to take in the 'replacements' array, otherwise remove the name.
             */
        if (next < length) {
            final CharSequence name;
            ensureNonNullElement("replacements", next, name = replacements[next++]);
            /*
                 * If the current name matches the specified replacement, we can leave the name as-is.
                 * Only if the name (in its local part) is not the same, proceed to the replacement.
                 */
            final String code = name.toString();
            if (!code.equals(wasID ? ((Identifier) old).getCode() : old.toString())) {
                if (i < 0) {
                    properties.put(IdentifiedObject.NAME_KEY, (authority != getAuthority()) ? new NamedIdentifier(authority, name) : code);
                } else {
                    aliases.set(i, createName(authority, name));
                }
                insertAt = i + 1;
            }
        } else {
            if (i < 0) {
                properties.remove(IdentifiedObject.NAME_KEY);
            } else {
                aliases.remove(i--);
            }
        }
    }
    /*
         * If there is any remaining elements in the 'replacements' array, insert them right after the last
         * element of the given authority that we found (so we keep together the names of the same authority).
         */
    while (next < length) {
        final CharSequence name;
        ensureNonNullElement("replacements", next, name = replacements[next++]);
        aliases.add(insertAt++, createName(authority, name));
    }
    /*
         * If the primary name has been removed as a result of this method execution,
         * take the first alias as the new primary name.
         */
    if (properties.get(IdentifiedObject.NAME_KEY) == null && !aliases.isEmpty()) {
        properties.put(IdentifiedObject.NAME_KEY, toIdentifier(aliases.remove(0)));
    }
    return self();
}
Also used : ImmutableIdentifier(org.apache.sis.metadata.iso.ImmutableIdentifier) Identifier(org.opengis.metadata.Identifier) ReferenceIdentifier(org.opengis.referencing.ReferenceIdentifier) IdentifiedObject(org.opengis.referencing.IdentifiedObject) InternationalString(org.opengis.util.InternationalString)

Aggregations

Identifier (org.opengis.metadata.Identifier)60 ReferenceIdentifier (org.opengis.referencing.ReferenceIdentifier)21 Test (org.junit.Test)14 ImmutableIdentifier (org.apache.sis.metadata.iso.ImmutableIdentifier)11 Citation (org.opengis.metadata.citation.Citation)10 IdentifiedObject (org.opengis.referencing.IdentifiedObject)10 InternationalString (org.opengis.util.InternationalString)10 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)6 DefaultIdentifier (org.apache.sis.metadata.iso.DefaultIdentifier)6 IdentifierMap (org.apache.sis.xml.IdentifierMap)6 GeneralParameterDescriptor (org.opengis.parameter.GeneralParameterDescriptor)5 OperationMethod (org.opengis.referencing.operation.OperationMethod)5 NameToIdentifier (org.apache.sis.internal.metadata.NameToIdentifier)4 NamedIdentifier (org.apache.sis.referencing.NamedIdentifier)4 GenericName (org.opengis.util.GenericName)4 URI (java.net.URI)3 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)3 IdentityHashMap (java.util.IdentityHashMap)2 LinkedHashMap (java.util.LinkedHashMap)2