use of org.jvnet.ogc.gml.v_3_1_1.jts.JTSToGML311GeometryConverter 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);
((GeometryElement) element).getValue().add(geoValue);
}
}
return element;
}
use of org.jvnet.ogc.gml.v_3_1_1.jts.JTSToGML311GeometryConverter in project ddf by codice.
the class CswFilterFactory method convertGeometry.
@SuppressWarnings("unchecked")
private JAXBElement<? extends AbstractGeometryType> convertGeometry(Geometry geometry) {
geometry.setUserData(CswConstants.SRS_NAME);
JAXBElement<? extends AbstractGeometryType> abstractGeometry = null;
try {
Map<String, String> geoConverterProps = new HashMap<String, String>();
geoConverterProps.put(CswJTSToGML311GeometryConverter.USE_POS_LIST_GEO_CONVERTER_PROP_KEY, String.valueOf(this.isSetUsePosList));
JTSToGML311GeometryConverter converter = new CswJTSToGML311GeometryConverter(geoConverterProps);
Marshaller marshaller = new MarshallerImpl(JAXB_CONTEXT.createMarshaller(), converter);
StringWriter writer = new StringWriter();
marshaller.marshal(geometry, writer);
String xmlGeo = writer.toString();
LOGGER.debug("Geometry as XML: {}", xmlGeo);
XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory();
xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
xmlInputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(new StringReader(xmlGeo));
Unmarshaller unmarshaller = JAXB_CONTEXT.createUnmarshaller();
Object object = unmarshaller.unmarshal(xmlStreamReader);
LOGGER.debug("Unmarshalled as => {}", object);
if (object instanceof JAXBElement) {
abstractGeometry = (JAXBElement<? extends AbstractGeometryType>) object;
} else {
LOGGER.debug("Unable to cast to JAXBElement<? extends AbstractGeometryType>. Object is of type [{}].", object.getClass().getName());
}
} catch (JAXBException | XMLStreamException e) {
LOGGER.debug("Unable to unmarshal geometry [{}]", geometry.getClass().getName(), e);
}
return abstractGeometry;
}
Aggregations