Search in sources :

Example 1 with XmlNode

use of org.codice.ddf.spatial.ogc.catalog.common.converter.XmlNode in project ddf by codice.

the class AbstractFeatureConverter method getValueForMetacardAttribute.

protected Serializable getValueForMetacardAttribute(AttributeFormat attributeFormat, HierarchicalStreamReader reader) {
    Serializable ser = null;
    switch(attributeFormat) {
        case BOOLEAN:
            ser = Boolean.valueOf(reader.getValue());
            break;
        case DOUBLE:
            ser = Double.valueOf(reader.getValue());
            break;
        case FLOAT:
            ser = Float.valueOf(reader.getValue());
            break;
        case INTEGER:
            ser = Integer.valueOf(reader.getValue());
            break;
        case LONG:
            ser = Long.valueOf(reader.getValue());
            break;
        case SHORT:
            ser = Short.valueOf(reader.getValue());
            break;
        case XML:
        case STRING:
            ser = reader.getValue();
            break;
        case GEOMETRY:
            XmlNode node = new XmlNode(reader);
            String xml = node.toString();
            GMLReader gmlReader = new GMLReader();
            Geometry geo = null;
            try {
                geo = gmlReader.read(xml, null);
                if (StringUtils.isNotBlank(srs) && !srs.equals(GeospatialUtil.EPSG_4326)) {
                    geo = GeospatialUtil.transformToEPSG4326LonLatFormat(geo, srs);
                }
            } catch (SAXException | IOException | ParserConfigurationException | GeoFormatException e) {
                geo = null;
                LOGGER.debug(ERROR_PARSING_MESSAGE, e);
            }
            if (geo != null) {
                WKTWriter wktWriter = new WKTWriter();
                ser = wktWriter.write(geo);
            }
            break;
        case BINARY:
            try {
                ser = reader.getValue().getBytes(UTF8_ENCODING);
            } catch (UnsupportedEncodingException e) {
                LOGGER.debug("Error encoding the binary value into the metacard.", e);
            }
            break;
        case DATE:
            ser = parseDateFromXml(reader);
            break;
        default:
            break;
    }
    return ser;
}
Also used : GMLReader(com.vividsolutions.jts.io.gml2.GMLReader) Geometry(com.vividsolutions.jts.geom.Geometry) WKTWriter(com.vividsolutions.jts.io.WKTWriter) Serializable(java.io.Serializable) XmlNode(org.codice.ddf.spatial.ogc.catalog.common.converter.XmlNode) GeoFormatException(org.codice.ddf.libs.geo.GeoFormatException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 2 with XmlNode

use of org.codice.ddf.spatial.ogc.catalog.common.converter.XmlNode in project ddf by codice.

the class GmlGeometryConverter method unmarshal.

@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    XmlNode gmlNode = new XmlNode(reader);
    GMLReader gmlReader = new GMLReader();
    Geometry geo = null;
    try {
        geo = gmlReader.read(gmlNode.toString(), null);
    } catch (SAXException | IOException | ParserConfigurationException e) {
        LOGGER.debug(ERROR_PARSING_MSG, e);
    }
    if (geo != null) {
        WKTWriter wktWriter = new WKTWriter();
        return wktWriter.write(geo);
    }
    return null;
}
Also used : GMLReader(com.vividsolutions.jts.io.gml2.GMLReader) Geometry(com.vividsolutions.jts.geom.Geometry) WKTWriter(com.vividsolutions.jts.io.WKTWriter) XmlNode(org.codice.ddf.spatial.ogc.catalog.common.converter.XmlNode) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 3 with XmlNode

use of org.codice.ddf.spatial.ogc.catalog.common.converter.XmlNode in project ddf by codice.

the class AbstractFeatureConverterWfs20 method getValueForMetacardAttribute.

protected Serializable getValueForMetacardAttribute(AttributeFormat attributeFormat, HierarchicalStreamReader reader) {
    Serializable ser = null;
    switch(attributeFormat) {
        case BOOLEAN:
            ser = Boolean.valueOf(reader.getValue());
            break;
        case DOUBLE:
            ser = Double.valueOf(reader.getValue());
            break;
        case FLOAT:
            ser = Float.valueOf(reader.getValue());
            break;
        case INTEGER:
            ser = Integer.valueOf(reader.getValue());
            break;
        case LONG:
            ser = Long.valueOf(reader.getValue());
            break;
        case SHORT:
            ser = Short.valueOf(reader.getValue());
            break;
        case XML:
        case STRING:
            ser = reader.getValue();
            break;
        case GEOMETRY:
            XmlNode node = new XmlNode(reader);
            String geometryXml = node.toString();
            Geometry geo = null;
            geo = (Geometry) readGml(geometryXml);
            LOGGER.debug("coordinateOrder = {}", coordinateOrder);
            if (GeospatialUtil.LAT_LON_ORDER.equals(coordinateOrder)) {
                swapCoordinates(geo);
            }
            if (geo != null) {
                WKTWriter wktWriter = new WKTWriter();
                ser = wktWriter.write(geo);
                LOGGER.debug("wkt = {}", ser);
            }
            break;
        case BINARY:
            try {
                ser = reader.getValue().getBytes(UTF8_ENCODING);
            } catch (UnsupportedEncodingException e) {
                LOGGER.debug("Error encoding the binary value into the metacard.", e);
            }
            break;
        case DATE:
            ser = parseDateFromXml(reader);
            break;
        default:
            break;
    }
    return ser;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) WKTWriter(com.vividsolutions.jts.io.WKTWriter) Serializable(java.io.Serializable) XmlNode(org.codice.ddf.spatial.ogc.catalog.common.converter.XmlNode) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

Geometry (com.vividsolutions.jts.geom.Geometry)3 WKTWriter (com.vividsolutions.jts.io.WKTWriter)3 XmlNode (org.codice.ddf.spatial.ogc.catalog.common.converter.XmlNode)3 GMLReader (com.vividsolutions.jts.io.gml2.GMLReader)2 IOException (java.io.IOException)2 Serializable (java.io.Serializable)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 SAXException (org.xml.sax.SAXException)2 GeoFormatException (org.codice.ddf.libs.geo.GeoFormatException)1