Search in sources :

Example 1 with DefaultRootObjectLocator

use of org.jvnet.jaxb2_commons.locator.DefaultRootObjectLocator in project ddf by codice.

the class RegistryPackageConverter method getWKTFromGeometry.

private static String getWKTFromGeometry(AbstractGeometryType geometry, JAXBElement jaxbElement) throws RegistryConversionException {
    String convertedGeometry = null;
    if (geometry != null) {
        try {
            GML311ToJTSGeometryConverter geometryConverter = new GML311ToJTSGeometryConverter();
            Geometry jtsGeometry = geometryConverter.createGeometry(new DefaultRootObjectLocator(jaxbElement), geometry);
            if (jtsGeometry != null) {
                WKTWriter writer = new WKTWriter();
                convertedGeometry = writer.write(jtsGeometry);
            }
        } catch (ConversionFailedException e) {
            String message = "Error converting geometry. Caught an exception.";
            throw new RegistryConversionException(message, e);
        }
    }
    return convertedGeometry;
}
Also used : GML311ToJTSGeometryConverter(org.jvnet.ogc.gml.v_3_1_1.jts.GML311ToJTSGeometryConverter) Geometry(com.vividsolutions.jts.geom.Geometry) DefaultRootObjectLocator(org.jvnet.jaxb2_commons.locator.DefaultRootObjectLocator) WKTWriter(com.vividsolutions.jts.io.WKTWriter) ConversionFailedException(org.jvnet.ogc.gml.v_3_1_1.jts.ConversionFailedException)

Example 2 with DefaultRootObjectLocator

use of org.jvnet.jaxb2_commons.locator.DefaultRootObjectLocator in project ddf by codice.

the class Gml3ToWktImpl method convert.

@SuppressWarnings("unchecked")
public String convert(InputStream xml) throws ValidationExceptionImpl {
    AbstractGeometryType geometry = null;
    try {
        JAXBElement<AbstractGeometryType> jaxbElement = parser.unmarshal(configurator, JAXBElement.class, xml);
        geometry = jaxbElement.getValue();
        GML311ToJTSGeometryConverter geometryConverter = new GML311ToJTSGeometryConverter();
        Geometry jtsGeo = geometryConverter.createGeometry(new DefaultRootObjectLocator(jaxbElement), geometry);
        WKTWriter wktWriter = new WKTWriter();
        return wktWriter.write(jtsGeo);
    } catch (ParserException e) {
        LOGGER.debug("Cannot parse gml", e);
        throw new ValidationExceptionImpl(e, Collections.singletonList("Cannot parse gml"), new ArrayList<String>());
    } catch (ConversionFailedException e) {
        LOGGER.debug("Cannot convert gml311 geo object {} to jts", geometry, e);
        throw new ValidationExceptionImpl(e, Collections.singletonList("Cannot convert geo object"), new ArrayList<String>());
    }
}
Also used : GML311ToJTSGeometryConverter(org.jvnet.ogc.gml.v_3_1_1.jts.GML311ToJTSGeometryConverter) Geometry(com.vividsolutions.jts.geom.Geometry) DefaultRootObjectLocator(org.jvnet.jaxb2_commons.locator.DefaultRootObjectLocator) WKTWriter(com.vividsolutions.jts.io.WKTWriter) ParserException(org.codice.ddf.parser.ParserException) ConversionFailedException(org.jvnet.ogc.gml.v_3_1_1.jts.ConversionFailedException) AbstractGeometryType(net.opengis.gml.v_3_1_1.AbstractGeometryType) ValidationExceptionImpl(ddf.catalog.validation.impl.ValidationExceptionImpl) ArrayList(java.util.ArrayList)

Example 3 with DefaultRootObjectLocator

use of org.jvnet.jaxb2_commons.locator.DefaultRootObjectLocator 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 = converter.createGeometry(new DefaultRootObjectLocator(xmlValue), xmlGeometry.getValue());
        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(com.vividsolutions.jts.geom.Geometry) WKTWriter(com.vividsolutions.jts.io.WKTWriter) DefaultRootObjectLocator(org.jvnet.jaxb2_commons.locator.DefaultRootObjectLocator) AbstractGeometryType(net.opengis.gml.v_3_1_1.AbstractGeometryType) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) Value(ddf.catalog.transformer.xml.binding.GeometryElement.Value)

Aggregations

Geometry (com.vividsolutions.jts.geom.Geometry)3 WKTWriter (com.vividsolutions.jts.io.WKTWriter)3 DefaultRootObjectLocator (org.jvnet.jaxb2_commons.locator.DefaultRootObjectLocator)3 GML311ToJTSGeometryConverter (org.jvnet.ogc.gml.v_3_1_1.jts.GML311ToJTSGeometryConverter)3 AbstractGeometryType (net.opengis.gml.v_3_1_1.AbstractGeometryType)2 ConversionFailedException (org.jvnet.ogc.gml.v_3_1_1.jts.ConversionFailedException)2 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)1 Value (ddf.catalog.transformer.xml.binding.GeometryElement.Value)1 ValidationExceptionImpl (ddf.catalog.validation.impl.ValidationExceptionImpl)1 ArrayList (java.util.ArrayList)1 ParserException (org.codice.ddf.parser.ParserException)1