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;
}
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));
}
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);
}
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());
}
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;
}
Aggregations