Search in sources :

Example 6 with Coordinate

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

the class KmlModelToJtsPointConverterTest method assertKmlModelToJtsPoint.

static void assertKmlModelToJtsPoint(Model kmlModel, Point jtsPoint) {
    assertThat(jtsPoint, notNullValue());
    Location location = kmlModel.getLocation();
    KmlToJtsCoordinateConverterTest.assertJtsCoordinatesFromKmlCoordinates(Collections.singletonList(new Coordinate(location.getLongitude(), location.getLatitude(), location.getAltitude())), jtsPoint.getCoordinates());
}
Also used : Coordinate(de.micromata.opengis.kml.v_2_2_0.Coordinate) Location(de.micromata.opengis.kml.v_2_2_0.Location)

Example 7 with Coordinate

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

the class KmlToJtsCoordinateConverterTest method testCoordinateConversion.

@Test
public void testCoordinateConversion() {
    org.locationtech.jts.geom.Coordinate jtsCoordinate;
    for (Coordinate kmlCoordinate : testKmlCoordinates) {
        jtsCoordinate = KmlToJtsCoordinateConverter.from(kmlCoordinate);
        assertJtsCoordinateFromKmlCoordinate(kmlCoordinate, jtsCoordinate);
    }
}
Also used : Coordinate(de.micromata.opengis.kml.v_2_2_0.Coordinate) Test(org.junit.Test)

Example 8 with Coordinate

use of de.micromata.opengis.kml.v_2_2_0.Coordinate 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 9 with Coordinate

use of de.micromata.opengis.kml.v_2_2_0.Coordinate 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 10 with Coordinate

use of de.micromata.opengis.kml.v_2_2_0.Coordinate 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)

Aggregations

Coordinate (de.micromata.opengis.kml.v_2_2_0.Coordinate)9 ArrayList (java.util.ArrayList)4 Point (de.micromata.opengis.kml.v_2_2_0.Point)3 Test (org.junit.Test)3 Geometry (de.micromata.opengis.kml.v_2_2_0.Geometry)2 LineString (de.micromata.opengis.kml.v_2_2_0.LineString)2 Location (de.micromata.opengis.kml.v_2_2_0.Location)2 Placemark (de.micromata.opengis.kml.v_2_2_0.Placemark)2 List (java.util.List)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 Document (de.micromata.opengis.kml.v_2_2_0.Document)1 Feature (de.micromata.opengis.kml.v_2_2_0.Feature)1 Folder (de.micromata.opengis.kml.v_2_2_0.Folder)1