use of org.opengis.util.NoSuchIdentifierException in project sis by apache.
the class Proj4Factory method name.
/**
* Returns the {@literal Proj.4} name of the given parameter value or parameter group.
*
* @param param the parameter value or parameter group for which to get the Proj.4 name.
* @param errorKey the resource key of the error message to produce if no Proj.4 name has been found.
* The message shall expect exactly one argument. This error key can be
* {@link Errors.Keys#UnsupportedOperation_1} or {@link Errors.Keys#UnexpectedParameter_1}.
* @return the Proj.4 name of the given object (never null).
* @throws FactoryException if the Proj.4 name has not been found.
*/
private String name(final IdentifiedObject param, final short errorKey) throws FactoryException {
String name = IdentifiedObjects.getName(param, Citations.PROJ4);
if (name == null) {
name = param.getName().getCode();
final String message = Errors.getResources(defaultProperties).getString(errorKey, name);
if (errorKey == Errors.Keys.UnsupportedOperation_1) {
throw new NoSuchIdentifierException(message, name);
} else {
throw new InvalidGeodeticParameterException(message);
}
}
return name;
}
use of org.opengis.util.NoSuchIdentifierException 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.util.NoSuchIdentifierException in project sis by apache.
the class ConsistencyTest method testCoordinateReferenceSystems.
/**
* Verifies the WKT consistency of all CRS instances.
*
* @throws FactoryException if an error other than "unsupported operation method" occurred.
*/
@Test
public void testCoordinateReferenceSystems() throws FactoryException {
assumeTrue(RUN_EXTENSIVE_TESTS);
final WKTFormat v1 = new WKTFormat(null, null);
final WKTFormat v1c = new WKTFormat(null, null);
final WKTFormat v2 = new WKTFormat(null, null);
final WKTFormat v2s = new WKTFormat(null, null);
v1.setConvention(Convention.WKT1);
v1c.setConvention(Convention.WKT1_COMMON_UNITS);
v2.setConvention(Convention.WKT2);
v2s.setConvention(Convention.WKT2_SIMPLIFIED);
for (final String code : CRS.getAuthorityFactory(null).getAuthorityCodes(CoordinateReferenceSystem.class)) {
if (!EXCLUDES.contains(code)) {
final CoordinateReferenceSystem crs;
try {
crs = CRS.forCode(code);
} catch (UnavailableFactoryException | NoSuchIdentifierException | FactoryDataException e) {
print(code, "WARNING", e.getLocalizedMessage());
continue;
}
lookup(parseAndFormat(v2, code, crs), crs);
lookup(parseAndFormat(v2s, code, crs), crs);
/*
* There is more information lost in WKT 1 than in WKT 2, so we can not test everything.
* For example we can not format fully three-dimensional geographic CRS because the unit
* is not the same for all axes. We can not format neither some axis directions.
*/
try {
parseAndFormat(v1, code, crs);
} catch (UnformattableObjectException e) {
print(code, "WARNING", e.getLocalizedMessage());
continue;
}
parseAndFormat(v1c, code, crs);
}
}
}
use of org.opengis.util.NoSuchIdentifierException in project sis by apache.
the class DefaultMathTransformFactory method getOperationMethod.
/**
* Returns the operation method for the specified name or identifier. The given argument shall be either
* a method {@linkplain DefaultOperationMethod#getName() name} (e.g. <cite>"Transverse Mercator"</cite>)
* or one of its {@linkplain DefaultOperationMethod#getIdentifiers() identifiers} (e.g. {@code "EPSG:9807"}).
*
* <p>The search is case-insensitive. Comparisons against method names can be
* {@linkplain DefaultOperationMethod#isHeuristicMatchForName(String) heuristic}.</p>
*
* <p>If more than one method match the given identifier, then the first (according iteration order)
* non-{@linkplain org.apache.sis.util.Deprecable#isDeprecated() deprecated} matching method is returned.
* If all matching methods are deprecated, the first one is returned.</p>
*
* @param identifier the name or identifier of the operation method to search.
* @return the coordinate operation method for the given name or identifier.
* @throws NoSuchIdentifierException if there is no operation method registered for the specified identifier.
*
* @see org.apache.sis.referencing.operation.DefaultCoordinateOperationFactory#getOperationMethod(String)
*/
public OperationMethod getOperationMethod(String identifier) throws NoSuchIdentifierException {
identifier = CharSequences.trimWhitespaces(identifier);
ArgumentChecks.ensureNonEmpty("identifier", identifier);
OperationMethod method = methodsByName.get(identifier);
if (method == null) {
final ReferencingServices services = ReferencingServices.getInstance();
synchronized (methods) {
method = services.getOperationMethod(methods, identifier);
}
if (method == null) {
throw new NoSuchIdentifierException(Resources.format(Resources.Keys.NoSuchOperationMethod_1, identifier), identifier);
}
/*
* Remember the method we just found, for faster check next time.
*/
final OperationMethod previous = methodsByName.putIfAbsent(identifier.intern(), method);
if (previous != null) {
method = previous;
}
}
return method;
}
use of org.opengis.util.NoSuchIdentifierException in project sis by apache.
the class MathTransformParser method parseParamMT.
/**
* Parses a {@code "PARAM_MT"} element. This element has the following pattern:
*
* {@preformat text
* PARAM_MT["<classification-name>" {,<parameter>}* ]
* }
*
* @param parent the parent element.
* @return the {@code "PARAM_MT"} element as an {@link MathTransform} object.
* @throws ParseException if the {@code "PARAM_MT"} element can not be parsed.
*/
private MathTransform parseParamMT(final Element parent) throws ParseException {
final Element element = parent.pullElement(FIRST, WKTKeywords.Param_MT);
if (element == null) {
return null;
}
classification = element.pullString("classification");
final ParameterValueGroup parameters;
try {
parameters = mtFactory.getDefaultParameters(classification);
} catch (NoSuchIdentifierException exception) {
throw element.parseFailed(exception);
}
/*
* Scan over all PARAMETER["name", value] elements and
* set the corresponding parameter in the parameter group.
*/
parseParameters(element, parameters, null, null);
element.close(ignoredElements);
/*
* We now have all informations for constructing the math transform.
*/
final MathTransform transform;
try {
transform = mtFactory.createParameterizedTransform(parameters);
} catch (FactoryException exception) {
throw element.parseFailed(exception);
}
lastMethod = mtFactory.getLastMethodUsed();
return transform;
}
Aggregations