Search in sources :

Example 1 with LinearRing

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

Example 2 with LinearRing

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

the class KmlToJtsLinearRingConverterTest method testKmlLinearRingWithNoCoordinatesReturnsNull.

@Test
public void testKmlLinearRingWithNoCoordinatesReturnsNull() {
    org.locationtech.jts.geom.LinearRing jtsLinearRing = KmlToJtsLinearRingConverter.from(new LinearRing());
    assertThat(jtsLinearRing, nullValue());
}
Also used : LinearRing(de.micromata.opengis.kml.v_2_2_0.LinearRing) Test(org.junit.Test)

Example 3 with LinearRing

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

the class KmlToJtsLinearRingConverterTest method setupClass.

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

Example 4 with LinearRing

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

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

the class KmlToJtsGeometryConverterTest method testConvertLinearRingGeometry.

@Test
public void testConvertLinearRingGeometry() {
    InputStream stream = KmlToJtsGeometryConverterTest.class.getResourceAsStream("/kmlLinearRing.kml");
    Kml kml = Kml.unmarshal(stream);
    assertThat(kml, notNullValue());
    LinearRing kmlLinearRing = ((LinearRing) ((Placemark) kml.getFeature()).getGeometry());
    assertThat(kmlLinearRing, notNullValue());
    org.locationtech.jts.geom.Geometry jtsGeometryLinearRing = KmlToJtsGeometryConverter.from(kmlLinearRing);
    assertThat(jtsGeometryLinearRing, instanceOf(org.locationtech.jts.geom.LinearRing.class));
    assertSpecificGeometry(kmlLinearRing, jtsGeometryLinearRing);
}
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) LinearRing(de.micromata.opengis.kml.v_2_2_0.LinearRing) Test(org.junit.Test)

Aggregations

LinearRing (de.micromata.opengis.kml.v_2_2_0.LinearRing)6 Kml (de.micromata.opengis.kml.v_2_2_0.Kml)4 Placemark (de.micromata.opengis.kml.v_2_2_0.Placemark)4 InputStream (java.io.InputStream)4 Polygon (de.micromata.opengis.kml.v_2_2_0.Polygon)2 BeforeClass (org.junit.BeforeClass)2 Test (org.junit.Test)2 BalloonStyle (de.micromata.opengis.kml.v_2_2_0.BalloonStyle)1 Boundary (de.micromata.opengis.kml.v_2_2_0.Boundary)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 Point2D (java.awt.geom.Point2D)1 ArrayList (java.util.ArrayList)1 ProfilePlacemark (se.trixon.mapollage.profile.ProfilePlacemark)1