Search in sources :

Example 1 with Arc

use of eu.esdihumboldt.util.geometry.interpolation.model.Arc in project hale by halestudio.

the class ArcByCenterPointHandler method createGeometry.

@Override
public Object createGeometry(Instance instance, int srsDimension, IOProvider reader) throws GeometryNotSupportedException {
    PointHandler handler = new PointHandler();
    // XXX support for different types of line strings in one instance (we
    // support only one type per instance!)
    Coordinate[] controlCoord = null;
    double radius = 0;
    double startAngle = 0;
    double endAngle = 0;
    // to parse coordinates of a line string
    // for use with GML 2, 3, 3.1, 3.2
    Collection<Object> values = PropertyResolver.getValues(instance, "coordinates", false);
    if (values != null && !values.isEmpty()) {
        Object value = values.iterator().next();
        if (value instanceof Instance) {
            try {
                controlCoord = GMLGeometryUtil.parseCoordinates((Instance) value);
            } catch (ParseException e) {
                throw new GeometryNotSupportedException("Could not parse coordinates", e);
            }
        }
    }
    // for use with GML 3, 3.2
    if (controlCoord == null || controlCoord.length == 0) {
        values = PropertyResolver.getValues(instance, "pos", false);
        if (values != null && !values.isEmpty()) {
            Iterator<Object> iterator = values.iterator();
            List<Coordinate> cs = new ArrayList<Coordinate>();
            while (iterator.hasNext()) {
                Object value = iterator.next();
                if (value instanceof Instance) {
                    Coordinate c = GMLGeometryUtil.parseDirectPosition((Instance) value);
                    if (c != null) {
                        cs.add(c);
                    }
                }
            }
            controlCoord = cs.toArray(new Coordinate[cs.size()]);
        }
    }
    // for use with GML 3.1, 3.2
    if (controlCoord == null || controlCoord.length == 0) {
        values = PropertyResolver.getValues(instance, "posList", false);
        if (values != null && !values.isEmpty()) {
            Iterator<Object> iterator = values.iterator();
            Object value = iterator.next();
            if (value instanceof Instance) {
                controlCoord = GMLGeometryUtil.parsePosList((Instance) value, srsDimension);
            }
        }
    }
    if (controlCoord == null || controlCoord.length == 0) {
        values = PropertyResolver.getValues(instance, "pointRep.Point", false);
        if (values != null && !values.isEmpty()) {
            Iterator<Object> iterator = values.iterator();
            List<Coordinate> cs = new ArrayList<Coordinate>();
            while (iterator.hasNext()) {
                Object value = iterator.next();
                if (value instanceof Instance) {
                    try {
                        @SuppressWarnings("unchecked") DefaultGeometryProperty<Point> point = (DefaultGeometryProperty<Point>) handler.createGeometry((Instance) value, srsDimension, reader);
                        cs.add(point.getGeometry().getCoordinate());
                    } catch (GeometryNotSupportedException e) {
                        throw new GeometryNotSupportedException("Could not parse Point Representation", e);
                    }
                }
            }
            controlCoord = cs.toArray(new Coordinate[cs.size()]);
        }
    }
    // for use with GML 3.1
    if (controlCoord == null || controlCoord.length == 0) {
        values = PropertyResolver.getValues(instance, "pointProperty.Point", false);
        if (values != null && !values.isEmpty()) {
            Iterator<Object> iterator = values.iterator();
            List<Coordinate> cs = new ArrayList<Coordinate>();
            while (iterator.hasNext()) {
                Object value = iterator.next();
                if (value instanceof Instance) {
                    try {
                        @SuppressWarnings("unchecked") DefaultGeometryProperty<Point> point = (DefaultGeometryProperty<Point>) handler.createGeometry((Instance) value, srsDimension, reader);
                        cs.add(point.getGeometry().getCoordinate());
                    } catch (GeometryNotSupportedException e) {
                        throw new GeometryNotSupportedException("Could not parse Point Property", e);
                    }
                }
            }
            controlCoord = cs.toArray(new Coordinate[cs.size()]);
        }
    }
    // for use with GML2, 3, 3.1, 3.2
    if (controlCoord == null || controlCoord.length == 0) {
        values = PropertyResolver.getValues(instance, "coord", false);
        if (values != null && !values.isEmpty()) {
            Iterator<Object> iterator = values.iterator();
            List<Coordinate> cs = new ArrayList<Coordinate>();
            while (iterator.hasNext()) {
                Object value = iterator.next();
                if (value instanceof Instance) {
                    Coordinate c = GMLGeometryUtil.parseCoord((Instance) value);
                    if (c != null) {
                        cs.add(c);
                    }
                }
            }
            controlCoord = cs.toArray(new Coordinate[cs.size()]);
        }
    }
    values = PropertyResolver.getValues(instance, "radius", false);
    if (values != null && !values.isEmpty()) {
        Object value = values.iterator().next();
        if (value instanceof Instance) {
            // ##TODO :: need to check with real time data
            radius = ConversionUtil.getAs(((Instance) value).getValue(), Double.class);
        }
    }
    values = PropertyResolver.getValues(instance, "startAngle", false);
    if (values != null && !values.isEmpty()) {
        Object value = values.iterator().next();
        if (value != null) {
            if (value instanceof Instance) {
                // ##TODO: handle if value comes in degree, minute and
                // second format. Need to check with real time data
                startAngle = ConversionUtil.getAs(((Instance) value).getValue(), Double.class);
            }
        }
    }
    values = PropertyResolver.getValues(instance, "endAngle", false);
    if (values != null && !values.isEmpty()) {
        Object value = values.iterator().next();
        if (value != null) {
            if (value instanceof Instance) {
                // ##TODO: handle if value comes in degree, minute and
                // second format. Need to check with real time data
                endAngle = ConversionUtil.getAs(((Instance) value).getValue(), Double.class);
            }
        }
    }
    if (controlCoord != null && controlCoord.length != 0 && radius != 0) {
        CRSDefinition crsDef = GMLGeometryUtil.findCRS(instance);
        // create Arc
        // FIXME verify how arc should be created from information in GML
        boolean clockwise = endAngle - startAngle < 0;
        Arc arc = new ArcByCenterPointImpl(controlCoord[0], radius, Angle.fromDegrees(startAngle), Angle.fromDegrees(endAngle), clockwise);
        // get interpolation algorithm
        InterpolationAlgorithm interpol = InterpolationHelper.getInterpolation(reader, getGeometryFactory());
        LineString interpolatedArc = interpol.interpolateArc(arc);
        if (interpolatedArc == null) {
            log.error("Arc could be not interpolated to Linestring");
            return null;
        }
        return new DefaultGeometryProperty<LineString>(crsDef, interpolatedArc);
    }
    throw new GeometryNotSupportedException();
}
Also used : Instance(eu.esdihumboldt.hale.common.instance.model.Instance) CRSDefinition(eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition) ArcByCenterPointImpl(eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcByCenterPointImpl) GeometryNotSupportedException(eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException) ArrayList(java.util.ArrayList) InterpolationAlgorithm(eu.esdihumboldt.util.geometry.interpolation.InterpolationAlgorithm) Point(org.locationtech.jts.geom.Point) Arc(eu.esdihumboldt.util.geometry.interpolation.model.Arc) DefaultGeometryProperty(eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty) Coordinate(org.locationtech.jts.geom.Coordinate) LineString(org.locationtech.jts.geom.LineString) ParseException(java.text.ParseException)

Example 2 with Arc

use of eu.esdihumboldt.util.geometry.interpolation.model.Arc in project hale by halestudio.

the class CircleHandler method createGeometry.

@Override
public Object createGeometry(Instance instance, int srsDimension, IOProvider reader) throws GeometryNotSupportedException {
    @SuppressWarnings("unchecked") DefaultGeometryProperty<LineString> lineStringGeomProperty = (DefaultGeometryProperty<LineString>) super.createGeometry(instance, srsDimension, reader);
    // create Arc for circle
    Coordinate[] coords = lineStringGeomProperty.getGeometry().getCoordinates();
    if (coords.length != 3) {
        throw new GeometryNotSupportedException("Arc must be defined by three points");
    }
    Arc arc = new ArcByPointsImpl(coords[0], coords[1], coords[2]);
    ArcByCenterPoint byCenter = arc.toArcByCenterPoint();
    ArcByCenterPoint circle = new ArcByCenterPointImpl(byCenter.getCenterPoint(), byCenter.getRadius(), byCenter.getStartAngle(), byCenter.getStartAngle(), byCenter.isClockwise());
    // get interpolation algorithm
    InterpolationAlgorithm interpol = InterpolationHelper.getInterpolation(reader, getGeometryFactory());
    LineString interpolatedCircle = interpol.interpolateArc(circle);
    if (interpolatedCircle == null) {
        log.error("Circle could be not interpolated to Linestring");
        return null;
    }
    return new DefaultGeometryProperty<LineString>(lineStringGeomProperty.getCRSDefinition(), interpolatedCircle);
}
Also used : ArcByPointsImpl(eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcByPointsImpl) ArcByCenterPoint(eu.esdihumboldt.util.geometry.interpolation.model.ArcByCenterPoint) Arc(eu.esdihumboldt.util.geometry.interpolation.model.Arc) DefaultGeometryProperty(eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty) LineString(org.locationtech.jts.geom.LineString) Coordinate(org.locationtech.jts.geom.Coordinate) ArcByCenterPointImpl(eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcByCenterPointImpl) GeometryNotSupportedException(eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException) InterpolationAlgorithm(eu.esdihumboldt.util.geometry.interpolation.InterpolationAlgorithm)

Example 3 with Arc

use of eu.esdihumboldt.util.geometry.interpolation.model.Arc 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(org.locationtech.jts.geom.Envelope) PaintSettings(eu.esdihumboldt.util.svg.test.PaintSettings)

Example 4 with Arc

use of eu.esdihumboldt.util.geometry.interpolation.model.Arc in project hale by halestudio.

the class AbstractArcTest method drawGridInterpolatedArcString.

/**
 * Draw an interpolated arc string with debug information. Saves the
 * resulting drawing.
 *
 * @param arcs the arc string to draw
 * @param gridSize the grid size
 * @param interpolated the interpolated geometry
 * @throws IOException if saving the drawing fails
 */
protected void drawGridInterpolatedArcString(ArcString arcs, double gridSize, LineString interpolated) throws IOException {
    withArcStringCanvas(arcs, svg -> {
        drawGrid(svg, gridSize);
        for (Arc arc : arcs.getArcs()) {
            drawArcWithMarkers(svg, arc);
        }
        if (interpolated != null) {
            svg.setColor(Color.BLACK);
            svg.setStroke(2.5f);
            svg.drawLineString(interpolated);
        }
    });
}
Also used : Arc(eu.esdihumboldt.util.geometry.interpolation.model.Arc)

Example 5 with Arc

use of eu.esdihumboldt.util.geometry.interpolation.model.Arc in project hale by halestudio.

the class GridInterpolationTest method testByPointsToCenterAllGrid.

@Test
public void testByPointsToCenterAllGrid() throws IOException {
    ArcByCenterPoint cbp = new ArcByPointsImpl(new Coordinate(0.01, 3.2), new Coordinate(3.33, 3.33), new Coordinate(0.01, -3.2)).toArcByCenterPoint();
    Arc arc = new ArcByCenterPointImpl(cbp.getCenterPoint(), cbp.getRadius(), Angle.fromDegrees(0), Angle.fromDegrees(0), false);
    gridInterpolationTest(arc, 0.1, true);
}
Also used : ArcByPointsImpl(eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcByPointsImpl) ArcByCenterPoint(eu.esdihumboldt.util.geometry.interpolation.model.ArcByCenterPoint) Arc(eu.esdihumboldt.util.geometry.interpolation.model.Arc) Coordinate(org.locationtech.jts.geom.Coordinate) ArcByCenterPointImpl(eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcByCenterPointImpl) AbstractArcTest(eu.esdihumboldt.util.geometry.interpolation.AbstractArcTest) Test(org.junit.Test)

Aggregations

Arc (eu.esdihumboldt.util.geometry.interpolation.model.Arc)26 Coordinate (org.locationtech.jts.geom.Coordinate)20 ArcByPointsImpl (eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcByPointsImpl)16 AbstractArcTest (eu.esdihumboldt.util.geometry.interpolation.AbstractArcTest)13 Test (org.junit.Test)13 ArcByCenterPointImpl (eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcByCenterPointImpl)8 ArrayList (java.util.ArrayList)7 ArcByCenterPoint (eu.esdihumboldt.util.geometry.interpolation.model.ArcByCenterPoint)6 LineString (org.locationtech.jts.geom.LineString)6 DefaultGeometryProperty (eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty)5 GeometryNotSupportedException (eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException)5 InterpolationAlgorithm (eu.esdihumboldt.util.geometry.interpolation.InterpolationAlgorithm)5 Angle (eu.esdihumboldt.util.geometry.interpolation.model.Angle)4 ArcStringImpl (eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcStringImpl)4 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)2 CRSDefinition (eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition)2 ParseException (java.text.ParseException)2 Point (org.locationtech.jts.geom.Point)2 TypeConstraint (eu.esdihumboldt.hale.common.schema.model.TypeConstraint)1 ArcString (eu.esdihumboldt.util.geometry.interpolation.model.ArcString)1