use of eu.esdihumboldt.util.geometry.interpolation.InterpolationAlgorithm 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;
}
Aggregations