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());
}
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());
}
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());
}
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());
}
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;
}
Aggregations