Search in sources :

Example 1 with CurveSegment

use of org.opengis.geometry.primitive.CurveSegment in project geotoolkit by Geomatys.

the class GeometryParser method readLinearRingText.

/**
 * Creates a <code>Curve</code> using the next token in the stream.
 *
 * @param tokenizer tokenizer over a stream of text in Well-known Text
 *                  format. The next tokens must form a &lt;LineString Text&gt;.
 * @return a <code>Curve</code> specified by the next
 *         token in the stream
 * @throws IOException    if an I/O error occurs
 * @throws ParseException if the coordinates used to create the <code>Curve</code>
 *                        do not form a closed linestring, or if an unexpected token was
 *                        encountered
 */
private Curve readLinearRingText(final StreamTokenizer tokenizer) throws IOException, ParseException {
    List<Position> coordList = getCoordinates(tokenizer);
    LineString lineString = geometryFactory.createLineString(coordList);
    List<CurveSegment> curveSegmentList = Collections.singletonList((CurveSegment) lineString);
    return primitiveFactory.createCurve(curveSegmentList);
}
Also used : CurveSegment(org.opengis.geometry.primitive.CurveSegment) Position(org.opengis.geometry.coordinate.Position) DirectPosition(org.opengis.geometry.DirectPosition) LineString(org.opengis.geometry.coordinate.LineString)

Example 2 with CurveSegment

use of org.opengis.geometry.primitive.CurveSegment in project geotoolkit by Geomatys.

the class JTSMultiCurve method applyCRSonChild.

public void applyCRSonChild() {
    for (OrientableCurve child : getElements()) {
        if (child.getCoordinateReferenceSystem() == null && child instanceof JTSCurve) {
            JTSCurve childCurve = (JTSCurve) child;
            childCurve.setCoordinateReferenceSystem(getCoordinateReferenceSystem());
            for (CurveSegment cv : childCurve.getSegments()) {
                if (cv instanceof JTSLineString) {
                    ((JTSLineString) cv).setCoordinateReferenceSystem(getCoordinateReferenceSystem());
                    ((JTSLineString) cv).applyCRSOnChild();
                }
            }
        }
    }
}
Also used : CurveSegment(org.opengis.geometry.primitive.CurveSegment) OrientableCurve(org.opengis.geometry.primitive.OrientableCurve) JTSCurve(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSCurve) JTSLineString(org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString)

Example 3 with CurveSegment

use of org.opengis.geometry.primitive.CurveSegment in project geotoolkit by Geomatys.

the class IntersectionTest method testEdgeIntersection.

@Test
public void testEdgeIntersection() {
    DirectPosition[] pointsA = new DirectPosition[4];
    pointsA[0] = createDirectPosition(0.0, 0.0);
    pointsA[1] = createDirectPosition(1.0, 0.0);
    pointsA[2] = createDirectPosition(0.0, 1.0);
    pointsA[3] = createDirectPosition(0.0, 0.0);
    DirectPosition[] pointsB = new DirectPosition[4];
    pointsB[0] = createDirectPosition(1.0, 0.0);
    pointsB[1] = createDirectPosition(1.0, 1.0);
    pointsB[2] = createDirectPosition(0.0, 1.0);
    pointsB[3] = createDirectPosition(1.0, 0.0);
    Surface sA = createSurface(pointsA);
    assertEquals(0.5, sA.getArea(), 1.0e-8);
    assertEquals(1.0 + 1.0 + Math.sqrt(2.0), sA.getPerimeter(), 0.0);
    Surface sB = createSurface(pointsB);
    assertEquals(0.5, sB.getArea(), 1.0e-8);
    assertEquals(1.0 + 1.0 + Math.sqrt(2.0), sB.getPerimeter(), 0.0);
    TransfiniteSet result = sA.intersection(sB);
    assertTrue("result was a " + result.getClass().getSimpleName(), result instanceof CurveSegment);
    CurveSegment curveResult = (CurveSegment) result;
    assertEquals(0.0, curveResult.getStartParam(), 1.0e-8);
// TODO
// assertEquals(Math.sqrt(2.0), curveResult.getEndParam(), 1.0e-8);
}
Also used : DirectPosition(org.opengis.geometry.DirectPosition) CurveSegment(org.opengis.geometry.primitive.CurveSegment) TransfiniteSet(org.opengis.geometry.TransfiniteSet) Surface(org.opengis.geometry.primitive.Surface) Test(org.junit.Test)

Example 4 with CurveSegment

use of org.opengis.geometry.primitive.CurveSegment 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 5 with CurveSegment

use of org.opengis.geometry.primitive.CurveSegment in project geotoolkit by Geomatys.

the class JTSCurve method toString.

@Override
public String toString() {
    StringBuilder sb = new StringBuilder(super.toString());
    sb.append("segments:");
    if (!curveSegments.isEmpty()) {
        sb.append("\n");
        for (CurveSegment seg : curveSegments) {
            sb.append(seg.toString()).append("\n");
        }
    }
    return sb.toString();
}
Also used : CurveSegment(org.opengis.geometry.primitive.CurveSegment)

Aggregations

CurveSegment (org.opengis.geometry.primitive.CurveSegment)14 DirectPosition (org.opengis.geometry.DirectPosition)7 Position (org.opengis.geometry.coordinate.Position)7 ArrayList (java.util.ArrayList)6 Ring (org.opengis.geometry.primitive.Ring)6 JTSLineString (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSLineString)5 PointArray (org.opengis.geometry.coordinate.PointArray)5 GeneralDirectPosition (org.apache.sis.geometry.GeneralDirectPosition)4 JTSCurve (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSCurve)4 LineString (org.opengis.geometry.coordinate.LineString)4 OrientableCurve (org.opengis.geometry.primitive.OrientableCurve)4 Primitive (org.opengis.geometry.primitive.Primitive)4 JTSPolygon (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.geometry.JTSPolygon)3 JTSRing (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSRing)3 Curve (org.opengis.geometry.primitive.Curve)3 SurfaceBoundary (org.opengis.geometry.primitive.SurfaceBoundary)3 List (java.util.List)2 JTSSurfaceBoundary (org.geotoolkit.geometry.isoonjts.spatialschema.geometry.primitive.JTSSurfaceBoundary)2 Test (org.junit.Test)2 DirectPosition2D (org.apache.sis.geometry.DirectPosition2D)1