Search in sources :

Example 1 with StraightSegment

use of ch.interlis.iom_j.itf.impl.jtsext.geom.StraightSegment in project ili2db by claeis.

the class Fgdb2iox method getPolyline.

private LineString getPolyline(JtsextGeometryFactory fact, int part, Coordinate[] points, int[] partsStart, java.util.Map<Integer, Arc> arcs, boolean closeIt) {
    int from = partsStart[part];
    int to = points.length;
    if (part < partsStart.length - 1) {
        to = partsStart[part + 1];
    }
    // LineString?
    if (arcs == null || arcs.size() == 0) {
        Coordinate[] coords = null;
        if (closeIt && !points[from].equals2D(points[to - 1])) {
            coords = Arrays.copyOfRange(points, from, to + 1);
            coords[to] = coords[0];
        } else {
            coords = Arrays.copyOfRange(points, from, to);
        }
        return fact.createLineString(coords);
    }
    // ASSERT: CompoundCurve
    ArrayList<CurveSegment> segs = new ArrayList<CurveSegment>();
    Coordinate start = points[from];
    for (int i = from + 1; i < to; i++) {
        Coordinate end = points[i];
        Arc arc = arcs.get(i - 1);
        CurveSegment seg = null;
        if (arc != null) {
            if (((arc.bits & EsriShpConstants.arcDefinedIP) != 0)) {
                Coordinate midpt = new Coordinate(arc.centerPoint_x, arc.centerPoint_y);
                seg = new ArcSegment(start, midpt, end);
            } else {
                Coordinate center = new Coordinate(arc.centerPoint_x, arc.centerPoint_y);
                double radius = ArcSegment.dist(start, center);
                double sign = 0.0;
                boolean isMinor = ((arc.bits & EsriShpConstants.arcIsMinor) != 0);
                if (CGAlgorithms.computeOrientation(start, end, center) < 0) {
                    sign = isMinor ? 1.0 : -1.0;
                } else {
                    sign = isMinor ? -1.0 : 1.0;
                }
                Coordinate midpt = ArcSegment.calcArcPt(start, end, center, radius, sign);
                seg = new ArcSegment(start, midpt, end);
            }
        } else {
            seg = new StraightSegment(start, end);
        }
        segs.add(seg);
        start = end;
    }
    if (closeIt && !points[from].equals2D(points[to - 1])) {
        segs.add(new StraightSegment(points[to - 1], points[from]));
    }
    return fact.createCompoundCurve(segs);
}
Also used : ArcSegment(ch.interlis.iom_j.itf.impl.jtsext.geom.ArcSegment) CurveSegment(ch.interlis.iom_j.itf.impl.jtsext.geom.CurveSegment) Coordinate(com.vividsolutions.jts.geom.Coordinate) ArrayList(java.util.ArrayList) StraightSegment(ch.interlis.iom_j.itf.impl.jtsext.geom.StraightSegment)

Aggregations

ArcSegment (ch.interlis.iom_j.itf.impl.jtsext.geom.ArcSegment)1 CurveSegment (ch.interlis.iom_j.itf.impl.jtsext.geom.CurveSegment)1 StraightSegment (ch.interlis.iom_j.itf.impl.jtsext.geom.StraightSegment)1 Coordinate (com.vividsolutions.jts.geom.Coordinate)1 ArrayList (java.util.ArrayList)1