Search in sources :

Example 51 with Identifier

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

the class NameToIdentifier method isHeuristicMatchForIdentifier.

/**
 * Returns {@code true} if the given identifier to search matches one of the object identifiers.
 *
 * @param  identifiers  the identifiers to compare against {@code toSearch}.
 * @param  toSearch     the identifier to check for equality.
 * @return {@code true} if the identifier to search is found in the given set of identifiers.
 *
 * @since 0.8
 */
public static boolean isHeuristicMatchForIdentifier(final Iterable<? extends ReferenceIdentifier> identifiers, final String toSearch) {
    if (toSearch != null && identifiers != null) {
        int s = toSearch.indexOf(DefaultNameSpace.DEFAULT_SEPARATOR);
        if (s < 0) {
            // no codespace in searched name
            for (final Identifier id : identifiers) {
                if (toSearch.equalsIgnoreCase(id.getCode())) {
                    return true;
                }
            }
            return false;
        }
        do {
            final String codespace = toSearch.substring(0, s).trim();
            final String code = toSearch.substring(++s).trim();
            for (final ReferenceIdentifier id : identifiers) {
                if (codespace.equalsIgnoreCase(id.getCodeSpace()) && code.equalsIgnoreCase(id.getCode())) {
                    return true;
                }
            }
            s = toSearch.indexOf(DefaultNameSpace.DEFAULT_SEPARATOR, s);
        } while (s >= 0);
    }
    return false;
}
Also used : Identifier(org.opengis.metadata.Identifier) ReferenceIdentifier(org.opengis.referencing.ReferenceIdentifier) ReferenceIdentifier(org.opengis.referencing.ReferenceIdentifier) InternationalString(org.opengis.util.InternationalString)

Example 52 with Identifier

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

the class ServicesForUtility method createCitation.

/**
 * Returns the build-in citation for the given primary key, or {@code null}.
 *
 * @param  key  the primary key of the desired citation.
 * @return the requested citation, or {@code null} if unknown.
 *
 * @todo The content is hard-coded for now. But the plan for a future version is to fetch richer information
 *       from a database, including for example the responsible party and the URL. However that method would
 *       need to make sure that the given key is present in the alternate titles, since we rely on that when
 *       checking for code spaces.
 */
public static Citation createCitation(final String key) {
    CharSequence title;
    CharSequence alternateTitle = null;
    CharSequence edition = null;
    String code = null;
    String codeSpace = null;
    String version = null;
    Identifier[] alternateIdentifiers = null;
    CharSequence citedResponsibleParty = null;
    PresentationForm presentationForm = null;
    // Copy citedResponsibleParty from those citations.
    Citation[] copyFrom = null;
    switch(key) {
        case "ISO 19115-1":
            {
                title = "Geographic Information — Metadata Part 1: Fundamentals";
                edition = "ISO 19115-1:2014(E)";
                code = "19115-1";
                codeSpace = "ISO";
                version = "2014(E)";
                citedResponsibleParty = "International Organization for Standardization";
                presentationForm = PresentationForm.DOCUMENT_DIGITAL;
                break;
            }
        case "ISO 19115-2":
            {
                title = "Geographic Information — Metadata Part 2: Extensions for imagery and gridded data";
                edition = "ISO 19115-2:2009(E)";
                code = "19115-2";
                codeSpace = "ISO";
                version = "2009(E)";
                copyFrom = new Citation[] { Citations.ISO_19115.get(0) };
                presentationForm = PresentationForm.DOCUMENT_DIGITAL;
                break;
            }
        case "WMS":
            {
                // OGC title
                title = "Web Map Server";
                // ISO title
                alternateTitle = "Geographic Information — Web map server interface";
                alternateIdentifiers = new Identifier[] { new ImmutableIdentifier(null, "OGC", "06-042", null, null), new ImmutableIdentifier(null, "ISO", "19128", "2005", null) };
                edition = "1.3";
                code = "WMS";
                codeSpace = "OGC";
                copyFrom = new Citation[] { Citations.OGC, Citations.ISO_19115.get(0) };
                presentationForm = PresentationForm.DOCUMENT_DIGITAL;
                break;
            }
        case Constants.OGC:
            {
                title = "Identifiers in OGC namespace";
                code = Constants.OGC;
                citedResponsibleParty = "Open Geospatial Consortium";
                presentationForm = PresentationForm.DOCUMENT_DIGITAL;
                break;
            }
        case Constants.IOGP:
            {
                // Not in public API (see Citations.IOGP javadoc)
                // Geomatics Guidance Note number 7, part 1
                title = "Using the EPSG Geodetic Parameter Dataset";
                code = Constants.IOGP;
                copyFrom = new Citation[] { Citations.EPSG };
                presentationForm = PresentationForm.DOCUMENT_DIGITAL;
                break;
            }
        case Constants.EPSG:
            {
                title = "EPSG Geodetic Parameter Dataset";
                code = Constants.EPSG;
                codeSpace = Constants.IOGP;
                citedResponsibleParty = "International Association of Oil & Gas producers";
                presentationForm = PresentationForm.TABLE_DIGITAL;
                /*
                 * More complete information is provided as an ISO 19115 structure
                 * in EPSG Surveying and Positioning Guidance Note Number 7, part 1.
                 * EPSGDataAccess.getAuthority() also add more information.
                 * After we moved the content of this citation in a database,
                 * EPSGDataAccess.getAuthority() should use this citation as a template.
                 */
                break;
            }
        case Constants.SIS:
            {
                title = "Apache Spatial Information System";
                code = key;
                break;
            }
        case "ISBN":
            {
                title = "International Standard Book Number";
                alternateTitle = key;
                break;
            }
        case "ISSN":
            {
                title = "International Standard Serial Number";
                alternateTitle = key;
                break;
            }
        case Constants.PROJ4:
            {
                title = "Proj.4";
                break;
            }
        case "S57":
            {
                title = "S-57";
                break;
            }
        default:
            return null;
    }
    /*
         * Do not use the 'c.getFoo().add(foo)' pattern below. Use the 'c.setFoo(singleton(foo))' pattern instead.
         * This is because this method may be invoked during XML serialization, in which case some getter methods
         * may return null (for preventing JAXB to marshal some empty elements).
         */
    final DefaultCitation c = new DefaultCitation(title);
    if (alternateTitle != null)
        c.setAlternateTitles(singleton(Types.toInternationalString(alternateTitle)));
    if (edition != null)
        c.setEdition(Types.toInternationalString(edition));
    if (code != null)
        c.setIdentifiers(singleton(new ImmutableIdentifier(null, codeSpace, code, version, null)));
    if (presentationForm != null)
        c.setPresentationForms(singleton(presentationForm));
    if (citedResponsibleParty != null) {
        final DefaultResponsibleParty r = new DefaultResponsibleParty(Role.PRINCIPAL_INVESTIGATOR);
        r.setParties(singleton(new DefaultOrganisation(citedResponsibleParty, null, null, null)));
        c.setCitedResponsibleParties(singleton(r));
    }
    if (copyFrom != null) {
        for (final Citation other : copyFrom) {
            final Collection<? extends ResponsibleParty> parties = other.getCitedResponsibleParties();
            final Collection<ResponsibleParty> current = c.getCitedResponsibleParties();
            if (current != null) {
                current.addAll(parties);
            } else {
                c.setCitedResponsibleParties(parties);
            }
        }
    }
    if (alternateIdentifiers != null) {
        // getIdentifiers() should not return null at this point.
        c.getIdentifiers().addAll(Arrays.asList(alternateIdentifiers));
    }
    c.freeze();
    return c;
}
Also used : DefaultOrganisation(org.apache.sis.metadata.iso.citation.DefaultOrganisation) DefaultResponsibleParty(org.apache.sis.metadata.iso.citation.DefaultResponsibleParty) DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) ResponsibleParty(org.opengis.metadata.citation.ResponsibleParty) DefaultResponsibleParty(org.apache.sis.metadata.iso.citation.DefaultResponsibleParty) ImmutableIdentifier(org.apache.sis.metadata.iso.ImmutableIdentifier) Identifier(org.opengis.metadata.Identifier) PresentationForm(org.opengis.metadata.citation.PresentationForm) Citation(org.opengis.metadata.citation.Citation) DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) ImmutableIdentifier(org.apache.sis.metadata.iso.ImmutableIdentifier)

Example 53 with Identifier

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

the class ReferencingUtilities method getPropertiesForModifiedCRS.

/**
 * Returns the properties of the given object but potentially with a modified name.
 * Current implement truncates the name at the first non-white character which is not
 * a valid Unicode identifier part, with the following exception:
 *
 * <ul>
 *   <li>If the character is {@code '('} and the content until the closing {@code ')'} is a valid
 *       Unicode identifier, then that part is included. The intent is to keep the prime meridian
 *       name in names like <cite>"NTF (Paris)"</cite>.</li>
 * </ul>
 *
 * <div class="note"><b>Example:</b><ul>
 *   <li><cite>"NTF (Paris)"</cite> is left unchanged.</li>
 *   <li><cite>"WGS 84 (3D)"</cite> is truncated as <cite>"WGS 84"</cite>.</li>
 *   <li><cite>"Ellipsoidal 2D CS. Axes: latitude, longitude. Orientations: north, east. UoM: degree"</cite>
 *       is truncated as <cite>"Ellipsoidal 2D CS"</cite>.</li>
 * </ul></div>
 *
 * @param  object    the identified object to view as a properties map.
 * @return a view of the identified object properties.
 *
 * @see IdentifiedObjects#getProperties(IdentifiedObject, String...)
 *
 * @since 0.7
 */
public static Map<String, ?> getPropertiesForModifiedCRS(final IdentifiedObject object) {
    final Map<String, ?> properties = IdentifiedObjects.getProperties(object, IdentifiedObject.IDENTIFIERS_KEY);
    final Identifier id = (Identifier) properties.get(IdentifiedObject.NAME_KEY);
    if (id != null) {
        String name = id.getCode();
        if (name != null) {
            for (int i = 0; i < name.length(); ) {
                final int c = name.codePointAt(i);
                if (!Character.isUnicodeIdentifierPart(c) && !Character.isSpaceChar(c)) {
                    if (c == '(') {
                        final int endAt = name.indexOf(')', i);
                        if (endAt >= 0) {
                            final String extra = name.substring(i + 1, endAt);
                            if (CharSequences.isUnicodeIdentifier(extra)) {
                                i += extra.length() + 2;
                            }
                        }
                    }
                    name = CharSequences.trimWhitespaces(name, 0, i).toString();
                    if (!name.isEmpty()) {
                        final Map<String, Object> copy = new HashMap<>(properties);
                        copy.put(IdentifiedObject.NAME_KEY, name);
                        return copy;
                    }
                }
                i += Character.charCount(c);
            }
        }
    }
    return properties;
}
Also used : Identifier(org.opengis.metadata.Identifier) HashMap(java.util.HashMap) IdentifiedObject(org.opengis.referencing.IdentifiedObject)

Example 54 with Identifier

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

the class Code method forIdentifiedObject.

/**
 * Returns a {@code <gml:identifier>} for the given identified object, or {@code null} if none.
 * This method searches for the following identifiers, in preference order:
 * <ul>
 *   <li>The first identifier having a code that begin with {@code "urn:"}.</li>
 *   <li>The first identifier having a code that begin with {@code "http:"}.</li>
 *   <li>The first identifier in the {@code "EPSG"} codespace, converted to the {@code "urn:} syntax.</li>
 *   <li>The first identifier in other codespace, converted to the {@code "urn:} syntax if possible.</li>
 * </ul>
 *
 * @param  type         the type of the identified object.
 * @param  identifiers  the object identifiers, or {@code null} if none.
 * @return the {@code <gml:identifier>} as a {@code Code} instance, or {@code null} if none.
 */
public static Code forIdentifiedObject(final Class<?> type, final Iterable<? extends ReferenceIdentifier> identifiers) {
    if (identifiers != null) {
        boolean isHTTP = false;
        boolean isEPSG = false;
        ReferenceIdentifier fallback = null;
        for (final ReferenceIdentifier identifier : identifiers) {
            final String code = identifier.getCode();
            // Paranoiac check.
            if (code == null)
                continue;
            if (code.regionMatches(true, 0, "urn:", 0, 4)) {
                return new Code(identifier);
            }
            if (!isHTTP) {
                isHTTP = code.regionMatches(true, 0, "http:", 0, 5);
                if (isHTTP) {
                    fallback = identifier;
                } else if (!isEPSG) {
                    isEPSG = Constants.EPSG.equalsIgnoreCase(identifier.getCodeSpace());
                    if (isEPSG || fallback == null) {
                        fallback = identifier;
                    }
                }
            }
        }
        /*
             * If no "urn:" or "http:" form has been found, try to create a "urn:" form from the first identifier.
             * For example "EPSG:4326" may be converted to "urn:ogc:def:crs:EPSG:8.2:4326". If the first identifier
             * can not be converted to a "urn:" form, then it will be returned as-is.
             */
        if (fallback != null) {
            if (!isHTTP) {
                final String urn = NameMeaning.toURN(type, fallback.getCodeSpace(), fallback.getVersion(), fallback.getCode());
                if (urn != null) {
                    final Code code = new Code();
                    /*
                         * Rational for EPSG special case below:
                         * -------------------------------------
                         * Apache SIS already formats the Identifier.getCodeSpace() value in the URN.
                         * This value is "EPSG" for IdentifiedObject instances from the EPSG database.
                         * But GML additionally have a "codeSpace" attribute, and common usage seems to
                         * give the "OGP" or "IOGP" value to that attribute as in the following example:
                         *
                         *     <gml:identifier codeSpace="IOGP">urn:ogc:def:crs:EPSG::4326</gml:identifier>
                         *
                         * A discussion can be found in the comments of https://issues.apache.org/jira/browse/SIS-196
                         *
                         * Where to take this "IOGP" value from? It is not the Identifier.getCodeSpace() String value
                         * since ISO 19115-1 clearly uses the "EPSG" value in their example.  We could consider using
                         * the Identifier.getAuthority() value, which is a Citation. But the "EPSG" part in above URN
                         * is named "the authority" in URN specification, which suggest that Identifier.getAuthority()
                         * should return a citation for the "EPSG Geodetic Parameter Dataset" rather than for the IOGP
                         * organisation.
                         *
                         * Apache SIS declares IOGP as the codespace of the EPSG codespace, i.e. the identifier of the
                         * EPSG authority is "IOGP:EPSG". So the code below searches for the "IOGP" part of the above.
                         * However there is no indication at this time that objects from other sources than SIS would
                         * follow such convention, so we also keep a hard-coded "IOGP" default value for now.
                         *
                         * A symmetrical special handling for EPSG is done in the 'getIdentifier()' method of this class.
                         *
                         * See https://issues.apache.org/jira/browse/SIS-199
                         */
                    final Citation authority = fallback.getAuthority();
                    if (isEPSG) {
                        // Default value if we do not find a codespace below.
                        code.codeSpace = Constants.IOGP;
                        if (authority != null) {
                            for (final Identifier id : authority.getIdentifiers()) {
                                if (Constants.EPSG.equalsIgnoreCase(id.getCode())) {
                                    if (id instanceof ReferenceIdentifier) {
                                        final String cs = ((ReferenceIdentifier) id).getCodeSpace();
                                        if (cs != null) {
                                            code.codeSpace = cs;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    } else {
                        code.codeSpace = getCodeSpace(authority);
                    }
                    code.code = urn;
                    return code;
                }
            }
            return new Code(fallback);
        }
    }
    return null;
}
Also used : ReferenceIdentifier(org.opengis.referencing.ReferenceIdentifier) NamedIdentifier(org.apache.sis.referencing.NamedIdentifier) Identifier(org.opengis.metadata.Identifier) ReferenceIdentifier(org.opengis.referencing.ReferenceIdentifier) Citation(org.opengis.metadata.citation.Citation)

Example 55 with Identifier

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

the class BuilderTest method testCreationFromObject.

/**
 * Tests the {@link Builder#Builder(IdentifiedObject)} constructor.
 *
 * @since 0.6
 */
@Test
public void testCreationFromObject() {
    final Map<String, Object> properties = new HashMap<>();
    final Identifier id = new SimpleIdentifier(null, "An identifier", false);
    assertNull(properties.put(AbstractIdentifiedObject.IDENTIFIERS_KEY, id));
    assertNull(properties.put(AbstractIdentifiedObject.ALIAS_KEY, "An alias"));
    assertNull(properties.put(AbstractIdentifiedObject.NAME_KEY, "Dummy object"));
    assertNull(properties.put(AbstractIdentifiedObject.REMARKS_KEY, "Some remarks"));
    final BuilderMock builder = new BuilderMock(new AbstractIdentifiedObject(properties));
    assertEquals("Expected only name, remarks and deprecated status.", 3, builder.properties.size());
    builder.onCreate(false);
    assertEquals("Expected name, aliases, identifiers and remarks.", 5, builder.properties.size());
    assertEquals(AbstractIdentifiedObject.NAME_KEY, "Dummy object", builder.properties.get(AbstractIdentifiedObject.NAME_KEY).toString());
    assertEquals(AbstractIdentifiedObject.REMARKS_KEY, "Some remarks", builder.properties.get(AbstractIdentifiedObject.REMARKS_KEY).toString());
    assertEquals(AbstractIdentifiedObject.ALIAS_KEY, "An alias", ((Object[]) builder.properties.get(AbstractIdentifiedObject.ALIAS_KEY))[0].toString());
    assertSame(AbstractIdentifiedObject.IDENTIFIERS_KEY, id, ((Object[]) builder.properties.get(AbstractIdentifiedObject.IDENTIFIERS_KEY))[0]);
}
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) HashMap(java.util.HashMap) SimpleIdentifier(org.apache.sis.internal.simple.SimpleIdentifier) Test(org.junit.Test)

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