use of com.vividsolutions.jts.geom.GeometryCollection 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;
}
use of com.vividsolutions.jts.geom.GeometryCollection in project ddf by codice.
the class TestWfs10JTStoGML200Converter method testGeometryToGeometryCollectionGML.
@Test
public void testGeometryToGeometryCollectionGML() throws JAXBException, SAXException, IOException, ParseException, NullPointerException {
GeometryCollection geometryCollection = (GeometryCollection) getGeometryFromWkt(GEOMETRYCOLLECTION);
assertThat(geometryCollection == null, is(Boolean.FALSE));
String geometryCollectionGML = Wfs10JTStoGML200Converter.convertGeometryToGML(geometryCollection).replaceAll("\n", "");
assertThat(StringUtils.isEmpty(geometryCollectionGML), is(Boolean.FALSE));
Diff diff = XMLUnit.compareXML(geometryCollectionGML, GEOMETRYCOLLECTION_GML);
assertTrue(XMLUNIT_IDENTICAL, diff.identical());
assertTrue(XMLUNIT_SIMILAR, diff.similar());
}
Aggregations