Search in sources :

Example 6 with InterpolationAlgorithm

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;
}
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

InterpolationAlgorithm (eu.esdihumboldt.util.geometry.interpolation.InterpolationAlgorithm)6 Coordinate (com.vividsolutions.jts.geom.Coordinate)5 LineString (com.vividsolutions.jts.geom.LineString)5 DefaultGeometryProperty (eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty)5 GeometryNotSupportedException (eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException)5 Arc (eu.esdihumboldt.util.geometry.interpolation.model.Arc)5 ArcByCenterPointImpl (eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcByCenterPointImpl)3 ArcByPointsImpl (eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcByPointsImpl)3 ArrayList (java.util.ArrayList)3 Point (com.vividsolutions.jts.geom.Point)2 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)2 CRSDefinition (eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition)2 ParseException (java.text.ParseException)2 Value (eu.esdihumboldt.hale.common.core.io.Value)1 TypeConstraint (eu.esdihumboldt.hale.common.schema.model.TypeConstraint)1 InterpolationAlgorithmFactory (eu.esdihumboldt.util.geometry.interpolation.extension.InterpolationAlgorithmFactory)1 ArcByCenterPoint (eu.esdihumboldt.util.geometry.interpolation.model.ArcByCenterPoint)1 ArcString (eu.esdihumboldt.util.geometry.interpolation.model.ArcString)1 ArcStringImpl (eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcStringImpl)1 SplitInterpolation (eu.esdihumboldt.util.geometry.interpolation.split.SplitInterpolation)1