Search in sources :

Example 16 with Arc

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

the class CircleByCenterPointHandler 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;
    // 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);
        }
    }
    if (controlCoord != null && controlCoord.length != 0 && radius != 0) {
        CRSDefinition crsDef = GMLGeometryUtil.findCRS(instance);
        // create Arc representing a circle
        Arc arc = new ArcByCenterPointImpl(controlCoord[0], radius, Angle.fromDegrees(0), Angle.fromDegrees(0), true);
        // get interpolation algorithm
        InterpolationAlgorithm interpol = InterpolationHelper.getInterpolation(reader, getGeometryFactory());
        LineString interpolatedCircle = interpol.interpolateArc(arc);
        if (interpolatedCircle == null) {
            log.error("Circle could be not interpolated to Linestring");
            return null;
        }
        return new DefaultGeometryProperty<LineString>(crsDef, interpolatedCircle);
    }
    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(com.vividsolutions.jts.geom.Point) Arc(eu.esdihumboldt.util.geometry.interpolation.model.Arc) DefaultGeometryProperty(eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) ParseException(java.text.ParseException)

Example 17 with Arc

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

the class AbstractArcTest method drawInterpolatedArcString.

/**
 * Draw an interpolated arc string with debug information. Saves the
 * resulting drawing.
 *
 * @param arcs the arc string to draw
 * @param interpolated the interpolated geometry
 * @throws IOException if saving the drawing fails
 */
protected void drawInterpolatedArcString(ArcString arcs, LineString interpolated) throws IOException {
    withArcStringCanvas(arcs, svg -> {
        if (interpolated != null) {
            svg.setColor(Color.DARK_GRAY);
            for (Coordinate coord : interpolated.getCoordinates()) {
                svg.drawPoint(coord);
            }
        }
        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) Coordinate(com.vividsolutions.jts.geom.Coordinate)

Example 18 with Arc

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

the class GridInterpolationTest method testArcString.

@Test
public void testArcString() throws IOException {
    List<Arc> arcs = new ArrayList<>();
    arcs.add(new ArcByPointsImpl(new Coordinate(-3, 2), new Coordinate(-2, 4), new Coordinate(0, 4)));
    arcs.add(new ArcByPointsImpl(new Coordinate(0, 4), new Coordinate(2, 3), new Coordinate(4, 4)));
    arcs.add(new ArcByPointsImpl(new Coordinate(4, 4), new Coordinate(4, 6), new Coordinate(2, 6)));
    gridInterpolationTest(new ArcStringImpl(arcs), 0.1, false);
}
Also used : ArcByPointsImpl(eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcByPointsImpl) Arc(eu.esdihumboldt.util.geometry.interpolation.model.Arc) Coordinate(com.vividsolutions.jts.geom.Coordinate) ArrayList(java.util.ArrayList) ArcStringImpl(eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcStringImpl) AbstractArcTest(eu.esdihumboldt.util.geometry.interpolation.AbstractArcTest) Test(org.junit.Test)

Example 19 with Arc

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

the class GridInterpolationTest method testArcStringAllGrid.

@Test
public void testArcStringAllGrid() throws IOException {
    List<Arc> arcs = new ArrayList<>();
    arcs.add(new ArcByPointsImpl(new Coordinate(-3, 2), new Coordinate(-2, 4), new Coordinate(0, 4)));
    arcs.add(new ArcByPointsImpl(new Coordinate(0, 4), new Coordinate(2, 3), new Coordinate(4, 4)));
    arcs.add(new ArcByPointsImpl(new Coordinate(4, 4), new Coordinate(4, 6), new Coordinate(2, 6)));
    gridInterpolationTest(new ArcStringImpl(arcs), 0.1, true);
}
Also used : ArcByPointsImpl(eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcByPointsImpl) Arc(eu.esdihumboldt.util.geometry.interpolation.model.Arc) Coordinate(com.vividsolutions.jts.geom.Coordinate) ArrayList(java.util.ArrayList) ArcStringImpl(eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcStringImpl) AbstractArcTest(eu.esdihumboldt.util.geometry.interpolation.AbstractArcTest) Test(org.junit.Test)

Example 20 with Arc

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

the class GridInterpolationTest method testByPoints3.

@Test
public void testByPoints3() throws IOException {
    Arc arc = new ArcByPointsImpl(new Coordinate(4, 4), new Coordinate(4, 6), new Coordinate(2, 6));
    gridInterpolationTest(arc, 0.1, false);
}
Also used : ArcByPointsImpl(eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcByPointsImpl) Arc(eu.esdihumboldt.util.geometry.interpolation.model.Arc) Coordinate(com.vividsolutions.jts.geom.Coordinate) AbstractArcTest(eu.esdihumboldt.util.geometry.interpolation.AbstractArcTest) Test(org.junit.Test)

Aggregations

Arc (eu.esdihumboldt.util.geometry.interpolation.model.Arc)26 Coordinate (com.vividsolutions.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 LineString (com.vividsolutions.jts.geom.LineString)6 ArcByCenterPoint (eu.esdihumboldt.util.geometry.interpolation.model.ArcByCenterPoint)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 Point (com.vividsolutions.jts.geom.Point)2 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)2 CRSDefinition (eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition)2 ParseException (java.text.ParseException)2 Envelope (com.vividsolutions.jts.geom.Envelope)1 TypeConstraint (eu.esdihumboldt.hale.common.schema.model.TypeConstraint)1