Search in sources :

Example 1 with CompoundCurve

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

the class Iox2fgdb method asOneLine.

private LineString asOneLine(LineString polyline) {
    if (!(polyline instanceof CompoundCurveRing)) {
        return polyline;
    }
    ArrayList<CurveSegment> segments = new ArrayList<CurveSegment>();
    for (CompoundCurve curve : ((CompoundCurveRing) polyline).getLines()) {
        segments.addAll(curve.getSegments());
    }
    CompoundCurve line = new CompoundCurve(segments, polyline.getFactory());
    return line;
}
Also used : CurveSegment(ch.interlis.iom_j.itf.impl.jtsext.geom.CurveSegment) CompoundCurve(ch.interlis.iom_j.itf.impl.jtsext.geom.CompoundCurve) ArrayList(java.util.ArrayList) CompoundCurveRing(ch.interlis.iom_j.itf.impl.jtsext.geom.CompoundCurveRing)

Example 2 with CompoundCurve

use of ch.interlis.iom_j.itf.impl.jtsext.geom.CompoundCurve 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 3 with CompoundCurve

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

the class Iox2gpkg method polyline2wkb.

/**
 * Converts a POLYLINE to a JTS CoordinateList.
 * @param polylineObj INTERLIS POLYLINE structure
 * @param isSurfaceOrArea true if called as part of a SURFACE conversion.
 * @param p maximum stroke to use when removing ARCs
 * @return JTS CoordinateList
 * @throws Iox2wkbException
 */
public byte[] polyline2wkb(IomObject obj, boolean isSurfaceOrArea, boolean asCompoundCurve, double p, int srsId) throws Iox2wkbException {
    if (obj == null) {
        return null;
    }
    try {
        os.reset();
        CompoundCurve surface = Iox2jtsext.polyline2JTS(obj, false, p);
        writeGeoPackageBinaryHeader(srsId, surface.getEnvelopeInternal());
        // wkb
        Iox2wkb helper = new Iox2wkb(outputDimension, os.order());
        os.write(helper.polyline2wkb(obj, isSurfaceOrArea, asCompoundCurve, p));
    } catch (IOException e) {
        throw new RuntimeException("Unexpected IO exception: " + e.getMessage());
    } catch (IoxException e) {
        throw new RuntimeException("Unexpected exception: " + e.getMessage());
    }
    return os.toByteArray();
}
Also used : CompoundCurve(ch.interlis.iom_j.itf.impl.jtsext.geom.CompoundCurve) Iox2wkb(ch.interlis.iox_j.wkb.Iox2wkb) IOException(java.io.IOException) IoxException(ch.interlis.iox.IoxException)

Example 4 with CompoundCurve

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

the class Iox2gpkg method multiline2wkb.

public byte[] multiline2wkb(IomObject obj, boolean asCompoundCurve, double p, int srsId) throws Iox2wkbException {
    if (obj == null) {
        return null;
    }
    try {
        os.reset();
        int polylinec = obj.getattrvaluecount(Wkb2iox.ATTR_POLYLINE);
        Envelope env = new Envelope();
        for (int polylinei = 0; polylinei < polylinec; polylinei++) {
            IomObject polyline = obj.getattrobj(Wkb2iox.ATTR_POLYLINE, polylinei);
            CompoundCurve curve = Iox2jtsext.polyline2JTS(polyline, false, p);
            env.expandToInclude(curve.getEnvelopeInternal());
        }
        writeGeoPackageBinaryHeader(srsId, env);
        Iox2wkb helper = new Iox2wkb(outputDimension, os.order());
        for (int polylinei = 0; polylinei < polylinec; polylinei++) {
            IomObject polyline = obj.getattrobj(Wkb2iox.ATTR_POLYLINE, polylinei);
            os.write(helper.polyline2wkb(polyline, false, asCompoundCurve, p));
        }
    } catch (IOException e) {
        throw new RuntimeException("Unexpected IO exception: " + e.getMessage());
    } catch (IoxException e) {
        throw new RuntimeException("Unexpected exception: " + e.getMessage());
    }
    return os.toByteArray();
}
Also used : IomObject(ch.interlis.iom.IomObject) CompoundCurve(ch.interlis.iom_j.itf.impl.jtsext.geom.CompoundCurve) Iox2wkb(ch.interlis.iox_j.wkb.Iox2wkb) IOException(java.io.IOException) Envelope(com.vividsolutions.jts.geom.Envelope) IoxException(ch.interlis.iox.IoxException)

Example 5 with CompoundCurve

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

the class Iox2fgdb method multiline2wkb.

public byte[] multiline2wkb(IomObject obj, boolean asCompoundCurve, double p, int srsId) throws IoxException {
    if (obj == null) {
        return null;
    }
    os.reset();
    int polylinec = obj.getattrvaluecount(Wkb2iox.ATTR_POLYLINE);
    if (asCompoundCurve) {
        int shapeType = EsriShpConstants.ShapeGeneralPolyline;
        shapeType |= EsriShpConstants.shapeHasCurves;
        shapeType |= (outputDimension == 3 ? EsriShpConstants.shapeHasZs : 0);
        os.writeInt(shapeType);
    } else {
        if (outputDimension == 3) {
            os.writeInt(EsriShpConstants.ShapePolylineZ);
        } else {
            os.writeInt(EsriShpConstants.ShapePolyline);
        }
    }
    java.util.ArrayList<CompoundCurve> curves = new java.util.ArrayList<CompoundCurve>();
    // boundingBox
    Envelope env = new Envelope();
    for (int polylinei = 0; polylinei < polylinec; polylinei++) {
        IomObject polyline = obj.getattrobj(Wkb2iox.ATTR_POLYLINE, polylinei);
        CompoundCurve curve = Iox2jtsext.polyline2JTS(polyline, false, p);
        curves.add(curve);
        env.expandToInclude(curve.getEnvelopeInternal());
    }
    os.writeDouble(env.getMinX());
    os.writeDouble(env.getMinY());
    os.writeDouble(env.getMaxX());
    os.writeDouble(env.getMaxY());
    // cParts The number of Lines in the Multiline.
    // cPoints The total number of points for all lines.
    int cPart = curves.size();
    int cPoints = 0;
    for (CompoundCurve curve : curves) {
        cPoints += getNumPoints(curve);
    }
    os.writeInt(cPart);
    os.writeInt(cPoints);
    // parts[cParts] An array of length NumParts. Stores, for each Line, the index of its
    // first point in the points array. Array indexes are with respect to 0.
    int partStart = 0;
    for (CompoundCurve curve : curves) {
        os.writeInt(partStart);
        partStart += getNumPoints(curve);
    }
    java.util.ArrayList<Arc> arcs = null;
    if (asCompoundCurve) {
        arcs = new java.util.ArrayList<Arc>();
    }
    java.util.ArrayList<Double> zv = null;
    if (outputDimension == 3) {
        zv = new java.util.ArrayList<Double>();
    }
    double[] zMin = new double[1];
    double[] zMax = new double[1];
    {
        Coordinate coord = curves.get(0).getStartPoint().getCoordinate();
        if (outputDimension == 3) {
            zMin[0] = coord.z;
            zMax[0] = coord.z;
        }
    }
    int startPtIdx = 0;
    for (CompoundCurve curve : curves) {
        writePoints(curve, true, zv, zMin, zMax, startPtIdx, arcs);
        startPtIdx += getNumPoints(curve);
    }
    if (outputDimension == 3) {
        // zMin
        os.writeDouble(zMin[0]);
        // zMax
        os.writeDouble(zMax[0]);
        // Zs[cPoints]
        for (Double z : zv) {
            os.writeDouble(z);
        }
    }
    if (asCompoundCurve) {
        writeArcs(arcs);
    }
    return os.toByteArray();
}
Also used : CompoundCurve(ch.interlis.iom_j.itf.impl.jtsext.geom.CompoundCurve) ArrayList(java.util.ArrayList) Envelope(com.vividsolutions.jts.geom.Envelope) IomObject(ch.interlis.iom.IomObject) Coordinate(com.vividsolutions.jts.geom.Coordinate)

Aggregations

CompoundCurve (ch.interlis.iom_j.itf.impl.jtsext.geom.CompoundCurve)6 Coordinate (com.vividsolutions.jts.geom.Coordinate)3 Envelope (com.vividsolutions.jts.geom.Envelope)3 IomObject (ch.interlis.iom.IomObject)2 CurveSegment (ch.interlis.iom_j.itf.impl.jtsext.geom.CurveSegment)2 IoxException (ch.interlis.iox.IoxException)2 Iox2wkb (ch.interlis.iox_j.wkb.Iox2wkb)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ArcSegment (ch.interlis.iom_j.itf.impl.jtsext.geom.ArcSegment)1 CompoundCurveRing (ch.interlis.iom_j.itf.impl.jtsext.geom.CompoundCurveRing)1