Search in sources :

Example 1 with NoSuchIdentifierException

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;
}
Also used : InvalidGeodeticParameterException(org.apache.sis.referencing.factory.InvalidGeodeticParameterException) NoSuchIdentifierException(org.opengis.util.NoSuchIdentifierException) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString)

Example 2 with NoSuchIdentifierException

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;
}
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 3 with NoSuchIdentifierException

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);
        }
    }
}
Also used : UnformattableObjectException(org.apache.sis.io.wkt.UnformattableObjectException) FactoryDataException(org.apache.sis.referencing.factory.FactoryDataException) NoSuchIdentifierException(org.opengis.util.NoSuchIdentifierException) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) UnavailableFactoryException(org.apache.sis.referencing.factory.UnavailableFactoryException) WKTFormat(org.apache.sis.io.wkt.WKTFormat) Test(org.junit.Test)

Example 4 with NoSuchIdentifierException

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;
}
Also used : ReferencingServices(org.apache.sis.internal.metadata.ReferencingServices) NoSuchIdentifierException(org.opengis.util.NoSuchIdentifierException) DefaultOperationMethod(org.apache.sis.referencing.operation.DefaultOperationMethod) OperationMethod(org.opengis.referencing.operation.OperationMethod)

Example 5 with NoSuchIdentifierException

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;
}
Also used : MathTransform(org.opengis.referencing.operation.MathTransform) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) FactoryException(org.opengis.util.FactoryException) NoSuchIdentifierException(org.opengis.util.NoSuchIdentifierException)

Aggregations

NoSuchIdentifierException (org.opengis.util.NoSuchIdentifierException)9 OperationMethod (org.opengis.referencing.operation.OperationMethod)3 FactoryDataException (org.apache.sis.referencing.factory.FactoryDataException)2 InvalidGeodeticParameterException (org.apache.sis.referencing.factory.InvalidGeodeticParameterException)2 DefaultOperationMethod (org.apache.sis.referencing.operation.DefaultOperationMethod)2 SimpleInternationalString (org.apache.sis.util.iso.SimpleInternationalString)2 ParameterNotFoundException (org.opengis.parameter.ParameterNotFoundException)2 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)2 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)2 MathTransform (org.opengis.referencing.operation.MathTransform)2 FactoryException (org.opengis.util.FactoryException)2 ResultSet (java.sql.ResultSet)1 NoSuchElementException (java.util.NoSuchElementException)1 ReferencingServices (org.apache.sis.internal.metadata.ReferencingServices)1 UnformattableObjectException (org.apache.sis.io.wkt.UnformattableObjectException)1 WKTFormat (org.apache.sis.io.wkt.WKTFormat)1 DefaultProjectedCRS (org.apache.sis.referencing.crs.DefaultProjectedCRS)1 UnavailableFactoryException (org.apache.sis.referencing.factory.UnavailableFactoryException)1 DefaultConversion (org.apache.sis.referencing.operation.DefaultConversion)1 DefaultMathTransformFactory (org.apache.sis.referencing.operation.transform.DefaultMathTransformFactory)1