Search in sources :

Example 1 with SegmentType

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;
}
Also used : SegmentType(ca.nrc.cadc.caom2.types.SegmentType) Vertex(ca.nrc.cadc.caom2.types.Vertex) MultiPolygon(ca.nrc.cadc.caom2.types.MultiPolygon) PgSpoint(ca.nrc.cadc.dali.postgresql.PgSpoint) Point(ca.nrc.cadc.caom2.types.Point)

Example 2 with SegmentType

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);
    }
}
Also used : Circle(ca.nrc.cadc.caom2.types.Circle) Vertex(ca.nrc.cadc.caom2.types.Vertex) ArrayList(java.util.ArrayList) Point(ca.nrc.cadc.caom2.types.Point) Point(ca.nrc.cadc.caom2.types.Point) SegmentType(ca.nrc.cadc.caom2.types.SegmentType) MultiPolygon(ca.nrc.cadc.caom2.types.MultiPolygon) MultiPolygon(ca.nrc.cadc.caom2.types.MultiPolygon) Polygon(ca.nrc.cadc.caom2.types.Polygon) Test(org.junit.Test)

Aggregations

MultiPolygon (ca.nrc.cadc.caom2.types.MultiPolygon)2 Point (ca.nrc.cadc.caom2.types.Point)2 SegmentType (ca.nrc.cadc.caom2.types.SegmentType)2 Vertex (ca.nrc.cadc.caom2.types.Vertex)2 Circle (ca.nrc.cadc.caom2.types.Circle)1 Polygon (ca.nrc.cadc.caom2.types.Polygon)1 PgSpoint (ca.nrc.cadc.dali.postgresql.PgSpoint)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1