Search in sources :

Example 1 with ParameterNotFoundException

use of org.opengis.parameter.ParameterNotFoundException in project sis by apache.

the class TensorValuesTest method testDescriptor.

/**
 * Tests {@link TensorValues#descriptor(String)}.
 */
@Test
public void testDescriptor() {
    final Double N0 = 0.0;
    final Double N1 = 1.0;
    final Integer N3 = 3;
    final ParameterValueGroup group = createWKT1();
    final ParameterDescriptorGroup d = group.getDescriptor();
    assertDescriptorEquals(NUM_ROW, N3, d.descriptor(NUM_ROW));
    assertDescriptorEquals(NUM_COL, N3, d.descriptor(NUM_COL));
    assertDescriptorEquals("elt_0_0", N1, d.descriptor("elt_0_0"));
    assertDescriptorEquals("elt_0_1", N0, d.descriptor("elt_0_1"));
    assertDescriptorEquals("elt_0_2", N0, d.descriptor("elt_0_2"));
    assertDescriptorEquals("elt_1_0", N0, d.descriptor("elt_1_0"));
    assertDescriptorEquals("elt_1_1", N1, d.descriptor("elt_1_1"));
    assertDescriptorEquals("elt_1_2", N0, d.descriptor("elt_1_2"));
    assertDescriptorEquals("elt_2_0", N0, d.descriptor("elt_2_0"));
    assertDescriptorEquals("elt_2_1", N0, d.descriptor("elt_2_1"));
    assertDescriptorEquals("elt_2_2", N1, d.descriptor("elt_2_2"));
    /*
         * Same test than above, but using the EPSG or pseudo-EPSG names.
         */
    assertDescriptorEquals("elt_0_0", N1, d.descriptor("A0"));
    assertDescriptorEquals("elt_0_1", N0, d.descriptor("A1"));
    assertDescriptorEquals("elt_0_2", N0, d.descriptor("A2"));
    assertDescriptorEquals("elt_1_0", N0, d.descriptor("B0"));
    assertDescriptorEquals("elt_1_1", N1, d.descriptor("B1"));
    assertDescriptorEquals("elt_1_2", N0, d.descriptor("B2"));
    assertDescriptorEquals("elt_2_0", N0, d.descriptor("C0"));
    assertDescriptorEquals("elt_2_1", N0, d.descriptor("C1"));
    assertDescriptorEquals("elt_2_2", N1, d.descriptor("C2"));
    /*
         * If we reduce the matrix size, than it shall not be possible
         * anymore to get the descriptor in the row that we removed.
         */
    group.parameter(NUM_COL).setValue(2);
    try {
        d.descriptor("elt_2_2");
        fail("elt_2_2 should not exist.");
    } catch (ParameterNotFoundException e) {
        final String message = e.getMessage();
        assertTrue(message, message.contains("elt_2_2"));
        assertTrue(message, message.contains(GROUP_NAME));
    }
}
Also used : ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) ParameterDescriptorGroup(org.opengis.parameter.ParameterDescriptorGroup) ParameterNotFoundException(org.opengis.parameter.ParameterNotFoundException) Test(org.junit.Test)

Example 2 with ParameterNotFoundException

use of org.opengis.parameter.ParameterNotFoundException in project sis by apache.

the class TensorValuesTest method testParameter.

/**
 * Tests {@link TensorValues#parameter(String)}.
 */
@Test
public void testParameter() {
    final Double N0 = 0.0;
    final Double N1 = 1.0;
    final Integer N3 = 3;
    final ParameterValueGroup group = createWKT1();
    assertValueEquals(NUM_ROW, N3, group.parameter(NUM_ROW));
    assertValueEquals(NUM_COL, N3, group.parameter(NUM_COL));
    assertValueEquals("elt_0_0", N1, group.parameter("elt_0_0"));
    assertValueEquals("elt_0_1", N0, group.parameter("elt_0_1"));
    assertValueEquals("elt_2_2", N1, group.parameter("elt_2_2"));
    assertValueEquals("elt_0_0", N1, group.parameter("A0"));
    assertValueEquals("elt_0_1", N0, group.parameter("A1"));
    assertValueEquals("elt_2_2", N1, group.parameter("C2"));
    /*
         * Change some values and test again.
         */
    group.parameter("elt_2_2").setValue(8);
    group.parameter("elt_0_1").setValue(6);
    assertValueEquals("elt_2_2", 8.0, group.parameter("elt_2_2"));
    assertValueEquals("elt_0_1", 6.0, group.parameter("elt_0_1"));
    assertValueEquals("elt_0_0", N1, group.parameter("elt_0_0"));
    assertValueEquals("elt_2_2", 8.0, group.parameter("C2"));
    assertValueEquals("elt_0_1", 6.0, group.parameter("A1"));
    assertValueEquals("elt_0_0", N1, group.parameter("A0"));
    /*
         * If we reduce the matrix size, than it shall not be possible
         * anymore to get the descriptor in the row that we removed.
         */
    group.parameter(NUM_COL).setValue(2);
    try {
        group.parameter("elt_2_2");
        fail("elt_2_2 should not exist.");
    } catch (ParameterNotFoundException e) {
        final String message = e.getMessage();
        assertTrue(message, message.contains("elt_2_2"));
        assertTrue(message, message.contains(GROUP_NAME));
    }
}
Also used : ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) ParameterNotFoundException(org.opengis.parameter.ParameterNotFoundException) Test(org.junit.Test)

Example 3 with ParameterNotFoundException

use of org.opengis.parameter.ParameterNotFoundException in project sis by apache.

the class UnmodifiableParameterValueGroupTest method testCreate.

/**
 * Tests creation of an {@link UnmodifiableParameterValueGroup} and verify the values.
 */
@Test
public void testCreate() {
    ParameterValueGroup group = DefaultParameterDescriptorGroupTest.M1_M1_O1_O2.createValue();
    group.parameter("Mandatory 1").setValue(5);
    group.parameter("Optional 3").setValue(8);
    group = UnmodifiableParameterValueGroup.create(group);
    assertEquals("values.size()", 3, group.values().size());
    assertEquals("values[0].name", "Mandatory 1", group.values().get(0).getDescriptor().getName().toString());
    assertEquals("values[1].name", "Mandatory 2", group.values().get(1).getDescriptor().getName().toString());
    assertEquals("values[2].name", "Optional 3", group.values().get(2).getDescriptor().getName().toString());
    assertEquals("values[0].value", 5, group.parameter("Mandatory 1").getValue());
    assertEquals("values[1].value", 10, group.parameter("Mandatory 2").getValue());
    assertEquals("values[2].value", 8, group.parameter("Optional 3").getValue());
    try {
        group.groups("dummy");
        fail("Shall not return non-existent groups.");
    } catch (ParameterNotFoundException e) {
        assertTrue(e.getMessage().contains("Test group"));
        assertTrue(e.getMessage().contains("dummy"));
    }
}
Also used : ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) ParameterNotFoundException(org.opengis.parameter.ParameterNotFoundException) Test(org.junit.Test)

Example 4 with ParameterNotFoundException

use of org.opengis.parameter.ParameterNotFoundException in project sis by apache.

the class ImageFileDirectory method completeMetadata.

/**
 * Completes the metadata with the information stored in the field of this IFD.
 * This method is invoked only if the user requested the ISO 19115 metadata.
 * This method creates a new {@code "metadata/contentInfo"} node for this image.
 * Information not under the {@code "metadata/contentInfo"} node will be merged
 * with the current content of the given {@code MetadataBuilder}.
 *
 * @param   metadata  where to write metadata information. Caller should have already invoked
 *                    {@link MetadataBuilder#setFormat(String)} before {@code completeMetadata(…)} calls.
 */
final void completeMetadata(final MetadataBuilder metadata, final Locale locale) throws DataStoreContentException, FactoryException {
    metadata.newCoverage(false);
    if (compression != null) {
        metadata.addCompression(compression.name().toLowerCase(locale));
    }
    for (int band = 0; band < samplesPerPixel; ) {
        metadata.newSampleDimension();
        metadata.setBitPerSample(bitsPerSample);
        if (minValues != null)
            metadata.addMinimumSampleValue(minValues.doubleValue(Math.min(band, minValues.size() - 1)));
        if (maxValues != null)
            metadata.addMaximumSampleValue(maxValues.doubleValue(Math.min(band, maxValues.size() - 1)));
        metadata.setBandIdentifier(++band);
    }
    /*
         * Add the resolution into the metadata. Our current ISO 19115 implementation restricts
         * the resolution unit to metres, but it may be relaxed in a future SIS version.
         */
    if (!Double.isNaN(resolution) && resolutionUnit != null) {
        metadata.addResolution(resolutionUnit.getConverterTo(Units.METRE).convert(resolution));
    }
    /*
         * Cell size is relevant only if the Threshholding TIFF tag value is 2. By convention in
         * this implementation class, other Threshholding values are stored as negative cell sizes:
         *
         *   -1 means that Threshholding is 1 or unspecified.
         *   -2 means that Threshholding is 2 but the matrix size has not yet been specified.
         *   -3 means that Threshholding is 3 (randomized process such as error diffusion).
         */
    switch(Math.min(cellWidth, cellHeight)) {
        case -1:
            {
                // Nothing to report.
                break;
            }
        case -3:
            {
                metadata.addProcessDescription(Resources.formatInternational(Resources.Keys.RandomizedProcessApplied));
                break;
            }
        default:
            {
                metadata.addProcessDescription(Resources.formatInternational(Resources.Keys.DitheringOrHalftoningApplied_2, (cellWidth >= 0) ? cellWidth : '?', (cellHeight >= 0) ? cellHeight : '?'));
                break;
            }
    }
    /*
         * Add Coordinate Reference System built from GeoTIFF tags.  Note that the CRS may not exist,
         * in which case the CRS builder returns null. This is safe since all MetadataBuilder methods
         * ignore null values (a design choice because this pattern come very often).
         */
    final boolean isGeorectified = (modelTiePoints == null) || (gridToCRS != null);
    metadata.newGridRepresentation(isGeorectified ? MetadataBuilder.GridType.GEORECTIFIED : MetadataBuilder.GridType.GEOREFERENCEABLE);
    metadata.setGeoreferencingAvailability(gridToCRS != null, false, false);
    CoordinateReferenceSystem crs = null;
    if (geoKeyDirectory != null) {
        final CRSBuilder helper = new CRSBuilder(reader);
        try {
            crs = helper.build(geoKeyDirectory, numericGeoParameters, asciiGeoParameters);
            metadata.addReferenceSystem(crs);
            helper.complete(metadata);
        } catch (NoSuchIdentifierException | ParameterNotFoundException e) {
            short key = Resources.Keys.UnsupportedProjectionMethod_1;
            if (e instanceof NoSuchAuthorityCodeException) {
                key = Resources.Keys.UnknownCRS_1;
            }
            reader.owner.warning(reader.resources().getString(key, reader.owner.getDisplayName()), e);
        } catch (IllegalArgumentException | NoSuchElementException | ClassCastException e) {
            if (!helper.alreadyReported) {
                reader.owner.warning(null, e);
            }
        }
    }
    try {
        if (!isGeorectified) {
            metadata.addGeolocation(new GridGeometry(filename(), crs, modelTiePoints));
        }
    } catch (TransformException e) {
        reader.owner.warning(null, e);
    }
    // Not needed anymore, so let GC do its work.
    geoKeyDirectory = null;
    numericGeoParameters = null;
    asciiGeoParameters = null;
    modelTiePoints = null;
}
Also used : NoSuchAuthorityCodeException(org.opengis.referencing.NoSuchAuthorityCodeException) TransformException(org.opengis.referencing.operation.TransformException) NoSuchIdentifierException(org.opengis.util.NoSuchIdentifierException) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) ParameterNotFoundException(org.opengis.parameter.ParameterNotFoundException) NoSuchElementException(java.util.NoSuchElementException)

Example 5 with ParameterNotFoundException

use of org.opengis.parameter.ParameterNotFoundException in project sis by apache.

the class CRSBuilder method verify.

/**
 * Verifies if the user-defined conversion created from GeoTIFF values
 * matches the given conversion created from the EPSG geodetic dataset.
 * This method does not verify the EPSG code of the given conversion.
 *
 * @param  projection  the conversion created from the EPSG geodetic dataset.
 */
private void verify(final Conversion projection, final Unit<Angle> angularUnit, final Unit<Length> linearUnit) throws FactoryException {
    final Unit<Angle> azimuthUnit = createUnit(GeoKeys.AzimuthUnits, (short) 0, Angle.class, Units.DEGREE);
    final String type = getAsString(GeoKeys.CoordTrans);
    if (type != null) {
        /*
             * Compare the name of the map projection declared in the GeoTIFF file with the name
             * of the projection used by the EPSG geodetic dataset.
             */
        final OperationMethod method = projection.getMethod();
        if (!IdentifiedObjects.isHeuristicMatchForName(method, type)) {
            Identifier expected = IdentifiedObjects.getIdentifier(method, Citations.GEOTIFF);
            if (expected == null) {
                expected = IdentifiedObjects.getIdentifier(method, null);
            }
            warning(Resources.Keys.NotTheEpsgValue_5, IdentifiedObjects.getIdentifierOrName(projection), expected.getCode(), GeoKeys.name(GeoKeys.CoordTrans), type, "");
        }
        /*
             * Compare the parameter values with the ones declared in the EPSG geodetic dataset.
             */
        final ParameterValueGroup parameters = projection.getParameterValues();
        for (final short key : remainingKeys()) {
            final Unit<?> unit;
            switch(GeoKeys.unitOf(key)) {
                case GeoKeys.RATIO:
                    unit = Units.UNITY;
                    break;
                case GeoKeys.LINEAR:
                    unit = linearUnit;
                    break;
                case GeoKeys.ANGULAR:
                    unit = angularUnit;
                    break;
                case GeoKeys.AZIMUTH:
                    unit = azimuthUnit;
                    break;
                default:
                    continue;
            }
            try {
                verify(projection, parameters.parameter("GeoTIFF:" + key).doubleValue(unit), key, unit);
            } catch (ParameterNotFoundException e) {
                warning(Resources.Keys.UnexpectedParameter_2, type, GeoKeys.name(key));
            }
        }
    }
}
Also used : Identifier(org.opengis.metadata.Identifier) Angle(javax.measure.quantity.Angle) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) ParameterNotFoundException(org.opengis.parameter.ParameterNotFoundException) OperationMethod(org.opengis.referencing.operation.OperationMethod)

Aggregations

ParameterNotFoundException (org.opengis.parameter.ParameterNotFoundException)16 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)7 GeneralParameterDescriptor (org.opengis.parameter.GeneralParameterDescriptor)6 ParameterDescriptorGroup (org.opengis.parameter.ParameterDescriptorGroup)4 Test (org.junit.Test)3 Constructor (java.lang.reflect.Constructor)2 PrivilegedAction (java.security.PrivilegedAction)2 ArrayList (java.util.ArrayList)2 Parser (org.apache.sis.io.wkt.Parser)2 FactoryException (org.opengis.util.FactoryException)2 NoSuchIdentifierException (org.opengis.util.NoSuchIdentifierException)2 ResultSet (java.sql.ResultSet)1 ParseException (java.text.ParseException)1 HashSet (java.util.HashSet)1 NoSuchElementException (java.util.NoSuchElementException)1 Angle (javax.measure.quantity.Angle)1 UnmodifiableArrayList (org.apache.sis.internal.util.UnmodifiableArrayList)1 DefaultParameterDescriptorGroup (org.apache.sis.parameter.DefaultParameterDescriptorGroup)1 AbstractIdentifiedObject (org.apache.sis.referencing.AbstractIdentifiedObject)1 FactoryDataException (org.apache.sis.referencing.factory.FactoryDataException)1