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