Search in sources :

Example 1 with Polygon

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

the class MetacardToKml method createPolygonGeo.

private static Geometry createPolygonGeo(Polygon jtsPoly) {
    de.micromata.opengis.kml.v_2_2_0.Polygon kmlPoly = KmlFactory.createPolygon();
    List<Coordinate> kmlCoords = kmlPoly.createAndSetOuterBoundaryIs().createAndSetLinearRing().createAndSetCoordinates();
    for (org.locationtech.jts.geom.Coordinate coord : jtsPoly.getExteriorRing().getCoordinates()) {
        kmlCoords.add(new Coordinate(coord.x, coord.y));
    }
    for (int n = 0; n < jtsPoly.getNumInteriorRing(); n++) {
        kmlCoords = kmlPoly.createAndAddInnerBoundaryIs().createAndSetLinearRing().createAndSetCoordinates();
        org.locationtech.jts.geom.Coordinate[] childCoordinates = jtsPoly.getInteriorRingN(n).getCoordinates();
        for (org.locationtech.jts.geom.Coordinate coord : childCoordinates) {
            kmlCoords.add(new Coordinate(coord.x, coord.y));
        }
    }
    return kmlPoly;
}
Also used : Point(org.locationtech.jts.geom.Point) Coordinate(de.micromata.opengis.kml.v_2_2_0.Coordinate)

Example 2 with Polygon

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

the class MetacardToKmlTest method getKmlGeoFromJtsGeoMultiPolygonWithNoHoles.

@Test
public void getKmlGeoFromJtsGeoMultiPolygonWithNoHoles() throws CatalogTransformerException {
    final org.locationtech.jts.geom.Geometry jtsGeoFromWkt = MetacardToKml.getJtsGeoFromWkt("MULTIPOLYGON (((-153.0063 57.1158, -154.0051 56.7347, -154.5164 56.9927, -154.671 57.4612, -153.2287 57.969, -152.5648 57.9014, -152.1411 57.5911, -153.0063 57.1158)), ((-155.5421 19.0835, -155.6882 18.9162, -155.9366 19.0594, -156.0735 19.7029, -155.8501 19.9773, -155.8611 20.2672, -155.2245 19.993, -154.8074 19.5087, -155.5421 19.0835)))");
    assertThat(jtsGeoFromWkt.getGeometryType(), is("MultiPolygon"));
    final Geometry kmlGeo = MetacardToKml.getKmlGeoFromJtsGeo(jtsGeoFromWkt);
    assertTrue(kmlGeo instanceof MultiGeometry);
    final MultiGeometry kmlMultiGeo = (MultiGeometry) kmlGeo;
    assertThat(kmlMultiGeo.getGeometry(), hasSize(2));
    assertTrue(kmlMultiGeo.getGeometry().get(0) instanceof Polygon);
    final Polygon kmlGeoPolygon = (Polygon) kmlMultiGeo.getGeometry().get(0);
    assertTrue(kmlGeoPolygon.getOuterBoundaryIs() != null);
    assertThat(kmlGeoPolygon.getOuterBoundaryIs().getLinearRing().getCoordinates(), hasSize(8));
    assertThat(kmlGeoPolygon.getOuterBoundaryIs().getLinearRing().getCoordinates().get(0).toString(), is("-153.0063,57.1158"));
    assertThat(kmlGeoPolygon.getInnerBoundaryIs(), hasSize(0));
}
Also used : Geometry(de.micromata.opengis.kml.v_2_2_0.Geometry) MultiGeometry(de.micromata.opengis.kml.v_2_2_0.MultiGeometry) MultiGeometry(de.micromata.opengis.kml.v_2_2_0.MultiGeometry) Polygon(de.micromata.opengis.kml.v_2_2_0.Polygon) Test(org.junit.Test)

Example 3 with Polygon

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

the class KmlToJtsPolygonConverterTest method testConvertPolygonWithHoles.

@Test
public void testConvertPolygonWithHoles() {
    Polygon kmlPolygonWithHoles = getTestKmlPolygonWithHoles();
    org.locationtech.jts.geom.Polygon jtsPolygon = KmlToJtsPolygonConverter.from(kmlPolygonWithHoles);
    assertJtsPolygon(kmlPolygonWithHoles, jtsPolygon);
}
Also used : Polygon(de.micromata.opengis.kml.v_2_2_0.Polygon) Test(org.junit.Test)

Example 4 with Polygon

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

the class KmlToJtsPolygonConverterTest method setupClass.

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

Example 5 with Polygon

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

the class KmlToJtsPolygonConverterTest method getTestKmlPolygonWithHoles.

private Polygon getTestKmlPolygonWithHoles() {
    InputStream stream = KmlToJtsPolygonConverterTest.class.getResourceAsStream("/kmlPolygonWithHoles.kml");
    Kml kml = Kml.unmarshal(stream);
    assertThat(kml, notNullValue());
    Polygon polygon = ((Polygon) ((Placemark) kml.getFeature()).getGeometry());
    assertThat(polygon, notNullValue());
    LinearRing linearRing = polygon.getOuterBoundaryIs().getLinearRing();
    assertThat(linearRing, notNullValue());
    List<LinearRing> holes = polygon.getInnerBoundaryIs().stream().map(Boundary::getLinearRing).collect(Collectors.toList());
    assertThat(holes, not(empty()));
    return polygon;
}
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) LinearRing(de.micromata.opengis.kml.v_2_2_0.LinearRing)

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