Search in sources :

Example 1 with JTSGeometryJ2D

use of org.geotoolkit.geometry.jts.awt.JTSGeometryJ2D in project geotoolkit by Geomatys.

the class PathIteratorTest method testPolygon.

@Test
public void testPolygon() {
    final LinearRing ring = GF.createLinearRing(new Coordinate[] { new Coordinate(3, 1), new Coordinate(7, 6), new Coordinate(5, 2), new Coordinate(3, 1) });
    final Polygon polygon = GF.createPolygon(ring, new LinearRing[0]);
    final Shape shape = new JTSGeometryJ2D(polygon);
    final PathIterator ite = shape.getPathIterator(null);
    double[] buffer = new double[2];
    int type;
    assertFalse(ite.isDone());
    type = ite.currentSegment(buffer);
    assertEquals(3, buffer[0], DELTA);
    assertEquals(1, buffer[1], DELTA);
    assertEquals(PathIterator.SEG_MOVETO, type);
    ite.next();
    assertFalse(ite.isDone());
    type = ite.currentSegment(buffer);
    assertEquals(7, buffer[0], DELTA);
    assertEquals(6, buffer[1], DELTA);
    assertEquals(PathIterator.SEG_LINETO, type);
    ite.next();
    assertFalse(ite.isDone());
    type = ite.currentSegment(buffer);
    assertEquals(5, buffer[0], DELTA);
    assertEquals(2, buffer[1], DELTA);
    assertEquals(PathIterator.SEG_LINETO, type);
    ite.next();
    assertFalse(ite.isDone());
    type = ite.currentSegment(buffer);
    assertEquals(PathIterator.SEG_CLOSE, type);
    ite.next();
    assertTrue(ite.isDone());
}
Also used : Shape(java.awt.Shape) Coordinate(org.locationtech.jts.geom.Coordinate) PathIterator(java.awt.geom.PathIterator) LinearRing(org.locationtech.jts.geom.LinearRing) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) JTSGeometryJ2D(org.geotoolkit.geometry.jts.awt.JTSGeometryJ2D) Point(org.locationtech.jts.geom.Point) Test(org.junit.Test)

Example 2 with JTSGeometryJ2D

use of org.geotoolkit.geometry.jts.awt.JTSGeometryJ2D in project geotoolkit by Geomatys.

the class PathIteratorTest method testPoint.

@Test
public void testPoint() {
    final Point point1 = GF.createPoint(new Coordinate(10, 20));
    final Shape shape = new JTSGeometryJ2D(point1);
    final PathIterator ite = shape.getPathIterator(null);
    double[] buffer = new double[2];
    int type;
    assertFalse(ite.isDone());
    type = ite.currentSegment(buffer);
    assertEquals(10, buffer[0], DELTA);
    assertEquals(20, buffer[1], DELTA);
    assertEquals(PathIterator.SEG_MOVETO, type);
    ite.next();
    assertTrue(ite.isDone());
}
Also used : Shape(java.awt.Shape) Coordinate(org.locationtech.jts.geom.Coordinate) PathIterator(java.awt.geom.PathIterator) Point(org.locationtech.jts.geom.Point) JTSGeometryJ2D(org.geotoolkit.geometry.jts.awt.JTSGeometryJ2D) Point(org.locationtech.jts.geom.Point) Test(org.junit.Test)

Example 3 with JTSGeometryJ2D

use of org.geotoolkit.geometry.jts.awt.JTSGeometryJ2D in project geotoolkit by Geomatys.

the class PathIteratorTest method testMultiPolygon.

@Test
public void testMultiPolygon() {
    final LinearRing ring1 = GF.createLinearRing(new Coordinate[] { new Coordinate(3, 1), new Coordinate(7, 6), new Coordinate(5, 2), new Coordinate(3, 1) });
    final LinearRing ring2 = GF.createLinearRing(new Coordinate[] { new Coordinate(12, 3), new Coordinate(1, 9), new Coordinate(4, 6), new Coordinate(12, 3) });
    final Polygon polygon1 = GF.createPolygon(ring1, new LinearRing[0]);
    final Polygon polygon2 = GF.createPolygon(ring2, new LinearRing[0]);
    final MultiPolygon poly = GF.createMultiPolygon(new Polygon[] { polygon1, polygon2 });
    final Shape shape = new JTSGeometryJ2D(poly);
    final PathIterator ite = shape.getPathIterator(null);
    double[] buffer = new double[2];
    int type;
    // first polygon
    assertFalse(ite.isDone());
    type = ite.currentSegment(buffer);
    assertEquals(3, buffer[0], DELTA);
    assertEquals(1, buffer[1], DELTA);
    assertEquals(PathIterator.SEG_MOVETO, type);
    ite.next();
    assertFalse(ite.isDone());
    type = ite.currentSegment(buffer);
    assertEquals(7, buffer[0], DELTA);
    assertEquals(6, buffer[1], DELTA);
    assertEquals(PathIterator.SEG_LINETO, type);
    ite.next();
    assertFalse(ite.isDone());
    type = ite.currentSegment(buffer);
    assertEquals(5, buffer[0], DELTA);
    assertEquals(2, buffer[1], DELTA);
    assertEquals(PathIterator.SEG_LINETO, type);
    ite.next();
    assertFalse(ite.isDone());
    type = ite.currentSegment(buffer);
    assertEquals(PathIterator.SEG_CLOSE, type);
    ite.next();
    // second polygon
    assertFalse(ite.isDone());
    type = ite.currentSegment(buffer);
    assertEquals(12, buffer[0], DELTA);
    assertEquals(3, buffer[1], DELTA);
    assertEquals(PathIterator.SEG_MOVETO, type);
    ite.next();
    assertFalse(ite.isDone());
    type = ite.currentSegment(buffer);
    assertEquals(1, buffer[0], DELTA);
    assertEquals(9, buffer[1], DELTA);
    assertEquals(PathIterator.SEG_LINETO, type);
    ite.next();
    assertFalse(ite.isDone());
    type = ite.currentSegment(buffer);
    assertEquals(4, buffer[0], DELTA);
    assertEquals(6, buffer[1], DELTA);
    assertEquals(PathIterator.SEG_LINETO, type);
    ite.next();
    assertFalse(ite.isDone());
    type = ite.currentSegment(buffer);
    assertEquals(PathIterator.SEG_CLOSE, type);
    ite.next();
    assertTrue(ite.isDone());
}
Also used : Shape(java.awt.Shape) Coordinate(org.locationtech.jts.geom.Coordinate) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) PathIterator(java.awt.geom.PathIterator) LinearRing(org.locationtech.jts.geom.LinearRing) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) JTSGeometryJ2D(org.geotoolkit.geometry.jts.awt.JTSGeometryJ2D) Point(org.locationtech.jts.geom.Point) Test(org.junit.Test)

Example 4 with JTSGeometryJ2D

use of org.geotoolkit.geometry.jts.awt.JTSGeometryJ2D in project geotoolkit by Geomatys.

the class PathIteratorTest method testMultiLineString2.

@Test
public void testMultiLineString2() throws ParseException {
    final WKTReader reader = new WKTReader();
    final Geometry geom = reader.read("MULTILINESTRING ((-5 0, 5 0), (355 0, 365 0), (-365 0, -355 0))");
    final JTSGeometryJ2D shape = new JTSGeometryJ2D(geom);
    final PathIterator ite = shape.getPathIterator(null);
    double[] buffer = new double[2];
    int type;
    assertFalse(ite.isDone());
    type = ite.currentSegment(buffer);
    assertEquals(-5, buffer[0], DELTA);
    assertEquals(0, buffer[1], DELTA);
    assertEquals(PathIterator.SEG_MOVETO, type);
    ite.next();
    assertFalse(ite.isDone());
    type = ite.currentSegment(buffer);
    assertEquals(5, buffer[0], DELTA);
    assertEquals(0, buffer[1], DELTA);
    assertEquals(PathIterator.SEG_LINETO, type);
    ite.next();
    assertFalse(ite.isDone());
    type = ite.currentSegment(buffer);
    assertEquals(355, buffer[0], DELTA);
    assertEquals(0, buffer[1], DELTA);
    assertEquals(PathIterator.SEG_MOVETO, type);
    ite.next();
    assertFalse(ite.isDone());
    type = ite.currentSegment(buffer);
    assertEquals(365, buffer[0], DELTA);
    assertEquals(0, buffer[1], DELTA);
    assertEquals(PathIterator.SEG_LINETO, type);
    ite.next();
    assertFalse(ite.isDone());
    type = ite.currentSegment(buffer);
    assertEquals(-365, buffer[0], DELTA);
    assertEquals(0, buffer[1], DELTA);
    assertEquals(PathIterator.SEG_MOVETO, type);
    ite.next();
    assertFalse(ite.isDone());
    type = ite.currentSegment(buffer);
    assertEquals(-355, buffer[0], DELTA);
    assertEquals(0, buffer[1], DELTA);
    assertEquals(PathIterator.SEG_LINETO, type);
    ite.next();
    assertTrue(ite.isDone());
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) PathIterator(java.awt.geom.PathIterator) WKTReader(org.locationtech.jts.io.WKTReader) JTSGeometryJ2D(org.geotoolkit.geometry.jts.awt.JTSGeometryJ2D) Point(org.locationtech.jts.geom.Point) Test(org.junit.Test)

Example 5 with JTSGeometryJ2D

use of org.geotoolkit.geometry.jts.awt.JTSGeometryJ2D in project geotoolkit by Geomatys.

the class LineSymbolizerRenderer method getShapes.

private Shape[] getShapes(ProjectedGeometry projectedGeometry, Object feature, float sizeCorrection) throws TransformException {
    final float offset = symbol.getOffset(feature, coeff) * sizeCorrection;
    final Shape[] j2dShapes;
    if (offset == 0) {
        j2dShapes = projectedGeometry.getDisplayShape();
    } else {
        final Geometry[] geoms = projectedGeometry.getDisplayGeometryJTS();
        j2dShapes = new Shape[geoms.length];
        for (int i = 0; i < geoms.length; i++) {
            Geometry g = geoms[i];
            if (g instanceof LineString) {
                g = LineStringTranslator.translateLineString((LineString) g, offset);
            } else if (g instanceof MultiLineString) {
                g = LineStringTranslator.translateLineString((MultiLineString) g, offset);
            }
            j2dShapes[i] = new JTSGeometryJ2D(g);
        // TODO : clip geometry
        }
    }
    return j2dShapes;
}
Also used : ProjectedGeometry(org.geotoolkit.display2d.primitive.ProjectedGeometry) Geometry(org.locationtech.jts.geom.Geometry) MultiLineString(org.locationtech.jts.geom.MultiLineString) Shape(java.awt.Shape) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) JTSGeometryJ2D(org.geotoolkit.geometry.jts.awt.JTSGeometryJ2D)

Aggregations

JTSGeometryJ2D (org.geotoolkit.geometry.jts.awt.JTSGeometryJ2D)12 Shape (java.awt.Shape)7 PathIterator (java.awt.geom.PathIterator)6 Geometry (org.locationtech.jts.geom.Geometry)6 Test (org.junit.Test)5 Coordinate (org.locationtech.jts.geom.Coordinate)5 Point (org.locationtech.jts.geom.Point)5 TransformException (org.opengis.referencing.operation.TransformException)4 ArrayList (java.util.ArrayList)3 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)3 Graphics2D (java.awt.Graphics2D)2 Rectangle (java.awt.Rectangle)2 AttributedString (java.text.AttributedString)2 DecimalFormat (java.text.DecimalFormat)2 GridGeometry (org.apache.sis.coverage.grid.GridGeometry)2 ExceptionPresentation (org.apache.sis.internal.map.ExceptionPresentation)2 Presentation (org.apache.sis.internal.map.Presentation)2 LineString (org.locationtech.jts.geom.LineString)2 LinearRing (org.locationtech.jts.geom.LinearRing)2 MultiLineString (org.locationtech.jts.geom.MultiLineString)2