Search in sources :

Example 1 with GeometryElement

use of ddf.catalog.transformer.xml.binding.GeometryElement in project ddf by codice.

the class GeometryAdapter method marshalFrom.

public static GeometryElement marshalFrom(Attribute attribute) throws CatalogTransformerException {
    GeometryElement element = new GeometryElement();
    element.setName(attribute.getName());
    if (attribute.getValue() != null) {
        for (Serializable value : attribute.getValues()) {
            if (!(value instanceof String)) {
                continue;
            }
            String wkt = (String) value;
            WKTReader wktReader = new WKTReader(geometryFactory);
            Geometry jtsGeometry = null;
            try {
                jtsGeometry = wktReader.read(wkt);
            } catch (ParseException e) {
                throw new CatalogTransformerException("Could not transform Metacard to XML.  Invalid WKT.", e);
            }
            JTSToGML311GeometryConverter converter = new JTSToGML311GeometryConverter();
            @SuppressWarnings("unchecked") JAXBElement<AbstractGeometryType> gmlElement = (JAXBElement<AbstractGeometryType>) converter.createElement(jtsGeometry);
            GeometryElement.Value geoValue = new GeometryElement.Value();
            geoValue.setGeometry(gmlElement);
            element.getValue().add(geoValue);
        }
    }
    return element;
}
Also used : Serializable(java.io.Serializable) JTSToGML311GeometryConverter(org.jvnet.ogc.gml.v_3_1_1.jts.JTSToGML311GeometryConverter) AbstractGeometryType(net.opengis.gml.v_3_1_1.AbstractGeometryType) Value(ddf.catalog.transformer.xml.binding.GeometryElement.Value) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) JAXBElement(javax.xml.bind.JAXBElement) WKTReader(org.locationtech.jts.io.WKTReader) Geometry(org.locationtech.jts.geom.Geometry) Value(ddf.catalog.transformer.xml.binding.GeometryElement.Value) GeometryElement(ddf.catalog.transformer.xml.binding.GeometryElement) ParseException(org.locationtech.jts.io.ParseException)

Aggregations

CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)1 GeometryElement (ddf.catalog.transformer.xml.binding.GeometryElement)1 Value (ddf.catalog.transformer.xml.binding.GeometryElement.Value)1 Serializable (java.io.Serializable)1 JAXBElement (javax.xml.bind.JAXBElement)1 AbstractGeometryType (net.opengis.gml.v_3_1_1.AbstractGeometryType)1 JTSToGML311GeometryConverter (org.jvnet.ogc.gml.v_3_1_1.jts.JTSToGML311GeometryConverter)1 Geometry (org.locationtech.jts.geom.Geometry)1 ParseException (org.locationtech.jts.io.ParseException)1 WKTReader (org.locationtech.jts.io.WKTReader)1