Search in sources :

Example 1 with LineString

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

the class MetacardToKmlTest method addJtsGeoPointsToKmlGeo.

@Test
public void addJtsGeoPointsToKmlGeo() {
    final LineString kmlLineString = new LineString();
    kmlLineString.setCoordinates(singletonList(new Coordinate(80.0, 170.0)));
    doReturn(new org.locationtech.jts.geom.Coordinate()).when(jtsLineString).getCoordinate();
    final Geometry newKmlGeometry = MetacardToKml.addJtsGeoPointsToKmlGeo(jtsLineString, kmlLineString);
    assertTrue(newKmlGeometry instanceof MultiGeometry);
    final MultiGeometry multiGeometry = (MultiGeometry) newKmlGeometry;
    assertThat("New KML Geometry should be MultiGeometry containing 2 Geometries", multiGeometry.getGeometry(), hasSize(2));
}
Also used : Geometry(de.micromata.opengis.kml.v_2_2_0.Geometry) MultiGeometry(de.micromata.opengis.kml.v_2_2_0.MultiGeometry) LineString(de.micromata.opengis.kml.v_2_2_0.LineString) Coordinate(de.micromata.opengis.kml.v_2_2_0.Coordinate) MultiGeometry(de.micromata.opengis.kml.v_2_2_0.MultiGeometry) Test(org.junit.Test)

Example 2 with LineString

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

the class KmlToJtsGeometryConverterTest method testConvertLineStringGeometry.

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

Example 3 with LineString

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

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

the class Operation method addPath.

private void addPath() {
    Collections.sort(mLineNodes, (LineNode o1, LineNode o2) -> o1.getDate().compareTo(o2.getDate()));
    mPathFolder = KmlFactory.createFolder().withName(Dict.PATH_GFX.toString());
    mPathGapFolder = KmlFactory.createFolder().withName(Dict.PATH_GAP_GFX.toString());
    String pattern = getPattern(mProfilePath.getSplitBy());
    SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
    TreeMap<String, ArrayList<LineNode>> map = new TreeMap<>();
    mLineNodes.forEach((node) -> {
        String key = dateFormat.format(node.getDate());
        if (!map.containsKey(key)) {
            map.put(key, new ArrayList<>());
        }
        map.get(key).add(node);
    });
    // Add paths
    for (ArrayList<LineNode> nodes : map.values()) {
        if (nodes.size() > 1) {
            Placemark path = mPathFolder.createAndAddPlacemark().withName(LineNode.getName(nodes));
            Style pathStyle = path.createAndAddStyle();
            pathStyle.createAndSetLineStyle().withColor("ff0000ff").withWidth(mProfilePath.getWidth());
            LineString line = path.createAndSetLineString().withExtrude(false).withTessellate(true);
            nodes.forEach((node) -> {
                line.addToCoordinates(node.getLon(), node.getLat());
            });
        }
    }
    // Add path gap
    ArrayList<LineNode> previousNodes = null;
    for (ArrayList<LineNode> nodes : map.values()) {
        if (previousNodes != null) {
            Placemark path = mPathGapFolder.createAndAddPlacemark().withName(LineNode.getName(previousNodes, nodes));
            Style pathStyle = path.createAndAddStyle();
            pathStyle.createAndSetLineStyle().withColor("ff00ffff").withWidth(mProfilePath.getWidth());
            LineString line = path.createAndSetLineString().withExtrude(false).withTessellate(true);
            LineNode prevLast = previousNodes.get(previousNodes.size() - 1);
            LineNode currentFirst = nodes.get(0);
            line.addToCoordinates(prevLast.getLon(), prevLast.getLat());
            line.addToCoordinates(currentFirst.getLon(), currentFirst.getLat());
        }
        previousNodes = nodes;
    }
}
Also used : ProfilePlacemark(se.trixon.mapollage.profile.ProfilePlacemark) Placemark(de.micromata.opengis.kml.v_2_2_0.Placemark) LineString(de.micromata.opengis.kml.v_2_2_0.LineString) ArrayList(java.util.ArrayList) 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) LineString(de.micromata.opengis.kml.v_2_2_0.LineString) TreeMap(java.util.TreeMap) SimpleDateFormat(java.text.SimpleDateFormat)

Example 5 with LineString

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

the class KmlToJtsLineStringConverterTest method setupClass.

@BeforeClass
public static void setupClass() {
    InputStream stream = KmlToJtsLineStringConverterTest.class.getResourceAsStream("/kmlLineString.kml");
    Kml kml = Kml.unmarshal(stream);
    testKmlLineString = ((LineString) ((Placemark) kml.getFeature()).getGeometry());
}
Also used : LineString(de.micromata.opengis.kml.v_2_2_0.LineString) InputStream(java.io.InputStream) Kml(de.micromata.opengis.kml.v_2_2_0.Kml) BeforeClass(org.junit.BeforeClass)

Aggregations

LineString (de.micromata.opengis.kml.v_2_2_0.LineString)6 Test (org.junit.Test)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)2 MultiGeometry (de.micromata.opengis.kml.v_2_2_0.MultiGeometry)2 Placemark (de.micromata.opengis.kml.v_2_2_0.Placemark)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)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 IconStyle (de.micromata.opengis.kml.v_2_2_0.IconStyle)1 LineStyle (de.micromata.opengis.kml.v_2_2_0.LineStyle)1 PolyStyle (de.micromata.opengis.kml.v_2_2_0.PolyStyle)1 Style (de.micromata.opengis.kml.v_2_2_0.Style)1 SimpleDateFormat (java.text.SimpleDateFormat)1