Search in sources :

Example 1 with DefaultBand

use of org.apache.sis.metadata.iso.content.DefaultBand in project sis by apache.

the class LandsatReader method band.

/**
 * Returns the band at the given index, creating it if needed.
 * If the given index is out of range, then this method logs a warning and returns {@code null}.
 *
 * @param  key    the key without its band number. Used only for formatting warning messages.
 * @param  index  the band index.
 */
private DefaultBand band(final String key, int index) {
    if (index < 1 || index > BAND_NAMES.length) {
        listeners.warning(errors().getString(Errors.Keys.UnexpectedValueInElement_2, key + index, index), null);
        return null;
    }
    DefaultBand band = bands[--index];
    if (band == null) {
        band = new DefaultBand();
        band.setDescription(new SimpleInternationalString(BAND_NAMES[index]));
        band.setPeakResponse((double) WAVELENGTHS[index]);
        band.setBoundUnits(Units.NANOMETRE);
        bands[index] = band;
    }
    return band;
}
Also used : DefaultBand(org.apache.sis.metadata.iso.content.DefaultBand) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString)

Example 2 with DefaultBand

use of org.apache.sis.metadata.iso.content.DefaultBand in project sis by apache.

the class TreeTableFormatTest method createBand.

/**
 * Creates a band for the given minimum and maximum wavelengths, in centimetres.
 */
private static DefaultBand createBand(final double min, final double max) {
    final DefaultBand band = new DefaultBand();
    band.setMinValue(min);
    band.setMaxValue(max);
    band.setUnits(Units.CENTIMETRE);
    return band;
}
Also used : DefaultBand(org.apache.sis.metadata.iso.content.DefaultBand)

Example 3 with DefaultBand

use of org.apache.sis.metadata.iso.content.DefaultBand in project sis by apache.

the class LandsatReader method getMetadata.

/**
 * Returns the metadata about the resources described in the Landsat file.
 * The {@link #read(BufferedReader)} method must be invoked at least once before.
 *
 * @throws FactoryException if an error occurred while creating the Coordinate Reference System.
 */
final Metadata getMetadata() throws FactoryException {
    metadata.addLanguage(Locale.ENGLISH, MetadataBuilder.Scope.METADATA);
    metadata.addResourceScope(ScopeCode.valueOf("COVERAGE"), null);
    try {
        flushSceneTime();
    } catch (DateTimeException e) {
        // May happen if the SCENE_CENTER_TIME attribute was found without DATE_ACQUIRED.
        warning(null, null, e);
    }
    /*
         * Create the Coordinate Reference System. We normally have only one of UTM or Polar Stereographic,
         * but this block is nevertheless capable to take both (such metadata are likely to be invalid, but
         * we can not guess which of the two CRS is correct).
         */
    if (datum != null) {
        if (utmZone > 0) {
            metadata.addReferenceSystem(datum.universal(1, TransverseMercator.Zoner.UTM.centralMeridian(utmZone)));
        }
        if (projection != null) {
            final double sp = projection.parameter(Constants.STANDARD_PARALLEL_1).doubleValue();
            ProjectedCRS crs = (ProjectedCRS) CRS.forCode(Constants.EPSG + ":" + (// Standard parallel = 71°N
            sp >= 0 ? // Standard parallel = 71°N
            Constants.EPSG_ARCTIC_POLAR_STEREOGRAPHIC : // Standard parallel = 71°S
            Constants.EPSG_ANTARCTIC_POLAR_STEREOGRAPHIC));
            if (datum != CommonCRS.WGS84 || Math.abs(sp) != 71 || projection.parameter(Constants.FALSE_EASTING).doubleValue() != 0 || projection.parameter(Constants.FALSE_NORTHING).doubleValue() != 0 || projection.parameter(Constants.CENTRAL_MERIDIAN).doubleValue() != 0) {
                crs = ReferencingUtilities.createProjectedCRS(Collections.singletonMap(ProjectedCRS.NAME_KEY, "Polar stereographic"), datum.geographic(), projection, crs.getCoordinateSystem());
            }
            metadata.addReferenceSystem(crs);
        }
    }
    /*
         * Set information about envelope (or geographic area) and grid size.
         */
    if (toBoundingBox(GEOGRAPHIC)) {
        metadata.addExtent(corners, GEOGRAPHIC);
    }
    for (int i = 0; i < gridSizes.length; i += DIM) {
        final int width = gridSizes[i];
        final int height = gridSizes[i + 1];
        if (width != 0 || height != 0) {
            metadata.newGridRepresentation(MetadataBuilder.GridType.GEORECTIFIED);
            metadata.setAxisName(0, DimensionNameType.SAMPLE);
            metadata.setAxisName(1, DimensionNameType.LINE);
            metadata.setAxisLength(0, width);
            metadata.setAxisLength(1, height);
        }
    }
    /*
         * At this point we are done configuring he metadata builder. Creates the ISO 19115 metadata instance,
         * then continue adding some more specific metadata elements by ourself. For example information about
         * bands are splitted in 3 different AttributeGroups based on their grid size.
         */
    final DefaultMetadata result = metadata.build(false);
    if (result != null) {
        /*
             * Set information about all non-null bands. The bands are categorized in three groups:
             * PANCHROMATIC, REFLECTIVE and THERMAL. The group in which each band belong is encoded
             * in the BAND_GROUPS bitmask.
             */
        final DefaultCoverageDescription content = (DefaultCoverageDescription) singletonOrNull(result.getContentInfo());
        if (content != null) {
            final DefaultAttributeGroup[] groups = new DefaultAttributeGroup[NUM_GROUPS];
            for (int i = 0; i < bands.length; i++) {
                final DefaultBand band = bands[i];
                if (band != null) {
                    final int gi = (BAND_GROUPS >>> 2 * i) & 3;
                    DefaultAttributeGroup group = groups[gi];
                    if (group == null) {
                        group = new DefaultAttributeGroup(CoverageContentType.PHYSICAL_MEASUREMENT, null);
                        content.getAttributeGroups().add(group);
                        groups[gi] = group;
                    }
                    group.getAttributes().add(band);
                }
            }
        }
        result.setMetadataStandards(Citations.ISO_19115);
        result.freeze();
    }
    return result;
}
Also used : DateTimeException(java.time.DateTimeException) DefaultBand(org.apache.sis.metadata.iso.content.DefaultBand) ProjectedCRS(org.opengis.referencing.crs.ProjectedCRS) DefaultMetadata(org.apache.sis.metadata.iso.DefaultMetadata) DefaultCoverageDescription(org.apache.sis.metadata.iso.content.DefaultCoverageDescription) DefaultAttributeGroup(org.apache.sis.metadata.iso.content.DefaultAttributeGroup)

Example 4 with DefaultBand

use of org.apache.sis.metadata.iso.content.DefaultBand in project sis by apache.

the class LandsatReader method setTransferFunction.

/**
 * Sets a component of the linear transfer function.
 *
 * @param  key      the key without its band number. Used only for formatting warning messages.
 * @param  band     index of the band to set.
 * @param  isScale  {@code true} for setting the scale factor, or {@code false} for setting the offset.
 * @param  value    the value to set.
 */
private void setTransferFunction(final String key, final int band, final boolean isScale, final String value) {
    // Done first in case an exception is thrown.
    final Double v = parseDouble(value);
    final DefaultBand db = band(key, band);
    if (db != null) {
        db.setTransferFunctionType(TransferFunctionType.LINEAR);
        if (isScale) {
            db.setScaleFactor(v);
        } else {
            db.setOffset(v);
        }
    }
}
Also used : DefaultBand(org.apache.sis.metadata.iso.content.DefaultBand)

Aggregations

DefaultBand (org.apache.sis.metadata.iso.content.DefaultBand)4 DateTimeException (java.time.DateTimeException)1 DefaultMetadata (org.apache.sis.metadata.iso.DefaultMetadata)1 DefaultAttributeGroup (org.apache.sis.metadata.iso.content.DefaultAttributeGroup)1 DefaultCoverageDescription (org.apache.sis.metadata.iso.content.DefaultCoverageDescription)1 SimpleInternationalString (org.apache.sis.util.iso.SimpleInternationalString)1 ProjectedCRS (org.opengis.referencing.crs.ProjectedCRS)1