Search in sources :

Example 1 with DefaultAttributeGroup

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

the class PropertyAccessorTest method testSetDeprecated.

/**
 * Tests setting a deprecated properties. This properties should not be visible in the map,
 * but still be accepted by the map views.
 */
@Test
@DependsOnMethod("testSet")
public void testSetDeprecated() {
    final PropertyAccessor accessor = new PropertyAccessor(HardCodedCitations.ISO_19115, CoverageDescription.class, DefaultCoverageDescription.class, DefaultCoverageDescription.class);
    final int indexOfDeprecated = accessor.indexOf("contentType", true);
    final int indexOfReplacement = accessor.indexOf("attributeGroup", true);
    assertTrue("Deprecated elements shall be sorted after non-deprecated ones.", indexOfDeprecated > indexOfReplacement);
    /*
         * Writes a value using the deprecated property.
         */
    final DefaultCoverageDescription instance = new DefaultCoverageDescription();
    assertNull("Shall be initially empty.", accessor.set(indexOfDeprecated, instance, CoverageContentType.IMAGE, PropertyAccessor.RETURN_PREVIOUS));
    assertEquals(CoverageContentType.IMAGE, accessor.get(indexOfDeprecated, instance));
    /*
         * Compares with the non-deprecated property.
         */
    final Collection<DefaultAttributeGroup> groups = instance.getAttributeGroups();
    assertSame(groups, accessor.get(indexOfReplacement, instance));
    assertEquals(CoverageContentType.IMAGE, getSingleton(getSingleton(groups).getContentTypes()));
    /*
         * While we can read/write the value through two properties,
         * only one should be visible.
         */
    assertEquals("Deprecated property shall not be visible.", 1, accessor.count(instance, ValueExistencePolicy.NON_EMPTY, PropertyAccessor.COUNT_SHALLOW));
}
Also used : DefaultCoverageDescription(org.apache.sis.metadata.iso.content.DefaultCoverageDescription) DefaultAttributeGroup(org.apache.sis.metadata.iso.content.DefaultAttributeGroup) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 2 with DefaultAttributeGroup

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

the class TreeTableFormatTest method testImageDescription.

/**
 * Tests the formatting of a {@link DefaultImageDescription} object.
 */
@Test
public void testImageDescription() {
    final DefaultImageDescription image = new DefaultImageDescription();
    image.setAttributeGroups(Arrays.asList(new DefaultAttributeGroup(null, createBand(0.25, 0.26)), new DefaultAttributeGroup(null, createBand(0.28, 0.29))));
    final String text = format.format(image.asTreeTable());
    assertMultilinesEquals("Image description\n" + "  ├─Attribute group (1 of 2)\n" + "  │   └─Attribute\n" + "  │       ├─Max value………………… 0.26\n" + "  │       ├─Min value………………… 0.25\n" + "  │       └─Units…………………………… cm\n" + "  └─Attribute group (2 of 2)\n" + "      └─Attribute\n" + "          ├─Max value………………… 0.29\n" + "          ├─Min value………………… 0.28\n" + "          └─Units…………………………… cm\n", text);
}
Also used : DefaultImageDescription(org.apache.sis.metadata.iso.content.DefaultImageDescription) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) DefaultAttributeGroup(org.apache.sis.metadata.iso.content.DefaultAttributeGroup) Test(org.junit.Test) DefaultCitationTest(org.apache.sis.metadata.iso.citation.DefaultCitationTest)

Example 3 with DefaultAttributeGroup

use of org.apache.sis.metadata.iso.content.DefaultAttributeGroup 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)

Aggregations

DefaultAttributeGroup (org.apache.sis.metadata.iso.content.DefaultAttributeGroup)3 DefaultCoverageDescription (org.apache.sis.metadata.iso.content.DefaultCoverageDescription)2 Test (org.junit.Test)2 DateTimeException (java.time.DateTimeException)1 DefaultMetadata (org.apache.sis.metadata.iso.DefaultMetadata)1 DefaultCitationTest (org.apache.sis.metadata.iso.citation.DefaultCitationTest)1 DefaultBand (org.apache.sis.metadata.iso.content.DefaultBand)1 DefaultImageDescription (org.apache.sis.metadata.iso.content.DefaultImageDescription)1 DependsOnMethod (org.apache.sis.test.DependsOnMethod)1 SimpleInternationalString (org.apache.sis.util.iso.SimpleInternationalString)1 ProjectedCRS (org.opengis.referencing.crs.ProjectedCRS)1