use of com.revolsys.geometry.model.GeometryFactory in project com.revolsys.open by revolsys.
the class LineStringTest method assertDistanceAlong.
private static void assertDistanceAlong(final double distanceAlong, final double distance, final double x, final double y, final Side side, final double... coordinates) {
final GeometryFactory geometryFactory = GeometryFactory.worldMercator().convertAxisCount(2);
final Point point = geometryFactory.point(x, y);
final LineString line = geometryFactory.lineString(2, coordinates);
final double actual = line.distanceAlong(point);
Assert.assertEquals("Distance Along", distanceAlong, actual, 0.0000001);
final PointLineStringMetrics metrics = line.getMetrics(point);
Assert.assertEquals("Metrics Distance Along", distanceAlong, metrics.getDistanceAlong(), 0.0000001);
Assert.assertEquals("Metrics Distance", distance, metrics.getDistance(), 0.0000001);
Assert.assertEquals("Metrics Side", side, metrics.getSide());
Assert.assertEquals("Metrics Length", line.getLength(), metrics.getLineLength(), 0.0000001);
Assert.assertEquals("Distance Along -> Metrics", distanceAlong, metrics.getDistanceAlong(), 0.0000001);
if (side != null) {
final Side reverseSide = Side.opposite(side);
final LineString reverseLine = line.reverse();
final PointLineStringMetrics reverseMetrics = reverseLine.getMetrics(point);
Assert.assertEquals("Reverse Metrics Side", reverseSide, reverseMetrics.getSide());
}
}
use of com.revolsys.geometry.model.GeometryFactory in project com.revolsys.open by revolsys.
the class LineStringTest method constructEmpty.
@Test
public void constructEmpty() {
for (int axisCount = 2; axisCount < 4; axisCount++) {
final GeometryFactory geometryFactory = GeometryFactory.fixed(26910, axisCount, GeometryFactory.newScalesFixed(axisCount, 1000.0));
// Empty Constructor
final LineString pointEmpty = geometryFactory.lineString();
assertEmpty(pointEmpty);
// Point[] Constructor
final LineString pointCoordinatesArrayNull = geometryFactory.lineString((Point[]) null);
assertEmpty(pointCoordinatesArrayNull);
final LineString pointCoordinatesArraySize0 = geometryFactory.lineString(new Point[0]);
assertEmpty(pointCoordinatesArraySize0);
final LineString pointCoordinatesNull = geometryFactory.lineString((Point) null);
assertEmpty(pointCoordinatesNull);
// LineString Constructor
final LineString pointCoordinatesListNull = geometryFactory.lineString((LineString) null);
assertEmpty(pointCoordinatesListNull);
final LineString pointCoordinatesListSize0 = geometryFactory.lineString(geometryFactory.lineString());
assertEmpty(pointCoordinatesListSize0);
// double[] Constructor
final LineString pointDoubleArray0Null = geometryFactory.lineString(0, (double[]) null);
assertEmpty(pointDoubleArray0Null);
final LineString pointDoubleArray2Null = geometryFactory.lineString(2, (double[]) null);
assertEmpty(pointDoubleArray2Null);
final LineString pointDoubleArray0NoValue = geometryFactory.lineString(0);
assertEmpty(pointDoubleArray0NoValue);
final LineString pointDoubleArray2NoValue = geometryFactory.lineString(2);
assertEmpty(pointDoubleArray2NoValue);
// LineString Constructor
final LineString pointLineStringNull = geometryFactory.lineString((LineString) null);
assertEmpty(pointLineStringNull);
}
}
use of com.revolsys.geometry.model.GeometryFactory in project com.revolsys.open by revolsys.
the class PointTest method assertEquals.
public static void assertEquals(final Point point, final double... coordinates) {
final GeometryFactory geometryFactory = point.getGeometryFactory();
final GeometryFactory geometryFactory2;
final int axisCount = geometryFactory.getAxisCount();
if (geometryFactory.getCoordinateSystem() instanceof ProjectedCoordinateSystem) {
final ProjectedCoordinateSystem projectedCs = (ProjectedCoordinateSystem) geometryFactory.getCoordinateSystem();
final GeographicCoordinateSystem geographicCoordinateSystem = projectedCs.getGeographicCoordinateSystem();
geometryFactory2 = GeometryFactory.floating(geographicCoordinateSystem.getCoordinateSystemId(), axisCount);
} else {
geometryFactory2 = GeometryFactory.floating(26910, axisCount);
}
assertCoordinatesEquals(point, coordinates);
final Point clone = point.newPoint();
assertCoordinatesEquals(clone, coordinates);
final Point converted = point.convertGeometry(geometryFactory);
assertCoordinatesEquals(converted, coordinates);
Assert.assertSame(point, converted);
final Point convertedOther = point.convertGeometry(geometryFactory2);
final Point convertedBack = convertedOther.convertGeometry(geometryFactory);
assertCoordinatesEquals(convertedBack, coordinates);
Assert.assertNotSame(point, convertedBack);
final Point copy = point.newGeometry(geometryFactory);
assertCoordinatesEquals(copy, coordinates);
Assert.assertNotSame(point, copy);
final Point copyOther = point.convertGeometry(geometryFactory2);
final Point copyBack = copyOther.convertGeometry(geometryFactory);
assertCoordinatesEquals(copyBack, coordinates);
Assert.assertNotSame(point, copyBack);
final String string = point.toString();
final Point pointString = geometryFactory.geometry(string);
assertCoordinatesEquals(pointString, coordinates);
final String wkt = point.toEwkt();
final Point pointWkt = geometryFactory.geometry(wkt);
assertCoordinatesEquals(pointWkt, coordinates);
}
use of com.revolsys.geometry.model.GeometryFactory in project com.revolsys.open by revolsys.
the class PointTest method constructEmpty.
@Test
public void constructEmpty() {
for (int axisCount = 2; axisCount < 4; axisCount++) {
final GeometryFactory geometryFactory = GeometryFactory.fixed(26910, axisCount, GeometryFactory.newScalesFixed(axisCount, 1000.0));
final Point pointEmpty = geometryFactory.point();
assertEmpty(pointEmpty);
final Point pointCoordinatesNull = geometryFactory.point((Point) null);
assertEmpty(pointCoordinatesNull);
final Point pointCoordinatesListNull = geometryFactory.point();
assertEmpty(pointCoordinatesListNull);
final Point pointObjectNull = geometryFactory.point((Object) null);
assertEmpty(pointObjectNull);
final Point pointDoubleArrayNull = geometryFactory.point((double[]) null);
assertEmpty(pointDoubleArrayNull);
final Point pointDoubleArraySize0 = geometryFactory.point(new double[0]);
assertEmpty(pointDoubleArraySize0);
final Point pointDoubleArraySize1 = geometryFactory.point(new double[1]);
assertEmpty(pointDoubleArraySize1);
}
}
use of com.revolsys.geometry.model.GeometryFactory in project com.revolsys.open by revolsys.
the class TestUtil method doTestGeometry.
public static void doTestGeometry(final Class<?> clazz, final String file) {
boolean valid = true;
final Resource resource = new ClassPathResource(file, clazz);
try (Reader<Record> reader = RecordReader.newRecordReader(resource)) {
int i = 0;
for (final Record object : reader) {
final int srid = object.getInteger("srid");
final int axisCount = object.getInteger("axisCount");
final double scaleXy = object.getInteger("scaleXy");
final double scaleZ = object.getInteger("scaleZ");
final double[] scales = { scaleXy, scaleXy, scaleZ };
final GeometryFactory geometryFactory = GeometryFactory.fixed(srid, axisCount, scales);
final String wkt = object.getValue("wkt");
final Geometry geometry = geometryFactory.geometry(wkt);
valid &= equalsExpectedWkt(i, object, geometry);
final CoordinateSystem coordinateSystem = geometry.getCoordinateSystem();
GeometryFactory otherGeometryFactory;
if (coordinateSystem instanceof ProjectedCoordinateSystem) {
final ProjectedCoordinateSystem projectedCoordinateSystem = (ProjectedCoordinateSystem) coordinateSystem;
otherGeometryFactory = GeometryFactory.fixed(projectedCoordinateSystem.getCoordinateSystemId(), axisCount, scales);
} else {
otherGeometryFactory = GeometryFactory.fixed(3005, axisCount, scales);
}
final Geometry convertedGeometry = geometry.convertGeometry(otherGeometryFactory);
final Geometry convertedBackGeometry = convertedGeometry.convertGeometry(geometryFactory);
valid &= equalsExpectedGeometry(i, convertedBackGeometry, geometry);
i++;
}
}
if (!valid) {
Assert.fail("Has Errors");
}
}
Aggregations