use of eu.esdihumboldt.util.svg.test.SVGPainter in project hale by halestudio.
the class SurfaceGeometryTest method testSurfaceArcsGml32_grid.
/**
* Test surface geometries read from a GML 3.2 file
*
* @throws Exception if an error occurs
*/
@Stories("Arcs")
@Test
public void testSurfaceArcsGml32_grid() throws Exception {
InstanceCollection instances = AbstractHandlerTest.loadXMLInstances(getClass().getResource("/data/gml/geom-gml32.xsd").toURI(), getClass().getResource("/data/surface/sample-surface-arcs.xml").toURI(), gridConfig);
// three instance expected
ResourceIterator<Instance> it = instances.iterator();
try {
List<GeometryProperty<?>> geoms = new ArrayList<>();
assertTrue("First sample feature missing", it.hasNext());
Instance instance1 = it.next();
geoms.addAll(checkSingleGeometry(instance1, null));
assertTrue("Second sample feature missing", it.hasNext());
Instance instance2 = it.next();
geoms.addAll(checkSingleGeometry(instance2, null));
assertTrue("Third sample feature missing", it.hasNext());
Instance instance3 = it.next();
geoms.addAll(checkSingleGeometry(instance3, null));
assertEquals("Unexpected number of geometries", 3, geoms.size());
Geometry geom1 = geoms.get(0).getGeometry();
Geometry geom2 = geoms.get(1).getGeometry();
Geometry geom3 = geoms.get(2).getGeometry();
Envelope envelope = new Envelope();
envelope.expandToInclude(geom1.getEnvelopeInternal());
envelope.expandToInclude(geom2.getEnvelopeInternal());
envelope.expandToInclude(geom3.getEnvelopeInternal());
PaintSettings settings = new PaintSettings(envelope, 1000, 10);
SVGPainter svg = new SVGPainter(settings);
svg.setColor(Color.BLACK);
svg.drawGeometry(geom1);
svg.setColor(Color.BLUE);
svg.drawGeometry(geom2);
svg.setColor(Color.RED);
svg.drawGeometry(geom3);
saveDrawing(svg);
// ensure that polygons could be created
assertTrue(Polygon.class.isAssignableFrom(geom1.getClass()));
assertTrue(Polygon.class.isAssignableFrom(geom2.getClass()));
assertTrue(Polygon.class.isAssignableFrom(geom3.getClass()));
// XXX how to test?
// assertTrue("Geometries intersect", geom1.touches(geom2));
// assertTrue("Geometries intersect", geom2.touches(geom3));
} finally {
it.close();
}
}
use of eu.esdihumboldt.util.svg.test.SVGPainter in project hale by halestudio.
the class SurfaceGeometryTest method testSurfaceArcsGml32.
/**
* Test surface geometries read from a GML 3.2 file
*
* @throws Exception if an error occurs
*/
@Stories("Arcs")
@Test
public void testSurfaceArcsGml32() throws Exception {
InstanceCollection instances = AbstractHandlerTest.loadXMLInstances(getClass().getResource("/data/gml/geom-gml32.xsd").toURI(), getClass().getResource("/data/surface/sample-surface-arcs.xml").toURI(), InterpolationConfigurations.segment(maxPositionalError));
// three instance expected
ResourceIterator<Instance> it = instances.iterator();
try {
List<GeometryProperty<?>> geoms = new ArrayList<>();
assertTrue("First sample feature missing", it.hasNext());
Instance instance1 = it.next();
geoms.addAll(checkSingleGeometry(instance1, null));
assertTrue("Second sample feature missing", it.hasNext());
Instance instance2 = it.next();
geoms.addAll(checkSingleGeometry(instance2, null));
assertTrue("Third sample feature missing", it.hasNext());
Instance instance3 = it.next();
geoms.addAll(checkSingleGeometry(instance3, null));
assertEquals("Unexpected number of geometries", 3, geoms.size());
Geometry geom1 = geoms.get(0).getGeometry();
Geometry geom2 = geoms.get(1).getGeometry();
Geometry geom3 = geoms.get(2).getGeometry();
Envelope envelope = new Envelope();
envelope.expandToInclude(geom1.getEnvelopeInternal());
envelope.expandToInclude(geom2.getEnvelopeInternal());
envelope.expandToInclude(geom3.getEnvelopeInternal());
PaintSettings settings = new PaintSettings(envelope, 1000, 10);
SVGPainter svg = new SVGPainter(settings);
svg.setColor(Color.BLACK);
svg.drawGeometry(geom1);
svg.setColor(Color.BLUE);
svg.drawGeometry(geom2);
svg.setColor(Color.RED);
svg.drawGeometry(geom3);
saveDrawing(svg);
// ensure that polygons could be created
assertTrue(Polygon.class.isAssignableFrom(geom1.getClass()));
assertTrue(Polygon.class.isAssignableFrom(geom2.getClass()));
assertTrue(Polygon.class.isAssignableFrom(geom3.getClass()));
// XXX how to test?
// intersection area cannot be computed
// double interArea1 = geom1.intersection(geom2).getArea();
// double interArea2 = geom2.intersection(geom3).getArea();
} finally {
it.close();
}
}
use of eu.esdihumboldt.util.svg.test.SVGPainter in project hale by halestudio.
the class AbstractArcTest method withArcStringCanvas.
/**
* Prepare a canvas to draw an arc, perform the given draw operation and
* save the drawing.
*
* @param arcs the arc string to draw
* @param draw function that draws on the canvas
* @throws IOException if saving the drawing fails
*/
protected void withArcStringCanvas(ArcString arcs, Consumer<SVGPainter> draw) throws IOException {
Envelope envelope = new Envelope();
for (Arc arc : arcs.getArcs()) {
envelope.expandToInclude(getArcEnvelope(arc));
}
PaintSettings settings = new PaintSettings(envelope, 1000, 10);
SVGPainter svg = new SVGPainter(settings);
svg.setCanvasSize(1000, 1000);
draw.accept(svg);
saveDrawing("arc-string", svg);
}
use of eu.esdihumboldt.util.svg.test.SVGPainter in project hale by halestudio.
the class InteriorPointTest method testPointWithin.
@SuppressWarnings("javadoc")
protected void testPointWithin(MultiPolygon geometry) throws Exception {
Point point = null;
Exception storedException = null;
try {
point = calculatePoint(geometry);
} catch (Exception e) {
storedException = e;
}
if (GEN_IMAGES) {
/*
* Stuff related to SVG commented out because of issues with
* dependencies in test product.
*/
PaintSettings settings = new PaintSettings(geometry.getEnvelopeInternal(), MAX_SIZE, POINT_SIZE);
SVGPainter g = new SVGPainter(settings);
Path file = File.createTempFile("pointwithin", ".svg").toPath();
// draw polygon
g.setColor(Color.BLACK);
g.setStroke(2.0f);
for (int i = 0; i < geometry.getNumGeometries(); i++) {
Polygon polygon = (Polygon) geometry.getGeometryN(i);
g.drawPolygon(polygon);
}
// draw centroid as reference
Point centroid = geometry.getCentroid();
g.setColor(Color.BLUE);
g.drawPoint(centroid);
// draw point
if (point != null) {
g.setColor(Color.RED);
g.drawPoint(point);
}
g.writeToFile(file);
System.out.println("Test graphic written to " + file);
}
if (storedException != null) {
throw storedException;
}
assertNotNull(point);
assertTrue("Point is not contained in the polygon", point.within(geometry));
}
use of eu.esdihumboldt.util.svg.test.SVGPainter in project hale by halestudio.
the class AbstractArcTest method withArcCanvas.
/**
* Prepare a canvas to draw an arc, perform the given draw operation and
* save the drawing.
*
* @param arc the arc to draw
* @param draw function that draws on the canvas
* @throws IOException if saving the drawing fails
*/
protected void withArcCanvas(Arc arc, Consumer<SVGPainter> draw) throws IOException {
Envelope envelope = getArcEnvelope(arc);
PaintSettings settings = new PaintSettings(envelope, 1000, 10);
SVGPainter svg = new SVGPainter(settings);
svg.setCanvasSize(1000, 1000);
draw.accept(svg);
saveDrawing("arc", svg);
}
Aggregations