use of ca.nrc.cadc.caom2.types.SegmentType in project caom2db by opencadc.
the class PostgreSQLGenerator method getMultiPolygon.
@Override
protected MultiPolygon getMultiPolygon(ResultSet rs, int col) throws SQLException {
double[] coords = Util.getDoubleArray(rs, col);
if (coords == null) {
return null;
}
MultiPolygon ret = new MultiPolygon();
for (int i = 0; i < coords.length; i += 3) {
double cval1 = coords[i];
double cval2 = coords[i + 1];
int s = (int) coords[i + 2];
SegmentType t = SegmentType.toValue(s);
Vertex v = new Vertex(cval1, cval2, t);
ret.getVertices().add(v);
}
ret.validate();
return ret;
}
use of ca.nrc.cadc.caom2.types.SegmentType in project caom2db by opencadc.
the class PostgreSQLGeneratorTest method testCircleToPolygonApproximatiom.
@Test
public void testCircleToPolygonApproximatiom() {
try {
Circle c = new Circle(new Point(12.0, 34.0), 1.0);
double ca = c.getArea();
double cs = c.getSize();
for (int i = 4; i < 32; i += 2) {
ca.nrc.cadc.dali.Polygon dpoly = gen.generatePolygonApproximation(c, i);
List<Vertex> verts = new ArrayList<Vertex>();
List<Point> points = new ArrayList<Point>();
SegmentType t = SegmentType.MOVE;
for (ca.nrc.cadc.dali.Point dp : dpoly.getVertices()) {
points.add(new Point(dp.getLongitude(), dp.getLatitude()));
verts.add(new Vertex(dp.getLongitude(), dp.getLatitude(), t));
t = SegmentType.LINE;
}
verts.add(Vertex.CLOSE);
MultiPolygon mp = new MultiPolygon(verts);
Polygon poly = new Polygon(points, mp);
double pa = poly.getArea();
double ps = poly.getSize();
double da = pa / ca;
log.info("n=" + i + " poly: " + ps + " " + pa + " (" + da + ")");
}
log.info("circle: " + ca + " " + cs);
} catch (Exception unexpected) {
log.error("unexpected exception", unexpected);
Assert.fail("unexpected exception: " + unexpected);
}
}
Aggregations