Search in sources :

Example 1 with ArcSegment

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

the class SplitInterpolation method interpolateToLineString.

private LineString interpolateToLineString(Arc arc) {
    // arc segments to process
    Deque<ArcSegment> toProcess = new LinkedList<>();
    // start with full arc as segment
    toProcess.addFirst(new ArcSplitSegment(arc, getMaxPositionalError()));
    // list to collect atomic parts
    List<ArcSegment> parts = new LinkedList<>();
    // for every segment to process...
    while (!toProcess.isEmpty()) {
        ArcSegment segment = toProcess.pop();
        if (segment.isAtomic()) {
            // segment cannot be split
            // -> use for result
            parts.add(segment);
        } else {
            // otherwise split the segment in two and handle the parts
            toProcess.addFirst(segment.getSecondPart());
            toProcess.addFirst(segment.getFirstPart());
        }
    }
    // combine the segments to a single LineString
    List<Coordinate> coords = new ArrayList<>();
    for (int i = 0; i < parts.size(); i++) {
        ArcSegment part = parts.get(i);
        if (i == 0) {
            coords.add(part.getStartPoint());
        }
        Coordinate middle = part.getMiddlePoint();
        if (middle != null) {
            // should actually not occur
            InterpolationUtil.addIfDifferent(coords, middle);
        }
        InterpolationUtil.addIfDifferent(coords, part.getEndPoint());
    }
    return createLineString(coords.toArray(new Coordinate[coords.size()]), arc);
}
Also used : ArcSegment(eu.esdihumboldt.util.geometry.interpolation.ArcSegment) Coordinate(org.locationtech.jts.geom.Coordinate) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Example 2 with ArcSegment

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

the class GridInterpolation method interpolateToLineString.

private LineString interpolateToLineString(Arc arc) {
    // arc segments to process
    Deque<ArcSegment> toProcess = new LinkedList<>();
    // start with full arc as segment
    toProcess.addFirst(new ArcGridSegment(arc, moveAllToGrid, gridSize));
    // list to collect atomic parts
    List<ArcSegment> parts = new LinkedList<>();
    // for every segment to process...
    while (!toProcess.isEmpty()) {
        ArcSegment segment = toProcess.pop();
        if (segment.isAtomic()) {
            // segment cannot be split
            // -> use for result
            parts.add(segment);
        } else {
            // otherwise split the segment in two and handle the parts
            toProcess.addFirst(segment.getSecondPart());
            toProcess.addFirst(segment.getFirstPart());
        }
    }
    // combine the segments to a single LineString
    List<Coordinate> coords = new ArrayList<>();
    for (int i = 0; i < parts.size(); i++) {
        ArcSegment part = parts.get(i);
        if (i == 0) {
            coords.add(part.getStartPoint());
        }
        Coordinate middle = part.getMiddlePoint();
        if (middle != null) {
            // should actually not occur
            InterpolationUtil.addIfDifferent(coords, middle);
        }
        InterpolationUtil.addIfDifferent(coords, part.getEndPoint());
    }
    return createLineString(coords.toArray(new Coordinate[coords.size()]), arc);
}
Also used : ArcSegment(eu.esdihumboldt.util.geometry.interpolation.ArcSegment) Coordinate(org.locationtech.jts.geom.Coordinate) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Aggregations

ArcSegment (eu.esdihumboldt.util.geometry.interpolation.ArcSegment)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 Coordinate (org.locationtech.jts.geom.Coordinate)2