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));
}
}
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));
}
}
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"));
}
}
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;
}
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));
}
}
}
}
Aggregations