Search in sources :

Example 6 with Polygon

use of de.micromata.opengis.kml.v_2_2_0.Polygon in project ddf by codice.

the class KMLTransformerImpl method createKmlGeo.

private Geometry createKmlGeo(com.vividsolutions.jts.geom.Geometry geo) throws CatalogTransformerException {
    Geometry kmlGeo = null;
    if (Point.class.getSimpleName().equals(geo.getGeometryType())) {
        Point jtsPoint = (Point) geo;
        kmlGeo = KmlFactory.createPoint().addToCoordinates(jtsPoint.getX(), jtsPoint.getY());
    } else if (LineString.class.getSimpleName().equals(geo.getGeometryType())) {
        LineString jtsLS = (LineString) geo;
        de.micromata.opengis.kml.v_2_2_0.LineString kmlLS = KmlFactory.createLineString();
        List<Coordinate> kmlCoords = kmlLS.createAndSetCoordinates();
        for (com.vividsolutions.jts.geom.Coordinate coord : jtsLS.getCoordinates()) {
            kmlCoords.add(new Coordinate(coord.x, coord.y));
        }
        kmlGeo = kmlLS;
    } else if (Polygon.class.getSimpleName().equals(geo.getGeometryType())) {
        Polygon jtsPoly = (Polygon) geo;
        de.micromata.opengis.kml.v_2_2_0.Polygon kmlPoly = KmlFactory.createPolygon();
        List<Coordinate> kmlCoords = kmlPoly.createAndSetOuterBoundaryIs().createAndSetLinearRing().createAndSetCoordinates();
        for (com.vividsolutions.jts.geom.Coordinate coord : jtsPoly.getCoordinates()) {
            kmlCoords.add(new Coordinate(coord.x, coord.y));
        }
        kmlGeo = kmlPoly;
    } else if (geo instanceof GeometryCollection) {
        List<Geometry> geos = new ArrayList<Geometry>();
        for (int xx = 0; xx < geo.getNumGeometries(); xx++) {
            geos.add(createKmlGeo(geo.getGeometryN(xx)));
        }
        kmlGeo = KmlFactory.createMultiGeometry().withGeometry(geos);
    } else {
        throw new CatalogTransformerException("Unknown / Unsupported Geometry Type '" + geo.getGeometryType() + "'. Unale to preform KML Transform.");
    }
    return kmlGeo;
}
Also used : CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) Point(com.vividsolutions.jts.geom.Point) Geometry(de.micromata.opengis.kml.v_2_2_0.Geometry) GeometryCollection(com.vividsolutions.jts.geom.GeometryCollection) LineString(com.vividsolutions.jts.geom.LineString) Coordinate(de.micromata.opengis.kml.v_2_2_0.Coordinate) List(java.util.List) ArrayList(java.util.ArrayList) Polygon(com.vividsolutions.jts.geom.Polygon)

Example 7 with Polygon

use of de.micromata.opengis.kml.v_2_2_0.Polygon in project java-mapollage by trixon.

the class Operation method addPolygon.

private void addPolygon(String name, ArrayList<Coordinate> coordinates, Folder polygonFolder) {
    List<Point2D.Double> inputs = new ArrayList<>();
    coordinates.forEach((coordinate) -> {
        inputs.add(new Point2D.Double(coordinate.getLongitude(), coordinate.getLatitude()));
    });
    try {
        List<Point2D.Double> convexHull = GrahamScan.getConvexHullDouble(inputs);
        Placemark placemark = polygonFolder.createAndAddPlacemark().withName(name);
        Style style = placemark.createAndAddStyle();
        LineStyle lineStyle = style.createAndSetLineStyle().withColor("00000000").withWidth(0.0);
        PolyStyle polyStyle = style.createAndSetPolyStyle().withColor("ccffffff").withColorMode(ColorMode.RANDOM);
        Polygon polygon = placemark.createAndSetPolygon();
        Boundary boundary = polygon.createAndSetOuterBoundaryIs();
        LinearRing linearRing = boundary.createAndSetLinearRing();
        convexHull.forEach((node) -> {
            linearRing.addToCoordinates(node.x, node.y);
        });
    } catch (IllegalArgumentException e) {
        System.err.println(e);
    }
}
Also used : ProfilePlacemark(se.trixon.mapollage.profile.ProfilePlacemark) Placemark(de.micromata.opengis.kml.v_2_2_0.Placemark) LineStyle(de.micromata.opengis.kml.v_2_2_0.LineStyle) ArrayList(java.util.ArrayList) PolyStyle(de.micromata.opengis.kml.v_2_2_0.PolyStyle) Boundary(de.micromata.opengis.kml.v_2_2_0.Boundary) Point2D(java.awt.geom.Point2D) LineStyle(de.micromata.opengis.kml.v_2_2_0.LineStyle) PolyStyle(de.micromata.opengis.kml.v_2_2_0.PolyStyle) Style(de.micromata.opengis.kml.v_2_2_0.Style) IconStyle(de.micromata.opengis.kml.v_2_2_0.IconStyle) BalloonStyle(de.micromata.opengis.kml.v_2_2_0.BalloonStyle) Polygon(de.micromata.opengis.kml.v_2_2_0.Polygon) LinearRing(de.micromata.opengis.kml.v_2_2_0.LinearRing)

Example 8 with Polygon

use of de.micromata.opengis.kml.v_2_2_0.Polygon in project java-mapollage by trixon.

the class Operation method addPolygons.

private void addPolygons(Folder polygonParent, List<Feature> features) {
    for (Feature feature : features) {
        if (feature instanceof Folder) {
            Folder folder = (Folder) feature;
            if (folder != mPathFolder && folder != mPathGapFolder && folder != mPolygonFolder) {
                System.out.println("ENTER FOLDER=" + folder.getName());
                System.out.println("PARENT FOLDER=" + polygonParent.getName());
                Folder polygonFolder = polygonParent.createAndAddFolder().withName(folder.getName()).withOpen(true);
                mFolderPolygonInputs.put(polygonFolder, new ArrayList<>());
                addPolygons(polygonFolder, folder.getFeature());
                System.out.println("POLYGON FOLDER=" + polygonFolder.getName() + " CONTAINS");
                if (mFolderPolygonInputs.get(polygonFolder) != null) {
                    addPolygon(folder.getName(), mFolderPolygonInputs.get(polygonFolder), polygonParent);
                }
                System.out.println("EXIT FOLDER=" + folder.getName());
                System.out.println("");
            }
        }
        if (feature instanceof Placemark) {
            Placemark placemark = (Placemark) feature;
            System.out.println("PLACEMARK=" + placemark.getName() + "(PARENT=)" + polygonParent.getName());
            Point point = (Point) placemark.getGeometry();
            point.getCoordinates().forEach((coordinate) -> {
                mFolderPolygonInputs.get(polygonParent).add(coordinate);
            });
        }
    }
}
Also used : ProfilePlacemark(se.trixon.mapollage.profile.ProfilePlacemark) Placemark(de.micromata.opengis.kml.v_2_2_0.Placemark) Point(de.micromata.opengis.kml.v_2_2_0.Point) Folder(de.micromata.opengis.kml.v_2_2_0.Folder) ProfileFolder(se.trixon.mapollage.profile.ProfileFolder) Feature(de.micromata.opengis.kml.v_2_2_0.Feature)

Example 9 with Polygon

use of de.micromata.opengis.kml.v_2_2_0.Polygon in project ddf by codice.

the class KmlLatLonBoxToJtsGeometryConverterTest method createKmlBoundingBoxCoordinates.

private static List<Coordinate> createKmlBoundingBoxCoordinates(double minX, double maxX, double minY, double maxY) {
    List<Coordinate> coordinates = new ArrayList<>();
    // This is the order that WKT wants the polygon
    // Starting Upper Right, moving clockwise
    coordinates.add(new Coordinate(maxX, maxY));
    coordinates.add(new Coordinate(maxX, minY));
    coordinates.add(new Coordinate(minX, minY));
    coordinates.add(new Coordinate(minX, maxY));
    coordinates.add(new Coordinate(maxX, maxY));
    return coordinates;
}
Also used : Coordinate(de.micromata.opengis.kml.v_2_2_0.Coordinate) ArrayList(java.util.ArrayList)

Example 10 with Polygon

use of de.micromata.opengis.kml.v_2_2_0.Polygon in project ddf by codice.

the class KmlToJtsGeometryConverterTest method testConvertPolygonGeometry.

@Test
public void testConvertPolygonGeometry() {
    InputStream stream = KmlToJtsGeometryConverterTest.class.getResourceAsStream("/kmlPolygon.kml");
    Kml kml = Kml.unmarshal(stream);
    assertThat(kml, notNullValue());
    Polygon kmlPolygon = ((Polygon) ((Placemark) kml.getFeature()).getGeometry());
    assertThat(kmlPolygon, notNullValue());
    org.locationtech.jts.geom.Geometry jtsGeometryPolygon = KmlToJtsGeometryConverter.from(kmlPolygon);
    assertThat(jtsGeometryPolygon, instanceOf(org.locationtech.jts.geom.Polygon.class));
    assertSpecificGeometry(kmlPolygon, jtsGeometryPolygon);
}
Also used : Placemark(de.micromata.opengis.kml.v_2_2_0.Placemark) InputStream(java.io.InputStream) Kml(de.micromata.opengis.kml.v_2_2_0.Kml) Polygon(de.micromata.opengis.kml.v_2_2_0.Polygon) Test(org.junit.Test)

Aggregations

Polygon (de.micromata.opengis.kml.v_2_2_0.Polygon)8 Test (org.junit.Test)5 Placemark (de.micromata.opengis.kml.v_2_2_0.Placemark)4 Coordinate (de.micromata.opengis.kml.v_2_2_0.Coordinate)3 Geometry (de.micromata.opengis.kml.v_2_2_0.Geometry)3 Kml (de.micromata.opengis.kml.v_2_2_0.Kml)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 LinearRing (de.micromata.opengis.kml.v_2_2_0.LinearRing)2 MultiGeometry (de.micromata.opengis.kml.v_2_2_0.MultiGeometry)2 ProfilePlacemark (se.trixon.mapollage.profile.ProfilePlacemark)2 GeometryCollection (com.vividsolutions.jts.geom.GeometryCollection)1 LineString (com.vividsolutions.jts.geom.LineString)1 Point (com.vividsolutions.jts.geom.Point)1 Polygon (com.vividsolutions.jts.geom.Polygon)1 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)1 BalloonStyle (de.micromata.opengis.kml.v_2_2_0.BalloonStyle)1 Boundary (de.micromata.opengis.kml.v_2_2_0.Boundary)1 Feature (de.micromata.opengis.kml.v_2_2_0.Feature)1 Folder (de.micromata.opengis.kml.v_2_2_0.Folder)1