Search in sources :

Example 1 with SplitInterpolation

use of eu.esdihumboldt.util.geometry.interpolation.split.SplitInterpolation in project hale by halestudio.

the class InterpolationHelper method getInterpolation.

/**
 * Get the interpolation algorithm for a given instance reader.
 *
 * @param instanceReader the instance reader
 * @param factory the geometry factory
 * @return the interpolation algorithm
 */
public static InterpolationAlgorithm getInterpolation(IOProvider instanceReader, GeometryFactory factory) {
    // FIXME weak cache based on reader?
    String algorithmId = instanceReader.getParameter(PARAMETER_INTERPOLATION_ALGORITHM).as(String.class, DEFAULT_ALGORITHM);
    InterpolationAlgorithmFactory fact = InterpolationExtension.getInstance().getFactory(algorithmId);
    if (fact == null) {
        log.warn("Could not find interpolation algorithm with ID " + algorithmId);
        fact = InterpolationExtension.getInstance().getFactory(DEFAULT_ALGORITHM);
    }
    if (fact == null) {
        throw new IllegalStateException("Default interpolation algorithm could not be found");
    }
    InterpolationAlgorithm result;
    try {
        result = fact.createExtensionObject();
    } catch (Exception e) {
        log.error("Interpolation algorithm could be created", e);
        result = new SplitInterpolation();
    }
    double maxPositionalError = getMaxPositionalError(instanceReader);
    // configure the algorithm
    Map<String, Value> configuration = new HashMap<>();
    instanceReader.storeConfiguration(configuration);
    Map<String, String> properties = new HashMap<>();
    for (Entry<String, Value> entry : configuration.entrySet()) {
        if (!entry.getValue().isRepresentedAsDOM()) {
            properties.put(entry.getKey(), entry.getValue().getStringRepresentation());
        }
    }
    result.configure(factory, maxPositionalError, properties);
    return result;
}
Also used : SplitInterpolation(eu.esdihumboldt.util.geometry.interpolation.split.SplitInterpolation) HashMap(java.util.HashMap) Value(eu.esdihumboldt.hale.common.core.io.Value) InterpolationAlgorithm(eu.esdihumboldt.util.geometry.interpolation.InterpolationAlgorithm) InterpolationAlgorithmFactory(eu.esdihumboldt.util.geometry.interpolation.extension.InterpolationAlgorithmFactory)

Aggregations

Value (eu.esdihumboldt.hale.common.core.io.Value)1 InterpolationAlgorithm (eu.esdihumboldt.util.geometry.interpolation.InterpolationAlgorithm)1 InterpolationAlgorithmFactory (eu.esdihumboldt.util.geometry.interpolation.extension.InterpolationAlgorithmFactory)1 SplitInterpolation (eu.esdihumboldt.util.geometry.interpolation.split.SplitInterpolation)1 HashMap (java.util.HashMap)1