Search in sources :

Example 1 with DefaultRangeDimension

use of org.apache.sis.metadata.iso.content.DefaultRangeDimension in project geotoolkit by Geomatys.

the class CBERS method toMetadata.

/**
 * Extract as much information as possible from CBERS metadata and map it to
 * ISO 19115-2.
 *
 * @param cbersData Metadata
 * @return ISO19115 Metadata
 */
public static Metadata toMetadata(Path cbersData) throws ParserConfigurationException, IOException, SAXException {
    final DefaultMetadata metadata = new DefaultMetadata();
    // Initialisation of DOM document.
    Document doc = DomUtilities.read(cbersData);
    // ////////////////////////////////
    // Data initialisation      //
    // ////////////////////////////////
    // Dom
    final Element root = doc.getDocumentElement();
    Element tmp = null;
    final Element img = DomUtilities.firstElement(doc.getDocumentElement(), "image");
    // metadata
    final DefaultDataIdentification identificationInfo = new DefaultDataIdentification();
    final DefaultGeorectified spatialRep = new DefaultGeorectified();
    final DefaultCitation citation = new DefaultCitation();
    final DefaultResponsibleParty responsibleParty = new DefaultResponsibleParty();
    final DefaultImageDescription contentInfo = new DefaultImageDescription();
    final DefaultDataQuality qualityInfo = new DefaultDataQuality();
    final DefaultLineage lineage = new DefaultLineage();
    final DefaultProcessStep processStep = new DefaultProcessStep();
    final DefaultProcessing processInfo = new DefaultProcessing();
    final DefaultCitation softwareReference = new DefaultCitation();
    final DefaultResponsibleParty processor = new DefaultResponsibleParty();
    final DefaultAcquisitionInformation acquisitionInfo = new DefaultAcquisitionInformation();
    final DefaultInstrument instrument = new DefaultInstrument();
    final DefaultPlatform platform = new DefaultPlatform();
    DefaultMetadata isoData = new DefaultMetadata();
    metadata.getSpatialRepresentationInfo().add(spatialRep);
    metadata.getIdentificationInfo().add(identificationInfo);
    metadata.getDataQualityInfo().add(qualityInfo);
    metadata.getAcquisitionInformation().add(acquisitionInfo);
    qualityInfo.setLineage(lineage);
    lineage.getProcessSteps().add(processStep);
    identificationInfo.setCitation(citation);
    identificationInfo.getPointOfContacts().add(responsibleParty);
    processInfo.getSoftwareReferences().add(softwareReference);
    processStep.setProcessingInformation(processInfo);
    acquisitionInfo.getInstruments().add(instrument);
    acquisitionInfo.getPlatforms().add(platform);
    platform.setCitation(new DefaultCitation("CBERS"));
    // other
    final ISODateParser fp = new ISODateParser();
    // /////////////////////////////////////
    // STEP LISTING            //
    // /////////////////////////////////////
    /**
     * The following comments describe how to fill ISO 19115 metadata from
     * CBERS xml elements. Syntax is : ISO 19115 xml tag to set : CBERS
     * element or default value to use.
     */
    // MI_Metadata/fileIdentifier : FileName
    String fileName = cbersData.getFileName().toString();
    fileName = fileName.substring(0, fileName.lastIndexOf('.'));
    isoData.setFileIdentifier(fileName);
    // MI_Metadata/language : (default value) english
    isoData.setLanguage(Locale.ENGLISH);
    // MI_Metadata/characterSet : (default value) utf8
    isoData.setCharacterSets(Collections.singleton(StandardCharsets.UTF_8));
    // MI_Metadata/dateStamp : get current date
    isoData.setDateStamp(new Date());
    // MI_Metadata/contact/role : (defaultValue) ??
    // MI_Metadata/contact/organisationName :(defaultValue) AGEOS (IRD ???)
    // MI_Metadata/contact/electronicMailAdress : (defaultValue) Institutional e-mail of AGEOS (IRD ??)
    // MI_Metadata/SpatialRepresentationInfo/numberOfDimensions : (defaultValue) 2
    spatialRep.setNumberOfDimensions(2);
    // MI_Metadata/spatialRepresentationInfo/axisDimensionProperties/dimensionName : (defaultValue) row
    final List<Dimension> dims = new ArrayList<Dimension>(2);
    final DefaultDimension dim1 = new DefaultDimension();
    dim1.setDimensionName(DimensionNameType.ROW);
    dims.add(dim1);
    // MI_Metadata/spatialRepresentationInfo/axisDimensionProperties/dimensionName : (defaultValue) column
    final DefaultDimension dim2 = new DefaultDimension();
    dim2.setDimensionName(DimensionNameType.COLUMN);
    dims.add(dim2);
    spatialRep.setAxisDimensionProperties(dims);
    // MI_Metadata/spatialRepresentationInfo/cellGeometry : GeoKeyDirectory.GTRasterTypeGeoKey
    // spatialRep.setCellGeometry(CellGeometry.POINT);
    // MI_Metadata/spatialRepresentationInfo/transformationParameterAvailability : (defaultValue) FALSE
    spatialRep.setTransformationParameterAvailable(false);
    // MI_Metadata/spatialRepresentationInfo/checkPointAvailability : (defaultValue) FALSE
    spatialRep.asMap().put("checkPointAvailability", false);
    isoData.getSpatialRepresentationInfo().add(spatialRep);
    // MI_Metadata/identificationInfo/citation/date/dateType : (defaulValue) Creation
    if (img != null) {
        tmp = DomUtilities.firstElement(img, "timeStamp");
        if (tmp != null) {
            tmp = DomUtilities.firstElement(tmp, "center");
            if (tmp != null) {
                Date centerDate = fp.parseToDate(tmp.getTextContent());
                DefaultCitationDate cDate = new DefaultCitationDate(centerDate, DateType.CREATION);
                citation.getDates().add(cDate);
            }
        }
    }
    // MI_Metadata/identificationInfo/citedResponsibleParty/role : (defaultValue) Originator
    responsibleParty.setRole(Role.ORIGINATOR);
    // MI_Metadata/identificationInfo/resourceConstraints/useConstraints : (defaultValue) otherConstraints
    final Constraints constraint = new DefaultLegalConstraints("otherConstraints");
    identificationInfo.getResourceConstraints().add(constraint);
    // MI_Metadata/identificationInfo/ topicCategory : (defaultValue) imageryBaseMapsEarthCover
    final TopicCategory category = TopicCategory.IMAGERY_BASE_MAPS_EARTH_COVER;
    identificationInfo.getTopicCategories().add(category);
    // MI_Metadata/identificationInfo/extent/geographicElement/geographicIdentifier/code : image/path, image/row
    if (img != null) {
        Element path = DomUtilities.firstElement(img, "path");
        Element row = DomUtilities.firstElement(img, "row");
        if (path != null && row != null) {
            String code = path.getTextContent() + '-' + row.getTextContent();
            DefaultExtent extent = new DefaultExtent();
            extent.getIdentifiers().add(new DefaultIdentifier(code));
            identificationInfo.getExtents().add(extent);
        }
    }
    // MI_Metadata/contentInfo/ attributeDescription : (defaultValue) equivalent radiance (W.m-2.Sr-1.um-1)
    // TODO : not supported
    // MI_Metadata/contentInfo/contentType : (defaultValue) image
    contentInfo.setContentType(CoverageContentType.IMAGE);
    if (img != null) {
        final Element sun = DomUtilities.firstElement(img, "sunPosition");
        if (sun != null) {
            // MI_Metadata/contentInfo/illuminationElevationAngle : image/sunPosition/elevation
            tmp = DomUtilities.firstElement(sun, "elevation");
            if (tmp != null) {
                contentInfo.setIlluminationElevationAngle(Double.valueOf(tmp.getTextContent()));
            }
            // MI_Metadata/contentInfo/illuminationAzimuthAngle : image/sunPosition/sunAzimuth
            tmp = DomUtilities.firstElement(sun, "sunAzimuth");
            if (tmp != null) {
                contentInfo.setIlluminationAzimuthAngle(Double.valueOf(tmp.getTextContent()));
            }
        }
        // MI_Metadata/contentInfo/processingLevelCode/code : image/level
        tmp = DomUtilities.firstElement(img, "level");
        if (tmp != null) {
            contentInfo.setProcessingLevelCode(new DefaultIdentifier(tmp.getTextContent()));
        }
    }
    // contentInfo/dimension/sequenceIdentifier : get BANDx string
    // contentInfo/dimension/descriptor : (defaultValue) BAND1
    final int start = fileName.lastIndexOf("BAND");
    final String band = fileName.substring(start, start + 5);
    final int bandNum = Integer.valueOf(band.substring(band.length() - 1));
    DefaultRangeDimension dim = new DefaultRangeDimension();
    // TODO : set sequence identifier
    dim.setDescriptor(new SimpleInternationalString(band));
    contentInfo.getDimensions().add(dim);
    // contentInfo/dimension/units : (defaultValue) W.m-2.Sr-1.um-1
    // TODO : No equivalent for default value.
    // dataQualityInfo/scope : (defaultValue) dataset
    qualityInfo.setScope(new DefaultScope(ScopeCode.DATASET));
    // dataQualityInfo/lineage/processStep/description: (defaultValue) CBERS LEVEL 2 PRODUCT
    processStep.setDescription(new SimpleInternationalString("CBERS LEVEL 2 PRODUCT"));
    if (img != null) {
        // dataQualityInfo/lineage/processStep/dateTime : image/processingTime
        tmp = DomUtilities.firstElement(img, "processingTime");
        if (tmp != null) {
            final Date resultDate = fp.parseToDate(tmp.getTextContent());
            processStep.setDate(resultDate);
        }
        // dataQualityInfo/lineage/processStep/processor/OrganisationName : image/processingStation
        tmp = DomUtilities.firstElement(img, "processingStation");
        if (tmp != null) {
            processor.setOrganisationName(new SimpleInternationalString(tmp.getTextContent()));
        }
    }
    // dataQualityInfo/lineage/processStep/processor/role : (defaultValue) processor
    processor.setRole(Role.PROCESSOR);
    // dataQualityInfo/lineage/processStep/ processingInformation/softwareReference/title : software
    // dataQualityInfo/lineage/processStep/ processingInformation/softwareReference/edition : version
    tmp = DomUtilities.firstElement(root, "software");
    if (tmp != null) {
        softwareReference.setTitle(new SimpleInternationalString(tmp.getTextContent()));
    }
    if (tmp != null) {
        tmp = DomUtilities.firstElement(root, "version");
    }
    softwareReference.setEdition(new SimpleInternationalString(tmp.getTextContent()));
    // dataQualityInfo/lineage/processStep/ processingInformation/softwareReference/date/date : (defaultValue) NilReason="missing"
    // dataQualityInfo/lineage/processStep/processingInformation/ algorithm/date/date/dateType : (defaultValue) creation
    // TODO : No equivalent for "missing" tag.
    // dataQualityInfo/lineage/processStep/processingInformation/algorithm/description : algorithm/description
    DefaultAlgorithm algo = new DefaultAlgorithm();
    tmp = DomUtilities.firstElement(root, "algorithm");
    if (tmp != null) {
        tmp = DomUtilities.firstElement(tmp, "description");
        if (tmp != null) {
            algo.setDescription(new SimpleInternationalString(tmp.getTextContent()));
        }
    }
    // acquisitionInformation/instrument/type : (defaultValue) Push-broom
    instrument.setType(new SimpleInternationalString("Push-broom"));
    Element sat = DomUtilities.firstElement(root, "Satellite");
    if (sat != null) {
        String platformId = null;
        String cTitle = null;
        tmp = DomUtilities.firstElement(sat, "instrument");
        if (tmp != null) {
            // acquisitionInformation/instrument/identifier : Satellite/instrument
            final String instrumentId = tmp.getTextContent();
            instrument.setIdentifier(new DefaultIdentifier(instrumentId));
            // MI_Metadata/identificationInfo/citation/title : concatenate acquisitionInformation/instrument/identifier and (if id is CCD) PAN or REF
            cTitle = instrumentId;
            if (cTitle.equals("CCD")) {
                if (bandNum < 5) {
                    cTitle += "REF";
                } else {
                    cTitle += "PAN";
                }
            }
            citation.setTitle(new SimpleInternationalString(cTitle));
        }
        final Element name = DomUtilities.firstElement(sat, "name");
        final Element number = DomUtilities.firstElement(sat, "number");
        if (name != null && number != null) {
            // acquisitionInformation/plateform/identifier : Concatenate {Satellite/name} and {Satellite/number}
            // acquisitionInformation/plateform/description : (defaultValue) CBERS_2B
            platformId = name.getTextContent() + '_' + number.getTextContent();
            platform.setIdentifier(new DefaultIdentifier(platformId));
            platform.setDescription(new SimpleInternationalString(platformId));
        }
        if (platformId != null && cTitle != null) {
            // MI_Metadata/IdentificationInfo/abstract : concatenate acquisitionInformation/platform/identifier and identificationInfo/citation/title
            identificationInfo.setAbstract(new SimpleInternationalString(platformId + ' ' + cTitle));
        }
    }
    return metadata;
}
Also used : DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) DefaultProcessing(org.apache.sis.metadata.iso.lineage.DefaultProcessing) DefaultRangeDimension(org.apache.sis.metadata.iso.content.DefaultRangeDimension) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) SimpleInternationalString(org.apache.sis.util.SimpleInternationalString) Document(org.w3c.dom.Document) DefaultDataQuality(org.apache.sis.metadata.iso.quality.DefaultDataQuality) DefaultLegalConstraints(org.apache.sis.metadata.iso.constraint.DefaultLegalConstraints) ISODateParser(org.geotoolkit.temporal.object.ISODateParser) DefaultExtent(org.apache.sis.metadata.iso.extent.DefaultExtent) DefaultAcquisitionInformation(org.apache.sis.metadata.iso.acquisition.DefaultAcquisitionInformation) 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) DefaultGeorectified(org.apache.sis.metadata.iso.spatial.DefaultGeorectified) DefaultResponsibleParty(org.apache.sis.metadata.iso.citation.DefaultResponsibleParty) DefaultAlgorithm(org.apache.sis.metadata.iso.lineage.DefaultAlgorithm) DefaultMetadata(org.apache.sis.metadata.iso.DefaultMetadata) DefaultDimension(org.apache.sis.metadata.iso.spatial.DefaultDimension) Dimension(org.opengis.metadata.spatial.Dimension) DefaultRangeDimension(org.apache.sis.metadata.iso.content.DefaultRangeDimension) TopicCategory(org.opengis.metadata.identification.TopicCategory) DefaultScope(org.apache.sis.metadata.iso.quality.DefaultScope) DefaultLineage(org.apache.sis.metadata.iso.lineage.DefaultLineage) Date(java.util.Date) DefaultCitationDate(org.apache.sis.metadata.iso.citation.DefaultCitationDate) DefaultDimension(org.apache.sis.metadata.iso.spatial.DefaultDimension) DefaultImageDescription(org.apache.sis.metadata.iso.content.DefaultImageDescription) Constraints(org.opengis.metadata.constraint.Constraints) DefaultLegalConstraints(org.apache.sis.metadata.iso.constraint.DefaultLegalConstraints) SimpleInternationalString(org.apache.sis.util.SimpleInternationalString) DefaultInstrument(org.apache.sis.metadata.iso.acquisition.DefaultInstrument) DefaultCitationDate(org.apache.sis.metadata.iso.citation.DefaultCitationDate)

Aggregations

ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 DefaultIdentifier (org.apache.sis.metadata.iso.DefaultIdentifier)1 DefaultMetadata (org.apache.sis.metadata.iso.DefaultMetadata)1 DefaultAcquisitionInformation (org.apache.sis.metadata.iso.acquisition.DefaultAcquisitionInformation)1 DefaultInstrument (org.apache.sis.metadata.iso.acquisition.DefaultInstrument)1 DefaultPlatform (org.apache.sis.metadata.iso.acquisition.DefaultPlatform)1 DefaultCitation (org.apache.sis.metadata.iso.citation.DefaultCitation)1 DefaultCitationDate (org.apache.sis.metadata.iso.citation.DefaultCitationDate)1 DefaultResponsibleParty (org.apache.sis.metadata.iso.citation.DefaultResponsibleParty)1 DefaultLegalConstraints (org.apache.sis.metadata.iso.constraint.DefaultLegalConstraints)1 DefaultImageDescription (org.apache.sis.metadata.iso.content.DefaultImageDescription)1 DefaultRangeDimension (org.apache.sis.metadata.iso.content.DefaultRangeDimension)1 DefaultExtent (org.apache.sis.metadata.iso.extent.DefaultExtent)1 DefaultDataIdentification (org.apache.sis.metadata.iso.identification.DefaultDataIdentification)1 DefaultAlgorithm (org.apache.sis.metadata.iso.lineage.DefaultAlgorithm)1 DefaultLineage (org.apache.sis.metadata.iso.lineage.DefaultLineage)1 DefaultProcessStep (org.apache.sis.metadata.iso.lineage.DefaultProcessStep)1 DefaultProcessing (org.apache.sis.metadata.iso.lineage.DefaultProcessing)1 DefaultDataQuality (org.apache.sis.metadata.iso.quality.DefaultDataQuality)1