Search in sources :

Example 1 with Value

use of ddf.catalog.transformer.xml.binding.GeometryElement.Value 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)

Example 2 with Value

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

the class GeometryAdapter method unmarshalFrom.

public static Attribute unmarshalFrom(GeometryElement element) throws ConversionFailedException {
    AttributeImpl attribute = null;
    GML311ToJTSGeometryConverter converter = new GML311ToJTSGeometryConverter();
    WKTWriter wktWriter = new WKTWriter();
    for (Value xmlValue : element.getValue()) {
        JAXBElement<AbstractGeometryType> xmlGeometry = xmlValue.getGeometry();
        Geometry geometry = null;
        if (xmlGeometry != null && xmlGeometry.getValue() != null) {
            try {
                geometry = converter.createGeometry(new DefaultRootObjectLocator(xmlValue), xmlGeometry.getValue());
            } catch (ConversionFailedException e) {
                LOGGER.debug("Unable to adapt goemetry. ", e);
            }
        }
        if (geometry != null && !geometry.isEmpty()) {
            String wkt = wktWriter.write(geometry);
            if (attribute == null) {
                attribute = new AttributeImpl(element.getName(), wkt);
            } else {
                attribute.addValue(wkt);
            }
        }
    }
    return attribute;
}
Also used : GML311ToJTSGeometryConverter(org.jvnet.ogc.gml.v_3_1_1.jts.GML311ToJTSGeometryConverter) Geometry(org.locationtech.jts.geom.Geometry) WKTWriter(org.locationtech.jts.io.WKTWriter) DefaultRootObjectLocator(org.jvnet.jaxb2_commons.locator.DefaultRootObjectLocator) ConversionFailedException(org.jvnet.ogc.gml.v_3_1_1.jts.ConversionFailedException) AbstractGeometryType(net.opengis.gml.v_3_1_1.AbstractGeometryType) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) Value(ddf.catalog.transformer.xml.binding.GeometryElement.Value)

Aggregations

Value (ddf.catalog.transformer.xml.binding.GeometryElement.Value)2 AbstractGeometryType (net.opengis.gml.v_3_1_1.AbstractGeometryType)2 Geometry (org.locationtech.jts.geom.Geometry)2 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)1 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)1 GeometryElement (ddf.catalog.transformer.xml.binding.GeometryElement)1 Serializable (java.io.Serializable)1 JAXBElement (javax.xml.bind.JAXBElement)1 DefaultRootObjectLocator (org.jvnet.jaxb2_commons.locator.DefaultRootObjectLocator)1 ConversionFailedException (org.jvnet.ogc.gml.v_3_1_1.jts.ConversionFailedException)1 GML311ToJTSGeometryConverter (org.jvnet.ogc.gml.v_3_1_1.jts.GML311ToJTSGeometryConverter)1 JTSToGML311GeometryConverter (org.jvnet.ogc.gml.v_3_1_1.jts.JTSToGML311GeometryConverter)1 ParseException (org.locationtech.jts.io.ParseException)1 WKTReader (org.locationtech.jts.io.WKTReader)1 WKTWriter (org.locationtech.jts.io.WKTWriter)1