Search in sources :

Example 1 with ReferenceSystem

use of org.opengis.referencing.ReferenceSystem in project sis by apache.

the class Formatter method appendComplement.

/**
 * Appends the optional complementary attributes common to many {@link IdentifiedObject} subtypes.
 * Those attributes are {@code ANCHOR}, {@code SCOPE}, {@code AREA}, {@code BBOX}, {@code VERTICALEXTENT},
 * {@code TIMEEXTENT}, {@code ID} (previously known as {@code AUTHORITY}) and {@code REMARKS},
 * and have a special treatment: they are written by {@link #append(FormattableObject)}
 * after the {@code formatTo(Formatter)} method returned.
 *
 * <p>The {@code ID[<name>,<code>,…]} element is normally written only for the root element
 * (unless the convention is {@code INTERNAL}), but there is various exceptions to this rule.
 * If formatted, the {@code ID} element will be by default on the same line than the enclosing
 * element (e.g. {@code SPHEROID["Clarke 1866", …, ID["EPSG", 7008]]}). Other example:</p>
 *
 * {@preformat text
 *   PROJCS["NAD27 / Idaho Central",
 *     GEOGCS[...etc...],
 *     ...etc...
 *     ID["EPSG", 26769]]
 * }
 *
 * For non-internal conventions, all elements other than {@code ID[…]} are formatted
 * only for {@link CoordinateOperation} and root {@link ReferenceSystem} instances,
 * with an exception for remarks of {@code ReferenceSystem} embedded inside {@code CoordinateOperation}.
 * Those restrictions are our interpretation of the following ISO 19162 requirement:
 *
 * <blockquote>(…snip…) {@code <scope extent identifier remark>} is a collection of four optional attributes
 * which may be applied to a coordinate reference system, a coordinate operation or a boundCRS. (…snip…)
 * Identifier (…snip…) may also be utilised for components of these objects although this is not recommended
 * except for coordinate operation methods (including map projections) and parameters. (…snip…)
 * A {@code <remark>} can be included within the descriptions of source and target CRS embedded within
 * a coordinate transformation as well as within the coordinate transformation itself.</blockquote>
 */
@SuppressWarnings("null")
private void appendComplement(final IdentifiedObject object, final FormattableObject parent, final FormattableObject gp) {
    isComplement = true;
    // Whether to format ID[…] elements.
    final boolean showIDs;
    // Whether we shall limit to a single ID[…] element.
    final boolean filterID;
    // Whether to format any element other than ID[…] and Remarks[…].
    final boolean showOthers;
    // Whether to format Remarks[…].
    final boolean showRemarks;
    if (convention == Convention.INTERNAL) {
        showIDs = true;
        filterID = false;
        showOthers = true;
        showRemarks = true;
    } else {
        /*
             * Except for the special cases of OperationMethod and Parameters, ISO 19162 recommends to format the
             * ID only for the root element.  But Apache SIS adds an other exception to this rule by handling the
             * components of CompoundCRS as if they were root elements. The reason is that users often create their
             * own CompoundCRS from standard components, for example by adding a time axis to some standard CRS like
             * "WGS84". The resulting CompoundCRS usually have no identifier. Then the users often need to extract a
             * particular component of a CompoundCRS, most often the horizontal part, and will need its identifier
             * for example in a Web Map Service (WMS). Those ID are lost if we do not format them here.
             */
        if (parent == null || parent instanceof CompoundCRS) {
            showIDs = true;
        } else if (gp instanceof CoordinateOperation && !(parent instanceof IdentifiedObject)) {
            // "SourceCRS[…]" and "TargetCRS[…]" sub-elements in CoordinateOperation.
            showIDs = true;
        } else if (convention == Convention.WKT2_SIMPLIFIED) {
            showIDs = false;
        } else {
            showIDs = (object instanceof OperationMethod) || (object instanceof GeneralParameterDescriptor);
        }
        if (convention.majorVersion() == 1) {
            filterID = true;
            showOthers = false;
            showRemarks = false;
        } else {
            filterID = (parent != null);
            if (object instanceof CoordinateOperation) {
                showOthers = !(parent instanceof ConcatenatedOperation);
                showRemarks = showOthers;
            } else if (object instanceof ReferenceSystem) {
                showOthers = (parent == null);
                showRemarks = (parent == null) || (gp instanceof CoordinateOperation);
            } else {
                // Mandated by ISO 19162.
                showOthers = false;
                showRemarks = false;
            }
        }
    }
    if (showOthers) {
        appendForSubtypes(object);
    }
    if (showIDs) {
        Collection<ReferenceIdentifier> identifiers = object.getIdentifiers();
        if (identifiers != null) {
            // Paranoiac check
            if (filterID) {
                for (final ReferenceIdentifier id : identifiers) {
                    if (Citations.identifierMatches(authority, id.getAuthority())) {
                        identifiers = Collections.singleton(id);
                        break;
                    }
                }
            }
            for (ReferenceIdentifier id : identifiers) {
                if (!(id instanceof FormattableObject)) {
                    id = ImmutableIdentifier.castOrCopy(id);
                }
                append((FormattableObject) id);
                if (filterID)
                    break;
            }
        }
    }
    if (showRemarks) {
        appendOnNewLine(WKTKeywords.Remark, object.getRemarks(), ElementKind.REMARKS);
    }
    isComplement = false;
}
Also used : ReferenceIdentifier(org.opengis.referencing.ReferenceIdentifier) CompoundCRS(org.opengis.referencing.crs.CompoundCRS) GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor) CoordinateOperation(org.opengis.referencing.operation.CoordinateOperation) ConcatenatedOperation(org.opengis.referencing.operation.ConcatenatedOperation) IdentifiedObject(org.opengis.referencing.IdentifiedObject) ReferenceSystem(org.opengis.referencing.ReferenceSystem) OperationMethod(org.opengis.referencing.operation.OperationMethod)

Example 2 with ReferenceSystem

use of org.opengis.referencing.ReferenceSystem in project sis by apache.

the class FrenchProfileTest method testReferenceSystemToAFNOR.

/**
 * Tests {@link FrenchProfile#toAFNOR(ReferenceSystem, boolean)}.
 */
@Test
public void testReferenceSystemToAFNOR() {
    ReferenceSystem std, fra;
    std = new ReferenceSystemMetadata(new ImmutableIdentifier(null, "EPSG", "4326"));
    fra = FrenchProfile.toAFNOR(std, false);
    assertInstanceOf("Expected AFNOR instance.", DirectReferenceSystem.class, fra);
    assertSame("Already an AFNOR instance.", fra, FrenchProfile.toAFNOR(fra));
    fra = FrenchProfile.toAFNOR(std, true);
    assertInstanceOf("Expected AFNOR instance.", IndirectReferenceSystem.class, fra);
    assertSame("Already an AFNOR instance.", fra, FrenchProfile.toAFNOR(fra));
}
Also used : ReferenceSystemMetadata(org.apache.sis.internal.jaxb.metadata.replace.ReferenceSystemMetadata) DirectReferenceSystem(org.apache.sis.internal.profile.fra.DirectReferenceSystem) IndirectReferenceSystem(org.apache.sis.internal.profile.fra.IndirectReferenceSystem) ReferenceSystem(org.opengis.referencing.ReferenceSystem) ImmutableIdentifier(org.apache.sis.metadata.iso.ImmutableIdentifier) Test(org.junit.Test)

Example 3 with ReferenceSystem

use of org.opengis.referencing.ReferenceSystem in project sis by apache.

the class MetadataCommand method run.

/**
 * Prints metadata or CRS 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) {
        if (!(metadata instanceof Metadata)) {
            final DefaultMetadata md = new DefaultMetadata();
            md.setReferenceSystemInfo(Collections.singleton((ReferenceSystem) metadata));
            metadata = md;
        }
        format(metadata);
    }
    return 0;
}
Also used : DefaultMetadata(org.apache.sis.metadata.iso.DefaultMetadata) Metadata(org.opengis.metadata.Metadata) DefaultMetadata(org.apache.sis.metadata.iso.DefaultMetadata) ReferenceSystem(org.opengis.referencing.ReferenceSystem)

Example 4 with ReferenceSystem

use of org.opengis.referencing.ReferenceSystem 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 ReferenceSystem

use of org.opengis.referencing.ReferenceSystem in project sis by apache.

the class Store method getMetadata.

/**
 * Returns the metadata associated to the parsed objects, or {@code null} if none.
 * The current implementation retains only instances of {@link ReferenceSystem}
 * and ignore other objects. The identification information {@code Citation} is
 * set to the CRS name and identifier, unless there is ambiguity.
 *
 * @return the metadata associated to the parsed object, or {@code null} if none.
 * @throws DataStoreException if an error occurred during the parsing process.
 */
@Override
public synchronized Metadata getMetadata() throws DataStoreException {
    if (metadata == null) {
        parse();
        final MetadataBuilder builder = new MetadataBuilder();
        String name = null;
        int count = 0;
        for (final Object object : objects) {
            if (object instanceof ReferenceSystem) {
                final ReferenceSystem rs = (ReferenceSystem) object;
                builder.addReferenceSystem(rs);
                name = IdentifiedObjects.getName(rs, null);
                count++;
                builder.addIdentifier(IdentifiedObjects.getIdentifier(rs, null), MetadataBuilder.Scope.RESOURCE);
            }
        }
        if (count == 1) {
            // Set the citation title only if non-ambiguous.
            builder.addTitle(name);
        } else {
            addTitleOrIdentifier(builder);
        }
        metadata = builder.build(true);
    }
    return metadata;
}
Also used : MetadataBuilder(org.apache.sis.internal.storage.MetadataBuilder) ReferenceSystem(org.opengis.referencing.ReferenceSystem)

Aggregations

ReferenceSystem (org.opengis.referencing.ReferenceSystem)8 Metadata (org.opengis.metadata.Metadata)3 DefaultIdentifier (org.apache.sis.metadata.iso.DefaultIdentifier)2 DefaultMetadata (org.apache.sis.metadata.iso.DefaultMetadata)2 Identifier (org.opengis.metadata.Identifier)2 IdentifiedObject (org.opengis.referencing.IdentifiedObject)2 CoordinateOperation (org.opengis.referencing.operation.CoordinateOperation)2 ReferenceSystemMetadata (org.apache.sis.internal.jaxb.metadata.replace.ReferenceSystemMetadata)1 DirectReferenceSystem (org.apache.sis.internal.profile.fra.DirectReferenceSystem)1 IndirectReferenceSystem (org.apache.sis.internal.profile.fra.IndirectReferenceSystem)1 SimpleExtent (org.apache.sis.internal.simple.SimpleExtent)1 MetadataBuilder (org.apache.sis.internal.storage.MetadataBuilder)1 ImmutableIdentifier (org.apache.sis.metadata.iso.ImmutableIdentifier)1 AbstractIdentifiedObject (org.apache.sis.referencing.AbstractIdentifiedObject)1 DataStore (org.apache.sis.storage.DataStore)1 ComparisonMode (org.apache.sis.util.ComparisonMode)1 Cache (org.apache.sis.util.collection.Cache)1 Test (org.junit.Test)1 Extent (org.opengis.metadata.extent.Extent)1 TemporalExtent (org.opengis.metadata.extent.TemporalExtent)1