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;
}
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);
}
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;
}
Aggregations