Search in sources :

Example 1 with SVGPainter

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();
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeometryProperty(eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty) SVGPainter(eu.esdihumboldt.util.svg.test.SVGPainter) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) ArrayList(java.util.ArrayList) Envelope(com.vividsolutions.jts.geom.Envelope) PaintSettings(eu.esdihumboldt.util.svg.test.PaintSettings) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) Polygon(com.vividsolutions.jts.geom.Polygon) Test(org.junit.Test) AbstractHandlerTest(eu.esdihumboldt.hale.io.gml.geometry.handler.internal.AbstractHandlerTest) Stories(ru.yandex.qatools.allure.annotations.Stories)

Example 2 with SVGPainter

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();
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeometryProperty(eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty) SVGPainter(eu.esdihumboldt.util.svg.test.SVGPainter) Instance(eu.esdihumboldt.hale.common.instance.model.Instance) InstanceCollection(eu.esdihumboldt.hale.common.instance.model.InstanceCollection) ArrayList(java.util.ArrayList) Envelope(com.vividsolutions.jts.geom.Envelope) PaintSettings(eu.esdihumboldt.util.svg.test.PaintSettings) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) Polygon(com.vividsolutions.jts.geom.Polygon) Test(org.junit.Test) AbstractHandlerTest(eu.esdihumboldt.hale.io.gml.geometry.handler.internal.AbstractHandlerTest) Stories(ru.yandex.qatools.allure.annotations.Stories)

Example 3 with SVGPainter

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);
}
Also used : Arc(eu.esdihumboldt.util.geometry.interpolation.model.Arc) SVGPainter(eu.esdihumboldt.util.svg.test.SVGPainter) Envelope(com.vividsolutions.jts.geom.Envelope) PaintSettings(eu.esdihumboldt.util.svg.test.PaintSettings)

Example 4 with SVGPainter

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));
}
Also used : Path(java.nio.file.Path) SVGPainter(eu.esdihumboldt.util.svg.test.SVGPainter) Point(com.vividsolutions.jts.geom.Point) InteriorPoint(eu.esdihumboldt.cst.functions.geometric.interiorpoint.InteriorPoint) PaintSettings(eu.esdihumboldt.util.svg.test.PaintSettings) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) Polygon(com.vividsolutions.jts.geom.Polygon) Point(com.vividsolutions.jts.geom.Point) InteriorPoint(eu.esdihumboldt.cst.functions.geometric.interiorpoint.InteriorPoint)

Example 5 with SVGPainter

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);
}
Also used : SVGPainter(eu.esdihumboldt.util.svg.test.SVGPainter) Envelope(com.vividsolutions.jts.geom.Envelope) PaintSettings(eu.esdihumboldt.util.svg.test.PaintSettings)

Aggregations

PaintSettings (eu.esdihumboldt.util.svg.test.PaintSettings)5 SVGPainter (eu.esdihumboldt.util.svg.test.SVGPainter)5 Envelope (com.vividsolutions.jts.geom.Envelope)4 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)3 Polygon (com.vividsolutions.jts.geom.Polygon)3 Geometry (com.vividsolutions.jts.geom.Geometry)2 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)2 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)2 GeometryProperty (eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty)2 AbstractHandlerTest (eu.esdihumboldt.hale.io.gml.geometry.handler.internal.AbstractHandlerTest)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Stories (ru.yandex.qatools.allure.annotations.Stories)2 Point (com.vividsolutions.jts.geom.Point)1 InteriorPoint (eu.esdihumboldt.cst.functions.geometric.interiorpoint.InteriorPoint)1 Arc (eu.esdihumboldt.util.geometry.interpolation.model.Arc)1 Path (java.nio.file.Path)1