Search in sources :

Example 1 with DefaultResolution

use of org.apache.sis.metadata.iso.identification.DefaultResolution in project geotoolkit by Geomatys.

the class ImageCoverageReader method getMetadata.

/**
 * Returns the ISO 19115 metadata object associated with the input source as a whole
 * and each coverages. The default implementation constructs the metadata from the
 * {@linkplain #getStreamMetadata() stream metadata} and the
 * {@linkplain #getCoverageMetadata(int) coverage metadata},
 * eventually completed by the {@link #getGridGeometry(int)}.
 * <p>
 * Since the relationship between Image I/O metadata and ISO 19115 is not always a
 * "<cite>one-to-one</cite>" relationship, this method works on a best effort basis.
 *
 * @return The ISO 19115 metadata (never {@code null}).
 * @throws CoverageStoreException If an error occurs while reading the information from the input source.
 *
 * @see <a href="../../image/io/metadata/SpatialMetadataFormat.html#default-formats">Metadata formats</a>
 *
 * @since 3.18
 */
public Metadata getMetadata() throws DataStoreException {
    final SpatialMetadata streamMetadata = getStreamMetadata();
    final DefaultMetadata metadata = createMetadata(streamMetadata);
    /*
         * Extract all information available from the stream metadata, provided that metadata
         * elements were not already provided by the above call to createMetadata(...). Since
         * createMetadata(...) typically get its information from the stream metadata as well,
         * we assume that creating here new objects from stream metadata would be redundant.
         */
    DataIdentification identification = null;
    if (streamMetadata != null) {
        final Collection<DataQuality> quality = metadata.getDataQualityInfo();
        if (quality.isEmpty()) {
            addIfNonNull(quality, streamMetadata.getInstanceForType(DataQuality.class));
        }
        final Collection<AcquisitionInformation> acquisition = metadata.getAcquisitionInformation();
        if (acquisition.isEmpty()) {
            addIfNonNull(acquisition, streamMetadata.getInstanceForType(AcquisitionInformation.class));
        }
        /*
             * Get the existing identification info if any, or create a new one otherwise.
             * If an identification info is found, remove it from the metadata (it will be
             * added back at the end of this method, or a copy of it will be added).
             */
        final Iterator<Identification> it = metadata.getIdentificationInfo().iterator();
        while (it.hasNext()) {
            final Identification candidate = it.next();
            if (candidate instanceof DataIdentification) {
                identification = (DataIdentification) candidate;
                it.remove();
                break;
            }
        }
        if (identification == null) {
            identification = streamMetadata.getInstanceForType(DataIdentification.class);
        }
    }
    /*
         * Check if we should complete the extents and resolutions. We will do so only
         * if the vertical/temporal extent, geographic bounding box and resolution are
         * not already provided in the metadata.  If the geographic extent is declared
         * by an other kind of object than GeographicBoundingBox, we will still add the
         * bounding box because the existing extent could be only a textual description.
         */
    // For logging warning only once.
    boolean failed = false;
    // 'false' if extents are already present.
    boolean computeExtents = true;
    // 'false' is resolutions are already present.
    boolean computeResolutions = true;
    // The extent to compute, if needed.
    DefaultExtent extent = null;
    // The extents already provided in the metadata.
    List<Extent> extents = null;
    // The resolutions to compute, if needed.
    Set<Resolution> resolutions = null;
    if (identification != null) {
        computeResolutions = isNullOrEmpty(identification.getSpatialResolutions());
        final Collection<? extends Extent> existings = identification.getExtents();
        if (!isNullOrEmpty(existings)) {
            extents = new ArrayList<>(existings);
            extent = UniqueExtents.getIncomplete(extents);
            if (extent == null) {
                // The plugin-provided Metadata instance seems to contain Extents
                // that are complete enough, so we will not try to complete them.
                computeExtents = false;
                extents = null;
            }
        }
    }
    /*
         * Check if we should complete the content info and the spatial representation info.
         * If the plugin-provided metadata declare explicitly such information, we will not
         * compute them in this method (the plugin information will have precedence).
         */
    final Collection<ContentInformation> contentInfo = metadata.getContentInfo();
    final Collection<SpatialRepresentation> spatialInfo = metadata.getSpatialRepresentationInfo();
    final boolean computeContent = (contentInfo != null) && contentInfo.isEmpty();
    final boolean computeSpatial = (spatialInfo != null) && spatialInfo.isEmpty();
    if (computeContent || computeSpatial || computeResolutions || computeExtents) {
        final GenericName coverageName = getCoverageName();
        if (computeContent || computeSpatial) {
            CoverageDescription ci = null;
            final SpatialMetadata coverageMetadata = getCoverageMetadata();
            if (coverageMetadata != null) {
                if (computeContent) {
                    ci = coverageMetadata.getInstanceForType(ImageDescription.class);
                    if (ci != null) {
                        contentInfo.add(ci);
                    }
                }
                if (computeSpatial) {
                    final Georectified rectified = coverageMetadata.getInstanceForType(Georectified.class);
                    if (rectified != null) {
                        metadata.getSpatialRepresentationInfo().add(rectified);
                    }
                }
            }
            /*
                 * Get or create the content info to store sample dimensions
                 */
            if (ci == null) {
                // get or create it
                if (contentInfo.size() > 0) {
                    CoverageDescription cd = contentInfo.stream().limit(1).filter(CoverageDescription.class::isInstance).map(CoverageDescription.class::cast).findFirst().orElse(null);
                    if (cd instanceof ModifiableMetadata && ((ModifiableMetadata) cd).state() != ModifiableMetadata.State.FINAL) {
                        ci = cd;
                    }
                } else {
                    ci = new DefaultCoverageDescription();
                    contentInfo.add(ci);
                }
            }
            if (ci != null && ci.getAttributeGroups() != null && ci.getAttributeGroups().isEmpty() && ci.getDimensions().isEmpty()) {
                final List<SampleDimension> sampleDimensions = getSampleDimensions();
                if (sampleDimensions != null) {
                    final MetadataBuilder mb = new MetadataBuilder();
                    for (int idx = 0, n = sampleDimensions.size(); idx < n; idx++) {
                        SampleDimension gsd = sampleDimensions.get(idx).forConvertedValues(true);
                        final Unit<? extends Quantity<?>> units = gsd.getUnits().orElse(null);
                        mb.newSampleDimension();
                        mb.setBandIdentifier(Names.createMemberName(null, null, "" + idx, Integer.class));
                        mb.addBandDescription(gsd.getName().toString());
                        if (units != null)
                            mb.setSampleUnits(units);
                        mb.addMinimumSampleValue(SampleDimensionUtils.getMinimumValue(gsd));
                        mb.addMaximumSampleValue(SampleDimensionUtils.getMaximumValue(gsd));
                        gsd = gsd.forConvertedValues(false);
                        gsd.getTransferFunctionFormula().ifPresent((f) -> {
                            mb.setTransferFunction(f.getScale(), f.getOffset());
                        });
                    }
                    final DefaultMetadata meta = mb.build();
                    final CoverageDescription imgDesc = (CoverageDescription) meta.getContentInfo().iterator().next();
                    ci.getAttributeGroups().addAll((Collection) imgDesc.getAttributeGroups());
                }
            }
        }
        if (computeResolutions || computeExtents) {
            /*
                 * Resolution along the horizontal axes only, ignoring all other axes. For linear units (feet,
                 * kilometres, etc.), we convert the units to metres for compliance with a current limitation
                 * of Apache SIS, which can handle only metres. For angular resolution (typically in degrees),
                 * we perform an APPROXIMATE conversion to metres using the nautical mile definition. This
                 * conversion is only valid along the latitudes axis (the number is wrong along the longitude
                 * axis), and more accurate for mid-latitude (the numbers are differents close to equator or
                 * to the poles).
                 */
            final GridGeometry gg = getGridGeometry();
            if (computeResolutions && gg.isDefined(GridGeometry.CRS)) {
                double[] res = null;
                try {
                    res = gg.getResolution(false);
                } catch (IncompleteGridGeometryException ex) {
                }
                final Quantity<?> m = CRSUtilities.getHorizontalResolution(gg.getCoordinateReferenceSystem(), res);
                if (m != null) {
                    double measureValue = m.getValue().doubleValue();
                    final Unit<?> unit = m.getUnit();
                    Unit<?> standardUnit = null;
                    double scaleFactor = 1;
                    if (Units.isAngular(unit)) {
                        standardUnit = Units.DEGREE;
                        // From definition of nautical miles.
                        scaleFactor = (1852 * 60);
                    } else if (Units.isLinear(unit)) {
                        standardUnit = Units.METRE;
                    }
                    if (standardUnit != null)
                        try {
                            measureValue = unit.getConverterToAny(standardUnit).convert(measureValue) * scaleFactor;
                            final DefaultResolution resolution = new DefaultResolution();
                            resolution.setDistance(measureValue);
                            if (resolutions == null) {
                                resolutions = new LinkedHashSet<>();
                            }
                            resolutions.add(resolution);
                        } catch (IncommensurableException e) {
                            // In case of failure, do not create a Resolution object.
                            Logging.recoverableException(LOGGER, ImageCoverageReader.class, "getMetadata", e);
                        }
                }
            }
            /*
                * Horizontal, vertical and temporal extents. The horizontal extents is
                * represented as a geographic bounding box, which may require a reprojection.
                */
            if (computeExtents && gg.isDefined(GridGeometry.ENVELOPE)) {
                if (extent == null) {
                    extent = new UniqueExtents();
                }
                try {
                    extent.addElements(gg.getEnvelope());
                } catch (TransformException e) {
                    // Not a big deal if we fail. We will just let the identification section unchanged.
                    if (!failed) {
                        // Log only once.
                        failed = true;
                        Logging.recoverableException(LOGGER, ImageCoverageReader.class, "getMetadata", e);
                    }
                }
            }
        }
    }
    /*
         * At this point, we have computed extents and resolutions from every images
         * in the stream. Now store the result. Note that we unconditionally create
         * a copy of the identification info, even if the original object was already
         * an instance of DefaultDataIdentification, because the original object may
         * be cached in the ImageReader.
         */
    if (extent != null || resolutions != null) {
        final DefaultDataIdentification copy = new DefaultDataIdentification(identification);
        if (extent != null) {
            if (extents != null) {
                copy.setExtents(extents);
            } else {
                copy.getExtents().add(extent);
            }
        }
        if (resolutions != null) {
            copy.setSpatialResolutions(resolutions);
        }
        identification = copy;
    }
    if (identification != null) {
        metadata.getIdentificationInfo().add(identification);
    }
    return metadata;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DataIdentification(org.opengis.metadata.identification.DataIdentification) DefaultDataIdentification(org.apache.sis.metadata.iso.identification.DefaultDataIdentification) DefaultExtent(org.apache.sis.metadata.iso.extent.DefaultExtent) Extent(org.opengis.metadata.extent.Extent) GridExtent(org.apache.sis.coverage.grid.GridExtent) IncommensurableException(javax.measure.IncommensurableException) SpatialRepresentation(org.opengis.metadata.spatial.SpatialRepresentation) CoverageDescription(org.opengis.metadata.content.CoverageDescription) DefaultCoverageDescription(org.apache.sis.metadata.iso.content.DefaultCoverageDescription) Identification(org.opengis.metadata.identification.Identification) DataIdentification(org.opengis.metadata.identification.DataIdentification) DefaultDataIdentification(org.apache.sis.metadata.iso.identification.DefaultDataIdentification) Georectified(org.opengis.metadata.spatial.Georectified) ModifiableMetadata(org.apache.sis.metadata.ModifiableMetadata) GenericName(org.opengis.util.GenericName) DefaultExtent(org.apache.sis.metadata.iso.extent.DefaultExtent) AcquisitionInformation(org.opengis.metadata.acquisition.AcquisitionInformation) DefaultCoverageDescription(org.apache.sis.metadata.iso.content.DefaultCoverageDescription) DefaultDataIdentification(org.apache.sis.metadata.iso.identification.DefaultDataIdentification) GridGeometry(org.apache.sis.coverage.grid.GridGeometry) SpatialMetadata(org.geotoolkit.image.io.metadata.SpatialMetadata) MetadataBuilder(org.apache.sis.internal.storage.MetadataBuilder) DefaultResolution(org.apache.sis.metadata.iso.identification.DefaultResolution) DataQuality(org.opengis.metadata.quality.DataQuality) DefaultMetadata(org.apache.sis.metadata.iso.DefaultMetadata) ContentInformation(org.opengis.metadata.content.ContentInformation) TransformException(org.opengis.referencing.operation.TransformException) SampleDimension(org.apache.sis.coverage.SampleDimension) ImageDescription(org.opengis.metadata.content.ImageDescription) IncompleteGridGeometryException(org.apache.sis.coverage.grid.IncompleteGridGeometryException) Resolution(org.opengis.metadata.identification.Resolution) DefaultResolution(org.apache.sis.metadata.iso.identification.DefaultResolution)

Example 2 with DefaultResolution

use of org.apache.sis.metadata.iso.identification.DefaultResolution in project geotoolkit by Geomatys.

the class DimapAccessor method fillMetadata.

/**
 * Converts the given dimap document in a metadata object.
 * Since there is no one to one relation between ISO 19115 and Dimap,
 * the returned metadata is a best effort relation.
 *
 * @param doc
 * @param metadata : metadata to fill, if null it will create one.
 * @return Metadata, never null
 */
public static DefaultMetadata fillMetadata(final Element doc, DefaultMetadata metadata) throws IOException {
    if (metadata == null) {
        metadata = new DefaultMetadata();
    } else {
        // To ensure we don't modify the original
        if (metadata instanceof MI_Metadata) {
            metadata = new MI_Metadata(metadata);
        } else {
            metadata = new DefaultMetadata(metadata);
        }
    }
    String thumbnail = null;
    String name = null;
    // Dimap_Document STRUCTURE
    // 
    // <Metadata_Id/>                    - Mandatory
    // <Dataset_Id/>                     - Mandatory
    // <Dataset_Frame/>                  - Optional
    // <Coordinate_Reference_System/>    - Mandatory
    // <Raster_CS/>                      - Mandatory
    // <Geoposition/>                    - Mandatory
    // <Production/>                     - Mandatory
    // <Quality_Assessment/>             - Optional
    // <Raster_Dimensions/>              - Mandatory
    // <Raster_Encoding/>                - Mandatory
    // <Data_Processing/>                - Mandatory
    // <Data_Access/>                    - Mandatory
    // <Image_Display/>                  - Mandatory
    // <Image_Interpretation/>           - Mandatory
    // <Dataset_Sources/>                - Mandatory
    // <Data_Strip/>                     - Mandatory
    // Default values
    metadata.setCharacterSets(Collections.singleton(StandardCharsets.UTF_8));
    metadata.setLanguage(Locale.ENGLISH);
    metadata.setDateStamp(new Date());
    // <xsd:element minOccurs="1" maxOccurs="1" ref="Dataset_Id"/> ----------
    final Element datasetID = firstElement(doc, TAG_DATASET_ID);
    if (datasetID != null) {
        // MAPPING
        // 
        // <DATASET_NAME/>       → used to build : MetaData.fileIdentifier
        // <DATASET_TN_PATH/>    → ?
        // <DATASET_TN_FORMAT/>  → ?
        // <DATASET_QL_PATH/>    → ?
        // <DATASET_QL_FORMAT/>  → ?
        // <COPYRIGHT/>          → MetaData.metadataConstraints > LegalConstraints.otherConstraints
        // → MetaData.identificationInfo > resourcesConstraints > LegalConstraints.otherConstraints
        final String copyright = textValueSafe(datasetID, TAG_DATASET_COPYRIGHT, String.class);
        thumbnail = textAttributeValueSafe(datasetID, TAG_DATASET_TN_PATH, ATTRIBUTE_HREF, String.class);
        name = textValueSafe(datasetID, TAG_DATASET_NAME, String.class);
        // MetaData > FileIdentifier
        metadata.setFileIdentifier(name.replaceAll(":", "_").replaceAll(" ", "_").replaceAll("/", "_"));
        // MetaData > MetadataConstraints
        final Restriction restriction = Restriction.COPYRIGHT;
        final DefaultLegalConstraints constraints = new DefaultLegalConstraints();
        constraints.setUseConstraints(Collections.singleton(restriction));
        constraints.setOtherConstraints(Collections.singleton(new SimpleInternationalString(copyright)));
        metadata.getMetadataConstraints().add(constraints);
        // duplicate ?
        final AbstractIdentification identification = getIdentificationInfo(metadata);
        identification.getResourceConstraints().add(constraints);
    }
    // <xsd:element minOccurs="0" maxOccurs="1" ref="Dataset_Frame"/> -------
    // Has been set from the geotiff informations
    final Element datasetFrame = firstElement(doc, TAG_DATASET_FRAME);
    if (datasetFrame != null) {
        if (metadata instanceof MI_Metadata) {
            Geometry geometry = null;
            try {
                geometry = readDatasetVertex(doc);
            } catch (NoSuchAuthorityCodeException ex) {
                throw new IOException("Exception when creating the bounding geometry : ", ex);
            } catch (FactoryException ex) {
                throw new IOException("Exception when creating the bounding geometry : ", ex);
            }
            // MetaData > DataIdentification > Extent > BoundingPolygon
            if (geometry != null) {
                final DefaultBoundingPolygon boundingPolygon = new DefaultBoundingPolygon();
                boundingPolygon.setPolygons(Collections.singleton(geometry));
                final DefaultGeographicDescription geographicDesc = new DefaultGeographicDescription();
                // not safe
                final Element gridReference = firstElement(doc, TAG_SCENE_GRID_REFERENCE);
                final String geographicId;
                if (gridReference != null) {
                    final String rawGeoId = gridReference.getTextContent();
                    geographicId = rawGeoId.substring(0, 3) + "-" + rawGeoId.substring(3);
                } else {
                    final String[] fileIdSplited = metadata.getFileIdentifier().split("-");
                    geographicId = fileIdSplited[0].substring(fileIdSplited[0].length() - 3) + "-" + fileIdSplited[1].substring(0, 3);
                }
                geographicDesc.setGeographicIdentifier(new DefaultIdentifier(geographicId));
                final DefaultExtent extent = getExtent(metadata);
                extent.getGeographicElements().add(boundingPolygon);
                extent.getGeographicElements().add(geographicDesc);
            }
        }
    }
    // <xsd:element minOccurs="1" maxOccurs="1"  ref="Production"/> ---------
    // Can be changed in a Responsible party information
    final Element production = firstElement(doc, TAG_PRODUCTION);
    if (production != null) {
        // MAPPING
        // 
        // <DATASET_PRODUCER_NAME/>      → MetaData.dataQualityInfo > DataQuality.lineage > Lineage.processSteps > ProcessStep.processors > ResponsibleParty.organisationName
        // <DATASET_PRODUCER_URL/>       → ?
        // <DATASET_PRODUCTION_DATE/>    → MetaData.dataQualityInfo > DataQuality.lineage > Lineage.processSteps > ProcessStep.date
        // <PRODUCT_TYPE/>               → ?
        // <PRODUCT_INFO/>               → MetaData.dataQualityInfo > DataQuality.lineage > Lineage.processSteps > ProcessStep.description
        // <JOB_ID/>                     → MetaData.dataQualityInfo > DataQuality.lineage > Lineage.processSteps > ProcessStep > Processing.identifier > Identifier.code
        // <Production_Facility>         Occurs : 1 to 1
        // <SOFTWARE_NAME/>          → MetaData.dataQualityInfo > DataQuality.lineage > Lineage.processSteps > ProcessStep.processingInfo > Processing.softwareReference > Citation.title
        // <SOFTWARE_VERSION/>       → MetaData.dataQualityInfo > DataQuality.lineage > Lineage.processSteps > ProcessStep.processingInfo > Processing.softwareReference > Citation.edition
        // <PROCESSING_CENTER/>      → MetaData.dataQualityInfo > DataQuality.lineage > Lineage.processSteps > ProcessStep.processingInfo > Processing.softwareReference > Citation.citedResponsibleParties > ResponsibleParty.organisationName
        // </Production_Facility>
        final String jobId = textValueSafe(production, TAG_JOB_ID, String.class);
        final String productType = textValueSafe(production, TAG_PRODUCT_TYPE, String.class);
        final String productInfo = textValueSafe(production, TAG_PRODUCT_INFO, String.class);
        final String producerName = textValueSafe(production, TAG_DATASET_PRODUCER_NAME, String.class);
        final Date productionDate = textValueSafe(production, TAG_DATASET_PRODUCTION_DATE, Date.class);
        final Element producerEle = firstElement(production, TAG_DATASET_PRODUCER_URL);
        URI producerURL = null;
        try {
            producerURL = new URI(producerEle.getAttribute(ATT_HREF));
        } catch (URISyntaxException ex) {
            LOGGER.log(Level.WARNING, ex.getLocalizedMessage(), ex);
        }
        final Element facility = firstElement(production, TAG_PRODUCTION_FACILITY);
        /**
         * Fills DataQualityInfo
         */
        // MetaData > DataQuality > Lineage > ProcessStep
        final DefaultResponsibleParty responsibleParty = new DefaultResponsibleParty(Role.ORIGINATOR);
        responsibleParty.setOrganisationName(new SimpleInternationalString(producerName));
        final DefaultProcessStep processStep = getProcessStep(metadata);
        processStep.setDescription(new SimpleInternationalString(productInfo));
        processStep.setDate(productionDate);
        processStep.getProcessors().add(responsibleParty);
        // MetaData > DataQuality > Lineage > ProcessStep > Processing > Identifier
        if (jobId != null) {
            final DefaultProcessing processing = getProcessingInfo(metadata);
            processing.setIdentifier(new DefaultIdentifier(jobId));
        }
        // MetaData > DataQuality > Lineage > ProcessStep > Processing > SoftwareReferences
        if (facility != null) {
            final String softwareName = textValueSafe(facility, TAG_PRODUCTION_FACILITY_SOFTWARE_NAME, String.class);
            final String softwareVersion = textValueSafe(facility, TAG_PRODUCTION_FACILITY_SOFTWARE_VERSION, String.class);
            final String productionCenter = textValueSafe(facility, TAG_PRODUCTION_FACILITY_PROCESSING_CENTER, String.class);
            final DefaultCitation softCitation = new DefaultCitation();
            softCitation.setTitle(new SimpleInternationalString(softwareName));
            softCitation.setEdition(new SimpleInternationalString(softwareVersion));
            if (productionCenter != null) {
                final DefaultResponsibleParty softResponsibleParty = new DefaultResponsibleParty();
                softResponsibleParty.setOrganisationName(new SimpleInternationalString(productionCenter));
                softCitation.getCitedResponsibleParties().add(softResponsibleParty);
            }
            final DefaultProcessing processing = getProcessingInfo(metadata);
            processing.getSoftwareReferences().add(softCitation);
        }
    }
    // <xsd:element minOccurs="1" maxOccurs="1"  ref="Raster_Dimensions"/> --
    // Has been set from the geotiff informations
    final Element rasterDim = firstElement(doc, TAG_RASTER_DIMENSIONS);
    if (rasterDim != null) {
        // MAPPING
        // 
        // <NCOLS/>  → MetaData.spatialRepresentationInfo > GridSpatialRepresentation.axisDimensionProperties > Dimension.dimensionSize
        // <NROWS/>  → MetaData.spatialRepresentationInfo > GridSpatialRepresentation.axisDimensionProperties > Dimension.dimensionSize
        // <NBANDS/> → ?
        final Integer ncols = textValueSafe(rasterDim, TAG_NCOLS, Integer.class);
        final Integer nrows = textValueSafe(rasterDim, TAG_NROWS, Integer.class);
        /**
         * Fills SpatialRepresentationInfo
         */
        // MetaData > GridSpatialRepresentation > Dimension
        final DefaultDimension rowDim = new DefaultDimension();
        rowDim.setDimensionSize(nrows);
        rowDim.setDimensionName(DimensionNameType.ROW);
        final DefaultDimension columnDim = new DefaultDimension();
        columnDim.setDimensionSize(ncols);
        columnDim.setDimensionName(DimensionNameType.COLUMN);
        final DefaultGridSpatialRepresentation gridSpacialRepr = (DefaultGridSpatialRepresentation) getSpatialRepresentationInfo(metadata);
        final List<Dimension> axisDimensions = gridSpacialRepr.getAxisDimensionProperties();
        axisDimensions.add(rowDim);
        axisDimensions.add(columnDim);
    }
    // <xsd:element minOccurs="1" maxOccurs="1"  ref="Data_Processing"/> ----
    final Element dataProcessing = firstElement(doc, TAG_DATA_PROCESSING);
    if (dataProcessing != null) {
        // MAPPING
        // 
        // <PROCESSING_LEVEL/>                   → ?
        // <GEOMETRIC_PROCESSING/>               → ?
        // <RADIOMETRIC_PROCESSING/>             → ?
        // <SPECTRAL_PROCESSING/>                → ?
        // <Processing_Options>                  Occurs : 1 to 1
        // <MEAN_RECTIFICATION_ELEVATION/>   → ?
        // <LINE_SHIFT/>                     → ?
        // <DECOMPRESSION_TYPE/>             → ?
        // <SWIR_BAND_REGISTRATION_FLAG/>    → ?
        // <X_BANDS_REGISTRATION_FLAG/>      → ?
        // <RESAMPLING_METHOD/>              → ?
        // <Dynamic_Stretch>                 Occurs : 0 to 1
        // <Thresholds>                  Occurs : 1 to n
        // <BAND_INDEX/>             → MetaData.contentInfo > ImageDescription.dimensions > Band.descriptor
        // <LOW_THRESHOLD/>          → MetaData.contentInfo > ImageDescription.dimensions > Band.minValue
        // <HIGH_THRESHOLD/>         → MetaData.contentInfo > ImageDescription.dimensions > Band.maxValue
        // </Thresholds>
        // <Dynamic_Stretch>
        // <Deconvolution>                   Occurs : 0 to 1
        // <LINE_SHIFT/>                 → ?
        // <DECOMPRESSION_TYPE/>         → ?
        // <Deconvolution>
        // <Sampling_Step>                   Occurs : 0 to 1
        // <SAMPLING_STEP_X/>            → ?
        // <SAMPLING_STEP_Y/>            → ?
        // <Sampling_Step>
        // <SuperMode_Processing>            Occurs : 0 to 1
        // <SM_CORRELATION_NEEDED/>      → ?
        // <SM_RAW_GRID_FILTERING/>      → ?
        // <SM_PROCESSING_TYPE/>         → ?
        // <SuperMode_Processing>
        // <Correction_Algorithm>            Occurs : 0 to n
        // <ALGORITHM_TYPE/>             → MetaData.dataQualityInfo > DataQuality.lineage > Lineage.processSteps > ProcessStep.processingInfo > Processing.algorithms > Algorithm.description
        // <ALGORITHM_NAME/>             → MetaData.dataQualityInfo > DataQuality.lineage > Lineage.processSteps > ProcessStep.processingInfo > Processing.algorithms > Algorithm.citation > Citation.title
        // <ALGORITHM_ACTIVATION/>       → ?
        // <Correction_Algorithm>
        // ...
        // </Processing_Options>
        // <Regions_Of_Interest>                 Occurs : 0 to 1
        // <Region_Of_Interest>              Occurs : 1 to n
        // <COL_MIN/>                    → ?
        // <ROW_MIN/>                    → ?
        // <COL_MAX/>                    → ?
        // <ROW_MAX/>                    → ?
        // </Region_Of_Interest>
        // ...
        // </Regions_Of_Interest>
        final String algoType = textValueSafe(dataProcessing, TAG_DATA_PROCESSING_ALGORITHM_TYPE, String.class);
        final String algoName = textValueSafe(dataProcessing, TAG_DATA_PROCESSING_ALGORITHM_NAME, String.class);
        final String processingLevel = textValueSafe(dataProcessing, TAG_DATA_PROCESSING_PROCESSING_LEVEL, String.class);
        // MetaData > DataQuality > Lineage > ProcessStep > Processing > Algorithm
        if (algoName != null && algoType != null) {
            final DefaultCitation citation = new DefaultCitation();
            citation.setTitle(new SimpleInternationalString(algoName));
            final DefaultAlgorithm algorithm = new DefaultAlgorithm();
            algorithm.setDescription(new SimpleInternationalString(algoType));
            algorithm.setCitation(citation);
            final DefaultProcessing processing = getProcessingInfo(metadata);
            processing.getAlgorithms().add(algorithm);
        }
        /**
         * Fills ContentInfo
         */
        // MetaData > ImageDescription > Dimension
        final Element processingOpts = firstElement(dataProcessing, TAG_PROCESSING_OPTIONS);
        if (processingOpts != null) {
            final Element dynamicStretch = firstElement(dataProcessing, TAG_DYNAMIC_STRETCH);
            if (dynamicStretch != null) {
                final List<Element> thresholds = getListElements(dynamicStretch, TAG_THRESHOLDS);
                for (int i = 0, len = thresholds.size(); i < len; i++) {
                    final Element threshold = (Element) thresholds.get(i);
                    final int bandIndex = textValueSafe(threshold, TAG_BAND_INDEX, Integer.class);
                    final Double lowThreshold = textValueSafe(threshold, TAG_LOW_THRESHOLD, Double.class);
                    final Double highThreshold = textValueSafe(threshold, TAG_HIGH_THRESHOLD, Double.class);
                    final DefaultNameFactory factory = new DefaultNameFactory();
                    final TypeName tname = factory.createTypeName(null, "BAND_INDEX");
                    final MemberName memberName = factory.createMemberName(null, String.valueOf(bandIndex), tname);
                    final DefaultBand dimension = getBandDimension(metadata, bandIndex);
                    dimension.setMinValue(lowThreshold);
                    dimension.setMaxValue(highThreshold);
                    dimension.setSequenceIdentifier(memberName);
                }
            }
        }
        // MetaData > ContentInfo (ImageDescription) > ProcessingLevelCode
        if (processingLevel != null) {
            final DefaultImageDescription contentInfo = (DefaultImageDescription) getContentInfo(metadata);
            contentInfo.setProcessingLevelCode(new DefaultIdentifier(processingLevel));
        }
    }
    // <xsd:element minOccurs="1" maxOccurs="1"  ref="Data_Access"/> --------
    final Element dataAccess = firstElement(doc, TAG_DATA_ACCESS);
    if (dataAccess != null) {
        // MAPPING
        // 
        // <DATA_FILE_FORMAT/>       → Metadata.identificationInfo > DataIdentification.resourceFormats > Format.name and Format.version
        // <DATA_FILE_FORMAT_DESC/>  → ?
        // <DATA_FILE_ORGANISATION/> → ?
        // <Data_File>               Occurs : 1 to 1
        // <DATA_FILE_PATH/>      → ?
        // </Data_File>
        final Element formatTag = firstElement(dataAccess, TAG_DATA_FILE_FORMAT);
        // MetaData > DataIdentification > Format
        if (formatTag != null) {
            final String version = formatTag.getAttribute(ATT_VERSION);
            final String formatName = formatTag.getTextContent();
            final DefaultFormat format = new DefaultFormat();
            format.setName(new SimpleInternationalString(formatName));
            format.setVersion(new SimpleInternationalString(version));
            final AbstractIdentification idf = getIdentificationInfo(metadata);
            idf.getResourceFormats().add(format);
        }
    }
    // <xsd:element minOccurs="1" maxOccurs="1" ref="Image_Interpretation"/>
    final Element imageInter = firstElement(doc, TAG_IMAGE_INTERPRETATION);
    if (imageInter != null) {
        // MAPPING
        // 
        // <Spectral_Band_Info>               Occurs : 1 to n
        // <BAND_INDEX/>                  → MetaData.contentInfo > ImageDescription.dimensions > Band.descriptor
        // <BAND_DESCRIPTION/>            → MetaData.contentInfo > ImageDescription.dimensions > Band.descriptor
        // <PHYSICAL_UNIT/>               → MetaData.contentInfo > ImageDescription.dimensions > Band.Units
        // <PHYSICAL_GAIN/>               → MetaData.contentInfo > ImageDescription.dimensions > Band.scaleFactor
        // <PHYSICAL_BIAS/>               → MetaData.contentInfo > ImageDescription.dimensions > Band.offset
        // <PHYSICAL_CALIBRATION_DATE/>   → ?
        // </Spectral_Band_Info>
        // ...
        /**
         * Fills ContentInfo
         */
        final List<Element> spectrals = getListElements(imageInter, TAG_SPECTRAL_BAND_INFO);
        if (spectrals != null) {
            final Element physicalUnitElem = firstElement(imageInter, TAG_PHYSICAL_UNIT);
            final int nbits = readNBits(doc);
            // MetaData > ImageDescription > Dimensions
            for (int i = 0, len = spectrals.size(); i < len; i++) {
                final Element spectre = (Element) spectrals.get(i);
                final int bandIndex = textValueSafe(spectre, TAG_BAND_INDEX, Integer.class);
                final String bandDesc = textValueSafe(spectre, TAG_BAND_DESCRIPTION, String.class);
                final Double physicalGain = textValueSafe(spectre, TAG_PHYSICAL_GAIN, Double.class);
                final Double physicalBias = textValueSafe(spectre, TAG_PHYSICAL_BIAS, Double.class);
                String physicalUnit = textValueSafe(spectre, TAG_PHYSICAL_UNIT, String.class);
                physicalUnit = physicalUnit.substring(physicalUnit.indexOf("(") + 1, physicalUnit.indexOf(")"));
                // final Unit unit = Units.valueOf(physicalUnit);
                final DefaultBand dimension = getBandDimension(metadata, bandIndex);
                dimension.setBitsPerValue(nbits);
                dimension.setDescriptor(new SimpleInternationalString(bandDesc));
                dimension.setScaleFactor(1 / physicalGain);
                dimension.setOffset(physicalBias);
            // dimension.setUnits(unit);
            }
        }
    }
    // <xsd:element minOccurs="1" maxOccurs="1" ref="Dataset_Sources"/> -----
    // Could be mapped to Aquisition informations
    final Element datasetSources = firstElement(doc, TAG_DATASET_SOURCES);
    if (datasetSources != null) {
        // MAPPING
        // 
        // <Source_Information>                      Occurs : 1 to 3
        // <SOURCE_ID/>                           → ?
        // <SOURCE_TYPE/>                         → ?
        // <SOURCE_DESCRIPTION/>                  → Metadata.identificationInfo > DataIdentification.abstract
        // <Source_Frame>                         Occurs : 0 to 1
        // <Vertex>                           Occurs : 4 to 4
        // <FRAME_LON/>                   → ?
        // <FRAME_LAT/>                   → ?
        // <FRAME_ROW/>                   → ?
        // <FRAME_COL/>                   → ?
        // <FRAME_X/>                     → ?
        // <FRAME_Y/>                     → ?
        // </Vertex>
        // ...
        // </Source_Frame>
        // <Scene_Source>                         Occurs : 0 to 1
        // <MISSION/>                         → MetaData.acquisitionInformation > AcquisitionInformation.operations > Operations.description
        // AND MetaData.acquisitionInformation > AcquisitionInformation.plateforms > Platform.identifier > Identifier.code
        // AND MetaData.acquisitionInformation > AcquisitionInformation.plateforms > Platform.Citation > Citation.title
        // AND MetaData.acquisitionInformation > AcquisitionInformation.plateforms > Platform.description
        // AND Metadata.identificationInfo > DataIdentification.abstract
        // AND Metadata.identificationInfo > DataIdentification.citation > Citation.title
        // 
        // <MISSION_INDEX/>                   → MetaData.acquisitionInformation > AcquisitionInformation.operations > Operations.identifier > Identifier.code
        // AND MetaData.acquisitionInformation > AcquisitionInformation.plateforms > Platform.identifier > Identifier.code
        // AND MetaData.acquisitionInformation > AcquisitionInformation.plateforms > Platform.description
        // AND Metadata.identificationInfo > DataIdentification.abstract
        // AND Metadata.identificationInfo > DataIdentification.citation > Citation.title
        // AND Metadata.identificationInfo > DataIdentification.spatialResolutions > Resolution.distance
        // 
        // <INSTRUMENT/>                      → MetaData.acquisitionInformation > AcquisitionInformation.instruments > Instrument.description
        // <INSTRUMENT_INDEX/>                → MetaData.acquisitionInformation > AcquisitionInformation.instruments > Instrument.identifier > Identifier.code
        // <SENSOR_CODE/>                     → Metadata.identificationInfo > DataIdentification.abstract
        // AND Metadata.identificationInfo > DataIdentification.resolution > Resolution.
        // 
        // <IMAGING_DATE/>                    → MetaData.identificationInfo > DataIdentification.citation > Citation.dates > CitationDate
        // <IMAGING_TIME/>                    → MetaData.identificationInfo > DataIdentification.citation > Citation.dates > CitationDate
        // <GRID_REFERENCE/>                  → ?
        // <SHIFT_VALUE/>                     → ?
        // <INCIDENCE_ANGLE/>                 → ?
        // <THEORETICAL_RESOLUTION/>          → ?
        // <SUN_AZIMUTH/>                     → MetaData.contentInfo > ImageDescription.processingLevelCode > Identifier.code
        // <SUN_ELEVATION/>                   → MetaData.contentInfo > ImageDescription.illuminationAzimuthAngle
        // <SCENE_PROCESSING_LEVEL/>          → MetaData.contentInfo > ImageDescription.illuminationElevationAngle
        // <VIEWING_ANGLE/>                   → ?
        // <Imaging_Parameters>               Occurs : 1 to 1
        // <REVOLUTION_NUMBER/>           → ?
        // <COMPRESSION_MODE/>            → ?
        // <DIRECT_PLAYBACK_INDICATOR/>   → ?
        // <REFOCUSING_STEP_NUM/>         → ?
        // <COUPLED_MODE_FLAG/>           → ?
        // <SWATH_MODE/>                  → ?
        // </Imaging_Parameters>
        // </Scene_Source>
        // <Quality_Assessment>                   Occurs : 0 to 1
        // <QUALITY_TABLES/>                  → ?
        // <Quality_Parameter>                Occurs : 1 to n
        // <QUALITY_PARAMETER_CODE/>      → ?
        // <QUALITY_PARAMETER_DESC/>      → ?
        // <QUALITY_PARAMETER_VALUE/>     → ?
        // </Quality_Parameter>
        // </Quality_Assessment>
        // </Source_Information>
        // ...
        final Element sourceInfo = firstElement(datasetSources, TAG_SOURCE_INFORMATION);
        if (sourceInfo != null) {
            final String sourceDesc = textValueSafe(sourceInfo, TAG_SOURCE_DESCRIPTION, String.class);
            final String sourceType = textValueSafe(sourceInfo, TAG_SOURCE_TYPE, String.class);
            /**
             * Fills IdentificationInfo, AcquisitionInfo and ContentInfo
             */
            final Element sceneSource = firstElement(sourceInfo, TAG_SCENE_SOURCE);
            if (sceneSource != null) {
                final String imagingDate = textValueSafe(sceneSource, TAG_SCENE_IMAGING_DATE, String.class);
                final String imagingTime = textValueSafe(sceneSource, TAG_SCENE_IMAGING_TIME, String.class);
                final String missionName = textValueSafe(sceneSource, TAG_SCENE_MISSION, String.class);
                final int missionIndex = textValueSafe(sceneSource, TAG_SCENE_MISSION_INDEX, Integer.class);
                final String instrumentName = textValueSafe(sceneSource, TAG_SCENE_INSTRUMENT, String.class);
                final int instrumentIndex = textValueSafe(sceneSource, TAG_SCENE_INSTRUMENT_INDEX, Integer.class);
                final String sensorCode = textValueSafe(sceneSource, TAG_SCENE_SENSOR_CODE, String.class);
                final Double incidenceAngle = textValueSafe(sceneSource, TAG_SCENE_INCIDENCE_ANGLE, Double.class);
                final Double theoreticalResolution = textValueSafe(sceneSource, TAG_SCENE_THEORETICAL_RESOLUTION, Double.class);
                final String viewingAngle = textValueSafe(sceneSource, TAG_SCENE_VIEWING_ANGLE, String.class);
                final Double sunAzimuth = textValueSafe(sceneSource, TAG_SCENE_SUN_AZIMUTH, Double.class);
                final Double sunElevation = textValueSafe(sceneSource, TAG_SCENE_SUN_ELEVATION, Double.class);
                /**
                 * Fills IdentificationInfo
                 */
                // MetaData > IdentificationInfo (DataIdentification) > GraphicOverviews
                final DefaultDataIdentification dataIdentification = (DefaultDataIdentification) getIdentificationInfo(metadata);
                if (thumbnail != null && thumbnail.contains(".")) {
                    dataIdentification.getGraphicOverviews().add(new DefaultBrowseGraphic(generateFileName(name, thumbnail.substring(thumbnail.lastIndexOf(".")))));
                }
                // MetaData > IdentificationInfo (DataIdentification) > supplementalInformation
                if (incidenceAngle != null) {
                    dataIdentification.setSupplementalInformation(new SimpleInternationalString(("incidence angle :" + incidenceAngle)));
                }
                // MetaData > IdentificationInfo (DataIdentification) > Abstract
                dataIdentification.setAbstract(new SimpleInternationalString(missionName + " " + missionIndex + " " + sourceDesc));
                // MetaData > IdentificationInfo (DataIdentification) > Citation
                final DefaultCitation citation = new DefaultCitation();
                final ISODateParser dateParser = new ISODateParser();
                final Date date = dateParser.parseToDate(imagingDate + "T" + imagingTime);
                citation.setDates(Collections.singleton(new DefaultCitationDate(date, DateType.CREATION)));
                citation.setTitle(new SimpleInternationalString(missionName + " " + missionIndex + " " + sourceType + " " + findTypeProduct(missionIndex, sensorCode)));
                dataIdentification.setCitation(citation);
                // MetaData > IdentificationInfo (DataIdentification) > Resolution
                final DefaultResolution resolution = new DefaultResolution();
                resolution.setDistance(findResolution(missionIndex, sensorCode));
                dataIdentification.setSpatialResolutions(Collections.singleton(resolution));
                /**
                 * Fills AcquisitionInfo
                 */
                final DefaultAcquisitionInformation acquisitionInfo = getAcquisitionInfo(metadata);
                // MetaData > AcquisitionInfo > Operations
                final DefaultOperation operation = new DefaultOperation();
                operation.setIdentifier(new DefaultIdentifier(String.valueOf(missionIndex)));
                operation.setDescription(new SimpleInternationalString(missionName));
                acquisitionInfo.getOperations().add(operation);
                // MetaData > AcquisitionInfo > Instruments
                final DefaultInstrument instrument = new DefaultInstrument();
                instrument.setIdentifier(new DefaultIdentifier(instrumentName + instrumentIndex));
                instrument.setDescription(new SimpleInternationalString(instrumentName));
                acquisitionInfo.getInstruments().add(instrument);
                // MetaData > AcquisitionInfo > Platforms
                final DefaultCitation platformCitation = new DefaultCitation();
                platformCitation.setTitle(new SimpleInternationalString(missionName));
                final DefaultPlatform platform = new DefaultPlatform();
                platform.setIdentifier(new DefaultIdentifier(missionName + missionIndex));
                platform.setCitation(platformCitation);
                platform.setDescription(new SimpleInternationalString(missionName + missionIndex));
                acquisitionInfo.getPlatforms().add(platform);
                /**
                 * Fills ContentInfo
                 */
                // MetaData > ContentInfo (ImageDescription) > IlluminationAzimuthAngle AND IlluminationElevationAngle
                final DefaultImageDescription contentInfo = (DefaultImageDescription) getContentInfo(metadata);
                contentInfo.setIlluminationAzimuthAngle(sunAzimuth);
                contentInfo.setIlluminationElevationAngle(sunElevation);
            }
        }
    }
    return metadata;
}
Also used : TypeName(org.opengis.util.TypeName) FactoryException(org.opengis.util.FactoryException) DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) AbstractIdentification(org.apache.sis.metadata.iso.identification.AbstractIdentification) DefaultProcessing(org.apache.sis.metadata.iso.lineage.DefaultProcessing) Element(org.w3c.dom.Element) DomUtilities.firstElement(org.geotoolkit.util.DomUtilities.firstElement) SimpleInternationalString(org.apache.sis.util.SimpleInternationalString) URISyntaxException(java.net.URISyntaxException) DefaultFormat(org.apache.sis.metadata.iso.distribution.DefaultFormat) URI(java.net.URI) DefaultBoundingPolygon(org.apache.sis.metadata.iso.extent.DefaultBoundingPolygon) DefaultLegalConstraints(org.apache.sis.metadata.iso.constraint.DefaultLegalConstraints) DefaultExtent(org.apache.sis.metadata.iso.extent.DefaultExtent) ISODateParser(org.geotoolkit.temporal.object.ISODateParser) DefaultAcquisitionInformation(org.apache.sis.metadata.iso.acquisition.DefaultAcquisitionInformation) DefaultOperation(org.apache.sis.metadata.iso.acquisition.DefaultOperation) DefaultNameFactory(org.apache.sis.util.iso.DefaultNameFactory) DefaultGridSpatialRepresentation(org.apache.sis.metadata.iso.spatial.DefaultGridSpatialRepresentation) DefaultDataIdentification(org.apache.sis.metadata.iso.identification.DefaultDataIdentification) DefaultIdentifier(org.apache.sis.metadata.iso.DefaultIdentifier) DefaultPlatform(org.apache.sis.metadata.iso.acquisition.DefaultPlatform) DefaultProcessStep(org.apache.sis.metadata.iso.lineage.DefaultProcessStep) NoSuchAuthorityCodeException(org.opengis.referencing.NoSuchAuthorityCodeException) DefaultResponsibleParty(org.apache.sis.metadata.iso.citation.DefaultResponsibleParty) DefaultBand(org.apache.sis.metadata.iso.content.DefaultBand) DefaultResolution(org.apache.sis.metadata.iso.identification.DefaultResolution) DefaultAlgorithm(org.apache.sis.metadata.iso.lineage.DefaultAlgorithm) DefaultMetadata(org.apache.sis.metadata.iso.DefaultMetadata) IOException(java.io.IOException) DefaultDimension(org.apache.sis.metadata.iso.spatial.DefaultDimension) SampleDimension(org.apache.sis.coverage.SampleDimension) Dimension(org.opengis.metadata.spatial.Dimension) RangeDimension(org.opengis.metadata.content.RangeDimension) Date(java.util.Date) DefaultCitationDate(org.apache.sis.metadata.iso.citation.DefaultCitationDate) DefaultGeographicDescription(org.apache.sis.metadata.iso.extent.DefaultGeographicDescription) Geometry(org.opengis.geometry.Geometry) Restriction(org.opengis.metadata.constraint.Restriction) DefaultDimension(org.apache.sis.metadata.iso.spatial.DefaultDimension) DefaultImageDescription(org.apache.sis.metadata.iso.content.DefaultImageDescription) SimpleInternationalString(org.apache.sis.util.SimpleInternationalString) MI_Metadata(org.apache.sis.internal.jaxb.gmi.MI_Metadata) MemberName(org.opengis.util.MemberName) DefaultBrowseGraphic(org.apache.sis.metadata.iso.identification.DefaultBrowseGraphic) DefaultCitationDate(org.apache.sis.metadata.iso.citation.DefaultCitationDate) DefaultInstrument(org.apache.sis.metadata.iso.acquisition.DefaultInstrument)

Example 3 with DefaultResolution

use of org.apache.sis.metadata.iso.identification.DefaultResolution in project sis by apache.

the class DefaultSource method setScaleDenominator.

/**
 * Sets the denominator of the representative fraction on a source map.
 * This method stores the value in the
 * {@linkplain #setSourceSpatialResolution(Resolution) source spatial resolution}.
 *
 * @param  newValue  the new scale denominator.
 *
 * @deprecated As of ISO 19115:2014, moved to {@link DefaultResolution#setEquivalentScale(RepresentativeFraction)}.
 */
@Deprecated
public void setScaleDenominator(final RepresentativeFraction newValue) {
    checkWritePermission(sourceSpatialResolution);
    Resolution resolution = null;
    if (newValue != null) {
        resolution = sourceSpatialResolution;
        if (resolution instanceof DefaultResolution) {
            ((DefaultResolution) resolution).setEquivalentScale(newValue);
        } else {
            resolution = new DefaultResolution(newValue);
        }
    }
    /*
         * Invoke the non-deprecated setter method only if the reference changed,
         * for consistency with other deprecated setter methods in metadata module.
         */
    if (resolution != sourceSpatialResolution) {
        setSourceSpatialResolution(resolution);
    }
}
Also used : DefaultResolution(org.apache.sis.metadata.iso.identification.DefaultResolution) Resolution(org.opengis.metadata.identification.Resolution) MD_Resolution(org.apache.sis.internal.jaxb.metadata.MD_Resolution) NominalResolution(org.opengis.metadata.lineage.NominalResolution) DefaultResolution(org.apache.sis.metadata.iso.identification.DefaultResolution)

Example 4 with DefaultResolution

use of org.apache.sis.metadata.iso.identification.DefaultResolution in project sis by apache.

the class MetadataBuilder method addResolution.

/**
 * Adds a linear resolution in metres.
 * Storage location is:
 *
 * <ul>
 *   <li>{@code metadata/identificationInfo/spatialResolution/distance}</li>
 * </ul>
 *
 * @param  distance  the resolution in metres, or {@code NaN} for no-operation.
 */
public final void addResolution(final double distance) {
    if (!Double.isNaN(distance)) {
        final DefaultResolution r = new DefaultResolution();
        r.setDistance(shared(distance));
        addIfNotPresent(identification().getSpatialResolutions(), r);
    }
}
Also used : DefaultResolution(org.apache.sis.metadata.iso.identification.DefaultResolution)

Example 5 with DefaultResolution

use of org.apache.sis.metadata.iso.identification.DefaultResolution in project geotoolkit by Geomatys.

the class LandsatMetadataParser method getMetadata.

/**
 * Returns Landsat ISO19115 metadatas.
 */
public final DefaultMetadata getMetadata(final LandsatConstants.CoverageGroup group) throws FactoryException, ParseException {
    ArgumentChecks.ensureNonNull("Metadata group name", group);
    if (isoMetadata == null) {
        // generate metadata
        final DefaultMetadata baseMetadata = new DefaultMetadata();
        assert metaGroups != null;
        // ----------------------------------------------------------------------//
        // ------------------------ Mandatory metadata --------------------------//
        // ----------------------------------------------------------------------//
        // -- set CRS
        baseMetadata.setReferenceSystemInfo(Collections.singleton(getCRS()));
        final Date metadataPublicationDate = getDateInfo();
        if (metadataPublicationDate != null)
            baseMetadata.setDateStamp(metadataPublicationDate);
        // -- unique file identifier
        baseMetadata.setFileIdentifier(UUID.randomUUID().toString());
        // -- Iso metadatas 19115 generation date.
        baseMetadata.setDateStamp(new Date());
        // -- set bounding box
        final double[] bbCoords = getProjectedBound2D();
        final DefaultGeographicBoundingBox geo = new // -- long
        DefaultGeographicBoundingBox(// -- long
        bbCoords[0], // -- long
        bbCoords[1], bbCoords[2], // -- lat
        bbCoords[3]);
        // -- geographic extent
        final DefaultExtent ex = new DefaultExtent();
        ex.setGeographicElements(Arrays.asList(geo));
        // -- acquisition date
        final DefaultTemporalExtent tex = new DefaultTemporalExtent();
        final Date acquisitionDate = getAcquisitionDate();
        tex.setBounds(acquisitionDate, acquisitionDate);
        ex.setTemporalElements(Arrays.asList(tex));
        // -- temporal extent
        final NamedIdentifier extentName = new NamedIdentifier(null, "Landsat extent");
        final Map<String, Object> propertiesExtent = new HashMap<>();
        propertiesExtent.put(IdentifiedObject.NAME_KEY, extentName);
        final NamedIdentifier extentBeginName = new NamedIdentifier(null, "Landsat extent");
        final Map<String, Object> propertiesBegin = new HashMap<>();
        propertiesBegin.put(IdentifiedObject.NAME_KEY, extentBeginName);
        final NamedIdentifier extentEnd = new NamedIdentifier(null, "Landsat extent");
        final Map<String, Object> propertiesEnd = new HashMap<>();
        propertiesEnd.put(IdentifiedObject.NAME_KEY, extentEnd);
        tex.setExtent(new DefaultPeriod(propertiesExtent, new DefaultInstant(propertiesBegin, acquisitionDate), new DefaultInstant(propertiesEnd, acquisitionDate)));
        // -- Resolution
        final String reres = getValue(false, RESOLUTION_LABEL + group);
        final Set<Resolution> res = new HashSet<>();
        if (reres != null) {
            final DefaultResolution defaultResolution = new DefaultResolution();
            defaultResolution.setDistance(Double.valueOf(reres));
            res.add(defaultResolution);
        }
        /**
         * Three different Images Descriptions.
         * - Reflective
         * - Panchromatic
         * - Thermal
         */
        // -- Reflective description.
        final DefaultImageDescription reflectiveImgDesc = new DefaultImageDescription();
        final DefaultAttributeGroup dAGReflectiveRef = new DefaultAttributeGroup();
        dAGReflectiveRef.setAttributes(getBandsInfos(CoverageGroup.REFLECTIVE, "REFLECTANCE"));
        final DefaultAttributeGroup dAGReflectiveRad = new DefaultAttributeGroup();
        dAGReflectiveRad.setAttributes(getBandsInfos(CoverageGroup.REFLECTIVE, "RADIANCE"));
        final Set<AttributeGroup> reflectiveInfos = new HashSet<>();
        reflectiveInfos.add(dAGReflectiveRef);
        reflectiveInfos.add(dAGReflectiveRad);
        reflectiveImgDesc.setAttributeGroups(reflectiveInfos);
        // -- Panchromatic image description.
        final DefaultImageDescription panchroImgDesc = new DefaultImageDescription();
        final DefaultAttributeGroup dAGPanchromaRef = new DefaultAttributeGroup();
        dAGPanchromaRef.setAttributes(getBandsInfos(CoverageGroup.PANCHROMATIC, "REFLECTANCE"));
        final DefaultAttributeGroup dAGPanchromaRad = new DefaultAttributeGroup();
        dAGPanchromaRad.setAttributes(getBandsInfos(CoverageGroup.PANCHROMATIC, "RADIANCE"));
        final Set<AttributeGroup> panchroInfos = new HashSet<>();
        panchroInfos.add(dAGPanchromaRef);
        panchroInfos.add(dAGPanchromaRad);
        panchroImgDesc.setAttributeGroups(panchroInfos);
        // -- Thermal descriptions. (only define with Radiance)
        final DefaultImageDescription thermalImgDesc = new DefaultImageDescription();
        final DefaultAttributeGroup dAGThermalRad = new DefaultAttributeGroup();
        dAGThermalRad.setAttributes(getBandsInfos(CoverageGroup.THERMAL, "RADIANCE"));
        thermalImgDesc.setAttributeGroups(Collections.singleton(dAGThermalRad));
        // -- image description
        final String cloud = getValue(false, "CLOUD_COVER");
        if (cloud != null) {
            final double val = Double.valueOf(cloud);
            reflectiveImgDesc.setCloudCoverPercentage(val);
            panchroImgDesc.setCloudCoverPercentage(val);
            thermalImgDesc.setCloudCoverPercentage(val);
        }
        final String sunAz = getValue(false, "SUN_AZIMUTH");
        if (sunAz != null) {
            final double val = Double.valueOf(sunAz);
            reflectiveImgDesc.setIlluminationAzimuthAngle(val);
            panchroImgDesc.setIlluminationAzimuthAngle(val);
            thermalImgDesc.setIlluminationAzimuthAngle(val);
        }
        final String sunEl = getValue(false, "SUN_ELEVATION");
        if (sunEl != null) {
            final double val = Double.valueOf(sunEl);
            reflectiveImgDesc.setIlluminationElevationAngle(val);
            panchroImgDesc.setIlluminationElevationAngle(val);
            thermalImgDesc.setIlluminationElevationAngle(val);
        }
        // ----------------------------------------------------------------------//
        // ------------------------- optional metadatas -------------------------//
        // ----------------------------------------------------------------------//
        // -- set metadata Date publication
        baseMetadata.setDateInfo(Collections.singleton(new DefaultCitationDate(metadataPublicationDate, DateType.PUBLICATION)));
        // -- Distribution informations
        final DefaultDistribution distribution = new DefaultDistribution();
        final String origin = getValue(false, "ORIGIN");
        if (origin != null)
            distribution.setDescription(new DefaultInternationalString(origin));
        final String outputFormat = getValue(false, "OUTPUT_FORMAT");
        final String processSoftVersion = getValue(false, "PROCESSING_SOFTWARE_VERSION");
        if ((outputFormat != null) && (processSoftVersion != null)) {
            DefaultFormat f = new DefaultFormat();
            f.setName(new SimpleInternationalString(outputFormat));
            f.setVersion(new SimpleInternationalString(processSoftVersion));
            distribution.setDistributionFormats(Collections.singleton(f));
        }
        baseMetadata.setDistributionInfo(Collections.singleton(distribution));
        // -- Aquisition informations
        final DefaultAcquisitionInformation dAI = new DefaultAcquisitionInformation();
        // -- platform
        final DefaultPlatform platform = new DefaultPlatform();
        final String platF = getValue(false, "SPACECRAFT_ID");
        if (platF != null) {
            platform.setCitation(new DefaultCitation());
        }
        // -- instrument
        final DefaultInstrument instru = new DefaultInstrument();
        final String instrum = getValue(false, "SENSOR_ID");
        if (instrum != null) {
            instru.setType(new DefaultInternationalString(instrum));
        }
        if (platF != null && instrum != null) {
            // -- set related founded instrument and platform
            // *****************************************************************//
            // -- a cycle is define here, platform -> instru and instru -> platform
            // -- like a dad know his son and a son know his dad.
            // -- during xml binding a cycle is not supported for the current Apach SIS version
            // -- decomment this row when upgrade SIS version
            // instru.setMountedOn(platform);
            // *****************************************************************//
            platform.setInstruments(Collections.singleton(instru));
            dAI.setPlatforms(Collections.singleton(platform));
            dAI.setInstruments(Collections.singleton(instru));
            baseMetadata.setAcquisitionInformation(Collections.singleton(dAI));
        }
        // build each specific metadata
        isoMetadata = new DefaultMetadata(baseMetadata);
        panchromaticMetadatas = new DefaultMetadata(baseMetadata);
        reflectiveMetadatas = new DefaultMetadata(baseMetadata);
        thermalMetadatas = new DefaultMetadata(baseMetadata);
        // -- all minimum mandatory metadatas.
        // -- comment about data
        final InternationalString abstractComment = new DefaultInternationalString(getValue(true, "ORIGIN"));
        // -- dates
        final Set<DefaultCitationDate> dateset = new HashSet<>();
        dateset.add(new DefaultCitationDate(acquisitionDate, DateType.CREATION));
        dateset.add(new DefaultCitationDate(metadataPublicationDate, DateType.PUBLICATION));
        {
            // general metadata
            final NamedIdentifier identifier = CoverageGroup.ALL.createName(getValue(false, LandsatConstants.SCENE_ID));
            final DefaultCitation titleCitation = new DefaultCitation(identifier.toString());
            titleCitation.setIdentifiers(Collections.singleton(identifier));
            titleCitation.setDates(dateset);
            final DefaultDataIdentification ddii = new DefaultDataIdentification();
            ddii.setExtents(Arrays.asList(ex));
            ddii.setAbstract(abstractComment);
            ddii.setCitation(titleCitation);
            isoMetadata.setIdentificationInfo(Arrays.asList(ddii));
        }
        {
            // panchromatic
            final NamedIdentifier identifier = CoverageGroup.PANCHROMATIC.createName(getValue(false, LandsatConstants.SCENE_ID));
            final DefaultCitation titleCitation = new DefaultCitation(identifier.toString());
            titleCitation.setIdentifiers(Collections.singleton(identifier));
            titleCitation.setDates(dateset);
            final DefaultDataIdentification ddii = new DefaultDataIdentification();
            ddii.setExtents(Arrays.asList(ex));
            ddii.setAbstract(abstractComment);
            ddii.setCitation(titleCitation);
            ddii.setSpatialResolutions(res);
            panchromaticMetadatas.setIdentificationInfo(Arrays.asList(ddii));
            panchromaticMetadatas.setContentInfo(Arrays.asList(panchroImgDesc));
        }
        {
            // reflective
            final NamedIdentifier identifier = CoverageGroup.REFLECTIVE.createName(getValue(false, LandsatConstants.SCENE_ID));
            final DefaultCitation titleCitation = new DefaultCitation(identifier.toString());
            titleCitation.setIdentifiers(Collections.singleton(identifier));
            titleCitation.setDates(dateset);
            final DefaultDataIdentification ddii = new DefaultDataIdentification();
            ddii.setExtents(Arrays.asList(ex));
            ddii.setAbstract(abstractComment);
            ddii.setCitation(titleCitation);
            ddii.setSpatialResolutions(res);
            reflectiveMetadatas.setIdentificationInfo(Arrays.asList(ddii));
            reflectiveMetadatas.setContentInfo(Arrays.asList(reflectiveImgDesc));
        }
        {
            // thermal
            final NamedIdentifier identifier = CoverageGroup.THERMAL.createName(getValue(false, LandsatConstants.SCENE_ID));
            final DefaultCitation titleCitation = new DefaultCitation(identifier.toString());
            titleCitation.setIdentifiers(Collections.singleton(identifier));
            titleCitation.setDates(dateset);
            final DefaultDataIdentification ddii = new DefaultDataIdentification();
            ddii.setExtents(Arrays.asList(ex));
            ddii.setAbstract(abstractComment);
            ddii.setCitation(titleCitation);
            ddii.setSpatialResolutions(res);
            thermalMetadatas.setIdentificationInfo(Arrays.asList(ddii));
            thermalMetadatas.setContentInfo(Arrays.asList(thermalImgDesc));
            final Set<ProcessStep> extendedInfos = getThermicInfos();
            if (!extendedInfos.isEmpty()) {
                final DefaultLineage defaultLineage = new DefaultLineage();
                defaultLineage.setProcessSteps(extendedInfos);
                thermalMetadatas.setResourceLineages(Collections.singleton(defaultLineage));
            }
        }
    }
    switch(group) {
        case ALL:
            return isoMetadata;
        case PANCHROMATIC:
            return panchromaticMetadatas;
        case REFLECTIVE:
            return reflectiveMetadatas;
        case THERMAL:
            return thermalMetadatas;
        default:
            throw new IllegalArgumentException("Unknown coverage " + group);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) DefaultInternationalString(org.apache.sis.util.DefaultInternationalString) SimpleInternationalString(org.apache.sis.util.SimpleInternationalString) InternationalString(org.opengis.util.InternationalString) DefaultInternationalString(org.apache.sis.util.DefaultInternationalString) DefaultDistribution(org.apache.sis.metadata.iso.distribution.DefaultDistribution) DefaultAttributeGroup(org.apache.sis.metadata.iso.content.DefaultAttributeGroup) DefaultFormat(org.apache.sis.metadata.iso.distribution.DefaultFormat) DefaultExtent(org.apache.sis.metadata.iso.extent.DefaultExtent) DefaultAcquisitionInformation(org.apache.sis.metadata.iso.acquisition.DefaultAcquisitionInformation) NamedIdentifier(org.apache.sis.referencing.NamedIdentifier) DefaultTemporalExtent(org.apache.sis.metadata.iso.extent.DefaultTemporalExtent) DefaultDataIdentification(org.apache.sis.metadata.iso.identification.DefaultDataIdentification) DefaultPlatform(org.apache.sis.metadata.iso.acquisition.DefaultPlatform) HashSet(java.util.HashSet) DefaultResolution(org.apache.sis.metadata.iso.identification.DefaultResolution) DefaultMetadata(org.apache.sis.metadata.iso.DefaultMetadata) AttributeGroup(org.opengis.metadata.content.AttributeGroup) DefaultAttributeGroup(org.apache.sis.metadata.iso.content.DefaultAttributeGroup) DefaultInstant(org.geotoolkit.temporal.object.DefaultInstant) DefaultLineage(org.apache.sis.metadata.iso.lineage.DefaultLineage) Date(java.util.Date) DefaultCitationDate(org.apache.sis.metadata.iso.citation.DefaultCitationDate) DefaultImageDescription(org.apache.sis.metadata.iso.content.DefaultImageDescription) DefaultGeographicBoundingBox(org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox) DefaultPeriod(org.geotoolkit.temporal.object.DefaultPeriod) SimpleInternationalString(org.apache.sis.util.SimpleInternationalString) SimpleInternationalString(org.apache.sis.util.SimpleInternationalString) InternationalString(org.opengis.util.InternationalString) DefaultInternationalString(org.apache.sis.util.DefaultInternationalString) IdentifiedObject(org.opengis.referencing.IdentifiedObject) DefaultCitationDate(org.apache.sis.metadata.iso.citation.DefaultCitationDate) DefaultInstrument(org.apache.sis.metadata.iso.acquisition.DefaultInstrument) Resolution(org.opengis.metadata.identification.Resolution) DefaultResolution(org.apache.sis.metadata.iso.identification.DefaultResolution)

Aggregations

DefaultResolution (org.apache.sis.metadata.iso.identification.DefaultResolution)5 DefaultMetadata (org.apache.sis.metadata.iso.DefaultMetadata)3 DefaultExtent (org.apache.sis.metadata.iso.extent.DefaultExtent)3 DefaultDataIdentification (org.apache.sis.metadata.iso.identification.DefaultDataIdentification)3 Resolution (org.opengis.metadata.identification.Resolution)3 Date (java.util.Date)2 SampleDimension (org.apache.sis.coverage.SampleDimension)2 DefaultAcquisitionInformation (org.apache.sis.metadata.iso.acquisition.DefaultAcquisitionInformation)2 DefaultInstrument (org.apache.sis.metadata.iso.acquisition.DefaultInstrument)2 DefaultPlatform (org.apache.sis.metadata.iso.acquisition.DefaultPlatform)2 DefaultCitation (org.apache.sis.metadata.iso.citation.DefaultCitation)2 DefaultCitationDate (org.apache.sis.metadata.iso.citation.DefaultCitationDate)2 DefaultImageDescription (org.apache.sis.metadata.iso.content.DefaultImageDescription)2 DefaultFormat (org.apache.sis.metadata.iso.distribution.DefaultFormat)2 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1