Search in sources :

Example 1 with LineSegment

use of org.opengis.geometry.coordinate.LineSegment in project geotoolkit by Geomatys.

the class SurfaceImplTest method testLargeSurface.

/**
 * We need to create a large surface with 7000 points
 */
@Test
public void testLargeSurface() {
    int NUMBER = 100000;
    double delta = 360.0 / (double) NUMBER;
    PointArray points = postitionFactory.createPointArray();
    for (double angle = 0.0; angle < 360.0; angle += delta) {
        double[] coordinates = new double[] { Math.sin(Math.toRadians(angle)), Math.cos(Math.toRadians(angle)) };
        DirectPosition point = postitionFactory.createDirectPosition(coordinates);
        points.add(point);
    }
    List<OrientableCurve> curves = new ArrayList<OrientableCurve>();
    // A curve will be created
    // - The curve will be set as parent curves for the Curve segments
    // - Start and end params for the CurveSegments will be set
    List<CurveSegment> segmentList = new ArrayList<CurveSegment>();
    for (int i = 0; i < points.size(); i++) {
        int start = i;
        int end = (i + 1) % points.size();
        DirectPosition point1 = points.getDirectPosition(start, null);
        DirectPosition point2 = points.getDirectPosition(end, null);
        LineSegment segment = geometryFactory.createLineSegment(point1, point2);
        segmentList.add(segment);
    }
    Curve curve = primitiveFactory.createCurve(segmentList);
    curves.add(curve);
    Ring ring = primitiveFactory.createRing(curves);
    SurfaceBoundary boundary = primitiveFactory.createSurfaceBoundary(ring, new ArrayList());
    JTSSurface surface = (JTSSurface) primitiveFactory.createSurface(boundary);
    Geometry peer = surface.computeJTSPeer();
}
Also used : DirectPosition(org.opengis.geometry.DirectPosition) SurfaceBoundary(org.opengis.geometry.primitive.SurfaceBoundary) ArrayList(java.util.ArrayList) Curve(org.opengis.geometry.primitive.Curve) OrientableCurve(org.opengis.geometry.primitive.OrientableCurve) OrientableCurve(org.opengis.geometry.primitive.OrientableCurve) PointArray(org.opengis.geometry.coordinate.PointArray) Geometry(org.locationtech.jts.geom.Geometry) CurveSegment(org.opengis.geometry.primitive.CurveSegment) Ring(org.opengis.geometry.primitive.Ring) LineSegment(org.opengis.geometry.coordinate.LineSegment) Test(org.junit.Test)

Example 2 with LineSegment

use of org.opengis.geometry.coordinate.LineSegment in project sldeditor by robward-scisys.

the class WKTConversion method extractLineSegments.

/**
 * Extract line segments.
 *
 * @param curveImpl the curve impl
 * @param ptList the pt list
 */
private static void extractLineSegments(CurveImpl curveImpl, WKTSegmentList ptList) {
    for (LineSegment lineSegment : curveImpl.asLineSegments()) {
        WKTPoint startPoint = new WKTPoint(lineSegment.getStartPoint());
        WKTPoint endPoint = new WKTPoint(lineSegment.getEndPoint());
        ptList.addPoint(startPoint);
        ptList.addPoint(endPoint);
    }
    ptList.removeIfFirstLastSame();
}
Also used : LineSegment(org.opengis.geometry.coordinate.LineSegment)

Aggregations

LineSegment (org.opengis.geometry.coordinate.LineSegment)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 Geometry (org.locationtech.jts.geom.Geometry)1 DirectPosition (org.opengis.geometry.DirectPosition)1 PointArray (org.opengis.geometry.coordinate.PointArray)1 Curve (org.opengis.geometry.primitive.Curve)1 CurveSegment (org.opengis.geometry.primitive.CurveSegment)1 OrientableCurve (org.opengis.geometry.primitive.OrientableCurve)1 Ring (org.opengis.geometry.primitive.Ring)1 SurfaceBoundary (org.opengis.geometry.primitive.SurfaceBoundary)1