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;
}
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>());
}
}
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;
}
Aggregations