Search in sources :

Example 1 with ArcString

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

the class GridInterpolationTest method gridInterpolationTest.

// utility methods
private LineString gridInterpolationTest(ArcString arcs, double maxPositionalError, boolean moveAllToGrid) throws IOException {
    GridInterpolation interpol = new GridInterpolation();
    Map<String, String> properties = new HashMap<>();
    if (moveAllToGrid) {
        properties.put(GridInterpolation.PARAMETER_MOVE_ALL_TO_GRID, "true");
    }
    interpol.configure(new GeometryFactory(), maxPositionalError, properties);
    LineString result = interpol.interpolateArcString(arcs);
    double gridSize = GridUtil.getGridSize(maxPositionalError);
    drawGridInterpolatedArcString(arcs, gridSize, result);
    // test interpolated geometry
    Coordinate[] coords = result.getCoordinates();
    for (int i = 0; i < coords.length; i++) {
        Coordinate c = coords[i];
        boolean checkGrid = moveAllToGrid;
        if (checkGrid) {
            // check if coordinate on grid
            GridUtilTest.checkOnGrid(c, gridSize);
        }
        // check if two coordinates are not the same
        if (i < coords.length - 1) {
            Coordinate c2 = coords[i + 1];
            assertNotEquals(MessageFormat.format("Subsequent coordinates are equal ({0} and {1})", c, c2), c, c2);
            if (checkGrid) {
                // better check is to compare difference in x and y based on
                // grid size
                boolean xDifferent = Math.abs(c2.x - c.x) > (gridSize / 2);
                boolean yDifferent = Math.abs(c2.y - c.y) > (gridSize / 2);
                assertTrue("Subsequent coordinates are equal", xDifferent || yDifferent);
            }
        }
    }
    return result;
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) HashMap(java.util.HashMap) LineString(com.vividsolutions.jts.geom.LineString) Coordinate(com.vividsolutions.jts.geom.Coordinate) ArcString(eu.esdihumboldt.util.geometry.interpolation.model.ArcString) LineString(com.vividsolutions.jts.geom.LineString) ArcByCenterPoint(eu.esdihumboldt.util.geometry.interpolation.model.ArcByCenterPoint)

Example 2 with ArcString

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

the class ArcStringHandler 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
    Coordinate[] coords = lineStringGeomProperty.getGeometry().getCoordinates();
    if (coords.length < 3) {
        throw new GeometryNotSupportedException("Arc string must be defined by at least three points");
    }
    List<Arc> arcs = new ArrayList<>();
    for (int i = 0; i < coords.length - 2; i += 3) {
        Arc arc = new ArcByPointsImpl(coords[i], coords[i + 1], coords[i + 2]);
        arcs.add(arc);
    }
    ArcString arcString = new ArcStringImpl(arcs);
    // get interpolation algorithm
    InterpolationAlgorithm interpol = InterpolationHelper.getInterpolation(reader, getGeometryFactory());
    LineString interpolatedArcString = interpol.interpolateArcString(arcString);
    if (interpolatedArcString == null) {
        log.error("ArcString could be not interpolated to Linestring");
        return null;
    }
    return new DefaultGeometryProperty<LineString>(lineStringGeomProperty.getCRSDefinition(), interpolatedArcString);
}
Also used : GeometryNotSupportedException(eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException) ArrayList(java.util.ArrayList) ArcString(eu.esdihumboldt.util.geometry.interpolation.model.ArcString) InterpolationAlgorithm(eu.esdihumboldt.util.geometry.interpolation.InterpolationAlgorithm) TypeConstraint(eu.esdihumboldt.hale.common.schema.model.TypeConstraint) ArcByPointsImpl(eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcByPointsImpl) Arc(eu.esdihumboldt.util.geometry.interpolation.model.Arc) DefaultGeometryProperty(eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty) LineString(com.vividsolutions.jts.geom.LineString) Coordinate(com.vividsolutions.jts.geom.Coordinate) ArcStringImpl(eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcStringImpl)

Example 3 with ArcString

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

the class SplitInterpolationTest method splitInterpolationTest.

// utility methods
private LineString splitInterpolationTest(ArcString arcs, double maxPositionalError) throws IOException {
    SplitInterpolation interpol = new SplitInterpolation();
    Map<String, String> properties = new HashMap<>();
    interpol.configure(new GeometryFactory(), maxPositionalError, properties);
    LineString result = interpol.interpolateArcString(arcs);
    drawInterpolatedArcString(arcs, result);
    // test interpolated geometry
    Coordinate[] coords = result.getCoordinates();
    for (int i = 0; i < coords.length; i++) {
        Coordinate c = coords[i];
        // check if two coordinates are not the same
        if (i < coords.length - 1) {
            Coordinate c2 = coords[i + 1];
            assertNotEquals(MessageFormat.format("Subsequent coordinates are equal ({0} and {1})", c, c2), c, c2);
        }
    }
    return result;
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) HashMap(java.util.HashMap) LineString(com.vividsolutions.jts.geom.LineString) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) ArcString(eu.esdihumboldt.util.geometry.interpolation.model.ArcString) ArcByCenterPoint(eu.esdihumboldt.util.geometry.interpolation.model.ArcByCenterPoint)

Aggregations

Coordinate (com.vividsolutions.jts.geom.Coordinate)3 LineString (com.vividsolutions.jts.geom.LineString)3 ArcString (eu.esdihumboldt.util.geometry.interpolation.model.ArcString)3 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)2 ArcByCenterPoint (eu.esdihumboldt.util.geometry.interpolation.model.ArcByCenterPoint)2 HashMap (java.util.HashMap)2 DefaultGeometryProperty (eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty)1 TypeConstraint (eu.esdihumboldt.hale.common.schema.model.TypeConstraint)1 GeometryNotSupportedException (eu.esdihumboldt.hale.io.gml.geometry.GeometryNotSupportedException)1 InterpolationAlgorithm (eu.esdihumboldt.util.geometry.interpolation.InterpolationAlgorithm)1 Arc (eu.esdihumboldt.util.geometry.interpolation.model.Arc)1 ArcByPointsImpl (eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcByPointsImpl)1 ArcStringImpl (eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcStringImpl)1 ArrayList (java.util.ArrayList)1