Search in sources :

Example 11 with GeometryCollection

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;
}
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 12 with GeometryCollection

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());
}
Also used : GeometryCollection(com.vividsolutions.jts.geom.GeometryCollection) Diff(org.custommonkey.xmlunit.Diff) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) Test(org.junit.Test)

Aggregations

GeometryCollection (com.vividsolutions.jts.geom.GeometryCollection)12 Geometry (com.vividsolutions.jts.geom.Geometry)6 LineString (com.vividsolutions.jts.geom.LineString)4 Point (com.vividsolutions.jts.geom.Point)4 Polygon (com.vividsolutions.jts.geom.Polygon)4 ArrayList (java.util.ArrayList)4 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)3 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)3 Serializable (java.io.Serializable)3 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)2 MultiPoint (com.vividsolutions.jts.geom.MultiPoint)2 ParseException (com.vividsolutions.jts.io.ParseException)2 WKTReader (com.vividsolutions.jts.io.WKTReader)2 Test (org.junit.Test)2 Envelope (com.vividsolutions.jts.geom.Envelope)1 Attribute (ddf.catalog.data.Attribute)1 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)1 Metacard (ddf.catalog.data.Metacard)1 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)1 Coordinate (de.micromata.opengis.kml.v_2_2_0.Coordinate)1