Search in sources :

Example 1 with DefaultCoverageDescription

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

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

the class MergerTest method createSample1.

/**
 * Creates a metadata sample with 3 content information of different kind.
 */
private static DefaultMetadata createSample1() {
    final DefaultFeatureCatalogueDescription features = new DefaultFeatureCatalogueDescription();
    final DefaultCoverageDescription coverage = new DefaultCoverageDescription();
    final DefaultImageDescription image = new DefaultImageDescription();
    final DefaultMetadata metadata = new DefaultMetadata();
    features.setFeatureCatalogueCitations(Collections.singleton(new DefaultCitation("Shapefile")));
    features.setIncludedWithDataset(Boolean.TRUE);
    metadata.getContentInfo().add(features);
    coverage.setProcessingLevelCode(new DefaultIdentifier("Level 1"));
    metadata.getContentInfo().add(coverage);
    image.setImagingCondition(ImagingCondition.CLOUD);
    image.setCloudCoverPercentage(0.8);
    metadata.getContentInfo().add(image);
    metadata.getLanguages().add(Locale.JAPANESE);
    metadata.getCharacterSets().add(StandardCharsets.UTF_16);
    return metadata;
}
Also used : DefaultImageDescription(org.apache.sis.metadata.iso.content.DefaultImageDescription) DefaultFeatureCatalogueDescription(org.apache.sis.metadata.iso.content.DefaultFeatureCatalogueDescription) DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) DefaultMetadata(org.apache.sis.metadata.iso.DefaultMetadata) DefaultCoverageDescription(org.apache.sis.metadata.iso.content.DefaultCoverageDescription) DefaultIdentifier(org.apache.sis.metadata.iso.DefaultIdentifier)

Example 3 with DefaultCoverageDescription

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

the class MergerTest method testDeepMerge.

/**
 * Tests a merge operation that merge also the collection elements. Such deep merge is a
 * little bit aggressive; it may be desired in some occasions, but may also be dangerous.
 */
@Test
public void testDeepMerge() {
    final DefaultMetadata source = createSample1();
    final DefaultMetadata target = createSample2();
    final Merger merger = new Merger(null);
    merger.copy(source, target);
    assertSetEquals(Arrays.asList(Locale.JAPANESE, Locale.FRENCH), target.getLanguages());
    assertSetEquals(Collections.singleton(StandardCharsets.UTF_16), target.getCharacterSets());
    final Iterator<ContentInformation> it = target.getContentInfo().iterator();
    final ImageDescription image = (ImageDescription) it.next();
    final FeatureCatalogueDescription features = (FeatureCatalogueDescription) it.next();
    final DefaultCoverageDescription coverage = (DefaultCoverageDescription) it.next();
    assertFalse(it.hasNext());
    assertEquals("imagingCondition", ImagingCondition.CLOUD, image.getImagingCondition());
    assertEquals("cloudCoverPercentage", Double.valueOf(0.8), image.getCloudCoverPercentage());
    assertEquals("processingLevelCode", "Level 2", image.getProcessingLevelCode().getCode());
    assertEquals("processingLevelCode", "Level 1", coverage.getProcessingLevelCode().getCode());
    assertEquals("includedWithDataset", Boolean.TRUE, features.isIncludedWithDataset());
    final Iterator<? extends Citation> ci = features.getFeatureCatalogueCitations().iterator();
    assertEquals("GPX file", ci.next().getTitle().toString());
    assertEquals("Shapefile", ci.next().getTitle().toString());
    assertFalse(ci.hasNext());
}
Also used : FeatureCatalogueDescription(org.opengis.metadata.content.FeatureCatalogueDescription) DefaultFeatureCatalogueDescription(org.apache.sis.metadata.iso.content.DefaultFeatureCatalogueDescription) DefaultMetadata(org.apache.sis.metadata.iso.DefaultMetadata) ContentInformation(org.opengis.metadata.content.ContentInformation) DefaultCoverageDescription(org.apache.sis.metadata.iso.content.DefaultCoverageDescription) ImageDescription(org.opengis.metadata.content.ImageDescription) DefaultImageDescription(org.apache.sis.metadata.iso.content.DefaultImageDescription) Test(org.junit.Test)

Example 4 with DefaultCoverageDescription

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

DefaultCoverageDescription (org.apache.sis.metadata.iso.content.DefaultCoverageDescription)4 DefaultMetadata (org.apache.sis.metadata.iso.DefaultMetadata)3 DefaultAttributeGroup (org.apache.sis.metadata.iso.content.DefaultAttributeGroup)2 DefaultFeatureCatalogueDescription (org.apache.sis.metadata.iso.content.DefaultFeatureCatalogueDescription)2 DefaultImageDescription (org.apache.sis.metadata.iso.content.DefaultImageDescription)2 Test (org.junit.Test)2 DateTimeException (java.time.DateTimeException)1 DefaultIdentifier (org.apache.sis.metadata.iso.DefaultIdentifier)1 DefaultCitation (org.apache.sis.metadata.iso.citation.DefaultCitation)1 DefaultBand (org.apache.sis.metadata.iso.content.DefaultBand)1 DependsOnMethod (org.apache.sis.test.DependsOnMethod)1 ContentInformation (org.opengis.metadata.content.ContentInformation)1 FeatureCatalogueDescription (org.opengis.metadata.content.FeatureCatalogueDescription)1 ImageDescription (org.opengis.metadata.content.ImageDescription)1 ProjectedCRS (org.opengis.referencing.crs.ProjectedCRS)1