Search in sources :

Example 1 with SuperLoop

use of org.twak.utils.collections.SuperLoop in project chordatlas by twak.

the class GMLReader method readGML3d.

public static LoopL<Point3d> readGML3d(File in, DefaultGeocentricCRS targetCS, CoordinateReferenceSystem sourceCS) {
    LoopL<Point3d> out = new LoopL();
    try {
        InputSource input = new InputSource(new FileInputStream(in));
        new GMLReader(input, targetCS, sourceCS) {

            Loop<Point3d> parent, poly;

            public void newPoly(String name) {
                parent = poly = new SuperLoop<Point3d>(name);
                out.add(poly);
            }

            @Override
            public void hole(int n) {
                poly = new Loop<Point3d>();
                parent.holes.add(poly);
            }

            public void addLine(double[] s, double[] e) {
                poly.append(new Point3d(s[0], s[1], s[2]));
            }
        };
    } catch (Throwable e) {
        e.printStackTrace();
    }
    System.out.println("found " + out.size() + " polygons ");
    return out;
}
Also used : Loop(org.twak.utils.collections.Loop) SuperLoop(org.twak.utils.collections.SuperLoop) InputSource(org.xml.sax.InputSource) Point3d(javax.vecmath.Point3d) SuperLoop(org.twak.utils.collections.SuperLoop) LoopL(org.twak.utils.collections.LoopL) LineString(com.vividsolutions.jts.geom.LineString) FileInputStream(java.io.FileInputStream)

Example 2 with SuperLoop

use of org.twak.utils.collections.SuperLoop in project chordatlas by twak.

the class GISGen method initGML.

public void initGML() {
    Closer<Point3d> closer = new Closer<>();
    LoopL<Point3d> polies = null;
    try {
        polies = GMLReader.readGML3d(Tweed.toWorkspace(new File(gmlFile)), DefaultGeocentricCRS.CARTESIAN, CRS.decode(crs));
    } catch (NoSuchAuthorityCodeException e) {
        e.printStackTrace();
        return;
    } catch (FactoryException e) {
        e.printStackTrace();
        return;
    }
    Optional<Gen> hg = tweed.frame.gens(HeightGen.class).stream().findAny();
    if (hg.isPresent())
        for (Loop<Point3d> poly : polies) {
            if (poly instanceof SuperLoop) {
                SuperLoop sl = ((SuperLoop) poly);
                sl.properties.putAll(((HeightGen) hg.get()).getProperties((String) sl.properties.get("name")));
            }
        }
    for (Loop<Point3d> poly : polies) {
        List<Point3d> points = new ArrayList();
        for (Pair<Point3d, Point3d> pair : poly.pairs()) {
            TweedSettings.settings.toOrigin.transform(pair.first());
            pair.first().y = 0;
            points.add(pair.first());
            lines.add(new Line3d(pair.first(), pair.second()));
        }
        if (TweedSettings.settings.flipFootprints)
            poly.reverse();
        closer.add(points.toArray(new Point3d[points.size()]));
    }
    createBlocks(closer, polies);
}
Also used : Closer(org.twak.viewTrace.Closer) Loop(org.twak.utils.collections.Loop) SuperLoop(org.twak.utils.collections.SuperLoop) NoSuchAuthorityCodeException(org.opengis.referencing.NoSuchAuthorityCodeException) FactoryException(org.opengis.referencing.FactoryException) SuperLoop(org.twak.utils.collections.SuperLoop) ArrayList(java.util.ArrayList) Line3d(org.twak.utils.geom.Line3d) Point3d(javax.vecmath.Point3d) File(java.io.File)

Aggregations

Point3d (javax.vecmath.Point3d)2 Loop (org.twak.utils.collections.Loop)2 SuperLoop (org.twak.utils.collections.SuperLoop)2 LineString (com.vividsolutions.jts.geom.LineString)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 ArrayList (java.util.ArrayList)1 FactoryException (org.opengis.referencing.FactoryException)1 NoSuchAuthorityCodeException (org.opengis.referencing.NoSuchAuthorityCodeException)1 LoopL (org.twak.utils.collections.LoopL)1 Line3d (org.twak.utils.geom.Line3d)1 Closer (org.twak.viewTrace.Closer)1 InputSource (org.xml.sax.InputSource)1