use of org.locationtech.jts.geom.LineString in project hale by halestudio.
the class CompositeCurveGeometryTest method testCompositeCurveGml32_mismatch.
/**
* Test composite curve geometries read from a GML 3.2 file
*
* @throws Exception if an error occurs
*/
@Test
public void testCompositeCurveGml32_mismatch() throws Exception {
InstanceCollection instances = AbstractHandlerTest.loadXMLInstances(getClass().getResource("/data/gml/geom-gml32.xsd").toURI(), getClass().getResource("/data/curve/sample-compositecurve-gml32_mismatch.xml").toURI());
LineString ls1 = geomFactory.createLineString(new Coordinate[] { new Coordinate(0, 0), new Coordinate(1, 1), new Coordinate(2, 2) });
LineString ls2 = geomFactory.createLineString(new Coordinate[] { new Coordinate(2, 3), new Coordinate(3, 1), new Coordinate(4, 0) });
LineString ls3 = geomFactory.createLineString(new Coordinate[] { new Coordinate(4, 0), new Coordinate(5, -1), new Coordinate(6, 0), new Coordinate(7, 2), new Coordinate(8, 4) });
MultiLineString separate = geomFactory.createMultiLineString(new LineString[] { ls1, ls2, ls3 });
// one instances expected
ResourceIterator<Instance> it = instances.iterator();
try {
// segments with LineStringSegment defined through coordinates
assertTrue("First sample feature missing", it.hasNext());
Instance instance = it.next();
checkSingleGeometry(instance, referenceChecker(separate));
} finally {
it.close();
}
}
use of org.locationtech.jts.geom.LineString in project hale by halestudio.
the class MultiLineStringGeometryTest method init.
@Override
public void init() {
super.init();
Coordinate[] coordinates = new Coordinate[] { new Coordinate(-39799.68820381, 273207.53980172), new Coordinate(-39841.185, 273182.863), new Coordinate(-39882.89, 273153.86) };
LineString linestring1 = geomFactory.createLineString(coordinates);
coordinates = new Coordinate[] { new Coordinate(-39799.8, 273207.7), new Coordinate(-39841.3, 273182.95), new Coordinate(-39882.99, 273153.99) };
LineString linestring2 = geomFactory.createLineString(coordinates);
LineString[] lines = new LineString[] { linestring1, linestring2 };
reference = geomFactory.createMultiLineString(lines);
checker = referenceChecker(reference);
gridChecker = combine(referenceChecker(reference, InterpolationHelper.DEFAULT_MAX_POSITION_ERROR), gridConfig.geometryChecker());
}
use of org.locationtech.jts.geom.LineString in project hale by halestudio.
the class GridInterpolationTest method gridInterpolationTest.
private LineString gridInterpolationTest(Arc arc, 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.interpolateArc(arc);
double gridSize = GridUtil.getGridSize(maxPositionalError);
drawGridInterpolatedArc(arc, gridSize, result);
// test interpolated geometry
Coordinate[] coords = result.getCoordinates();
for (int i = 0; i < coords.length; i++) {
Coordinate c = coords[i];
boolean checkGrid = moveAllToGrid || (!c.equals(arc.toArcByPoints().getStartPoint()) && !c.equals(arc.toArcByPoints().getMiddlePoint()) && !c.equals(arc.toArcByPoints().getEndPoint()));
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("Subsequent coordinates are equal", 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);
}
}
// check distance from center
double distance = arc.toArcByCenterPoint().getCenterPoint().distance(c);
double delta = Math.abs(distance - arc.toArcByCenterPoint().getRadius());
assertTrue(delta <= maxPositionalError);
}
return result;
}
use of org.locationtech.jts.geom.LineString in project hale by halestudio.
the class SplitInterpolationTest method splitInterpolationTest.
private LineString splitInterpolationTest(Arc arc, double maxPositionalError) throws IOException {
SplitInterpolation interpol = new SplitInterpolation();
Map<String, String> properties = new HashMap<>();
interpol.configure(new GeometryFactory(), maxPositionalError, properties);
LineString result = interpol.interpolateArc(arc);
drawInterpolatedArc(arc, result);
// test interpolated geometry
Coordinate[] coords = result.getCoordinates();
if (coords.length > 1 && arc instanceof ArcByPoints) {
// test start and end point
assertEquals(arc.toArcByPoints().getStartPoint(), coords[0]);
assertEquals(arc.toArcByPoints().getEndPoint(), coords[coords.length - 1]);
}
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("Subsequent coordinates are equal", c, c2);
}
// check distance from center
double distance = arc.toArcByCenterPoint().getCenterPoint().distance(c);
double delta = Math.abs(distance - arc.toArcByCenterPoint().getRadius());
assertTrue(delta <= maxPositionalError);
}
return result;
}
use of org.locationtech.jts.geom.LineString 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