Search in sources :

Example 1 with Geometry

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

the class KMLTransformerImpl method getKmlGeoFromWkt.

private Geometry getKmlGeoFromWkt(final String wkt) throws CatalogTransformerException {
    if (StringUtils.isBlank(wkt)) {
        throw new CatalogTransformerException("WKT was null or empty. Unable to preform KML Transform on Metacard.");
    }
    com.vividsolutions.jts.geom.Geometry geo = readGeoFromWkt(wkt);
    Geometry kmlGeo = createKmlGeo(geo);
    if (!Point.class.getSimpleName().equals(geo.getGeometryType())) {
        kmlGeo = addPointToKmlGeo(kmlGeo, geo.getCoordinate());
    }
    return kmlGeo;
}
Also used : Geometry(de.micromata.opengis.kml.v_2_2_0.Geometry) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException)

Example 2 with Geometry

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

Aggregations

CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)2 Geometry (de.micromata.opengis.kml.v_2_2_0.Geometry)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 Coordinate (de.micromata.opengis.kml.v_2_2_0.Coordinate)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1