Search in sources :

Example 1 with ArcSegment

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

the class Iox2fgdb method writePoints.

private void writePoints(LineString line, boolean isCCW, java.util.ArrayList<Double> zv, double[] zMin, double[] zMax, int startPtIdx, java.util.List<Arc> arcs) {
    if (line instanceof CompoundCurve) {
        CompoundCurve polyline = (CompoundCurve) line;
        // start point
        {
            CurveSegment seg = polyline.getSegments().get(0);
            Coordinate coord = seg.getStartPoint();
            os.writeDouble(coord.x);
            os.writeDouble(coord.y);
            if (zv != null) {
                double z = coord.z;
                zv.add(z);
                if (z < zMin[0]) {
                    zMin[0] = z;
                }
                if (z > zMax[0]) {
                    zMax[0] = z;
                }
            }
        }
        int arcSegc = 0;
        for (int i = 0; i < polyline.getNumSegments(); i++) {
            CurveSegment seg = polyline.getSegments().get(i);
            if (seg instanceof ArcSegment) {
                arcSegc++;
                ArcSegment arcSeg = (ArcSegment) seg;
                Coordinate ip = arcSeg.getMidPoint();
                int flags = 0;
                // flags|=arcSeg.getSign()>0?0:EsriShpConstants.arcIsCCW;
                // flags|=EsriShpConstants.arcIsMinor; // arcSeg.getTheta()>Math.PI?0:EsriShpConstants.arcIsMinor;
                flags |= EsriShpConstants.arcDefinedIP;
                Arc arc = new Arc(startPtIdx + i, ip.x, ip.y, flags);
                arcs.add(arc);
            }
            Coordinate coord = seg.getEndPoint();
            os.writeDouble(coord.x);
            os.writeDouble(coord.y);
            if (zv != null) {
                double z = coord.z;
                zv.add(z);
                if (z < zMin[0]) {
                    zMin[0] = z;
                }
                if (z > zMax[0]) {
                    zMax[0] = z;
                }
            }
        }
        return;
    } else {
        for (Coordinate coord : line.getCoordinates()) {
            os.writeDouble(coord.x);
            os.writeDouble(coord.y);
            if (zv != null) {
                double z = coord.z;
                zv.add(z);
                if (z < zMin[0]) {
                    zMin[0] = z;
                }
                if (z > zMax[0]) {
                    zMax[0] = z;
                }
            }
        }
        return;
    }
}
Also used : ArcSegment(ch.interlis.iom_j.itf.impl.jtsext.geom.ArcSegment) CurveSegment(ch.interlis.iom_j.itf.impl.jtsext.geom.CurveSegment) CompoundCurve(ch.interlis.iom_j.itf.impl.jtsext.geom.CompoundCurve) Coordinate(com.vividsolutions.jts.geom.Coordinate)

Example 2 with ArcSegment

use of ch.interlis.iom_j.itf.impl.jtsext.geom.ArcSegment 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)2 CurveSegment (ch.interlis.iom_j.itf.impl.jtsext.geom.CurveSegment)2 Coordinate (com.vividsolutions.jts.geom.Coordinate)2 CompoundCurve (ch.interlis.iom_j.itf.impl.jtsext.geom.CompoundCurve)1 StraightSegment (ch.interlis.iom_j.itf.impl.jtsext.geom.StraightSegment)1 ArrayList (java.util.ArrayList)1