Search in sources :

Example 11 with WKTWriter

use of com.vividsolutions.jts.io.WKTWriter 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 12 with WKTWriter

use of com.vividsolutions.jts.io.WKTWriter 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)

Example 13 with WKTWriter

use of com.vividsolutions.jts.io.WKTWriter in project ddf by codice.

the class CswFilterDelegate method bufferGeometry.

private String bufferGeometry(String wkt, double distance) {
    LOGGER.debug("Buffering WKT {} by distance {} meter(s).", wkt, distance);
    Geometry geometry = getGeometryFromWkt(wkt);
    double bufferInDegrees = metersToDegrees(distance);
    LOGGER.debug("Buffering {} by {} degree(s).", geometry.getClass().getSimpleName(), bufferInDegrees);
    Geometry bufferedGeometry = geometry.buffer(bufferInDegrees);
    String bufferedWkt = new WKTWriter().write(bufferedGeometry);
    LOGGER.debug("Buffered WKT: {}.", bufferedWkt);
    return bufferedWkt;
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) WKTWriter(com.vividsolutions.jts.io.WKTWriter)

Example 14 with WKTWriter

use of com.vividsolutions.jts.io.WKTWriter 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

WKTWriter (com.vividsolutions.jts.io.WKTWriter)14 Geometry (com.vividsolutions.jts.geom.Geometry)13 ParseException (com.vividsolutions.jts.io.ParseException)4 IOException (java.io.IOException)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 XmlNode (org.codice.ddf.spatial.ogc.catalog.common.converter.XmlNode)3 DefaultRootObjectLocator (org.jvnet.jaxb2_commons.locator.DefaultRootObjectLocator)3 GML311ToJTSGeometryConverter (org.jvnet.ogc.gml.v_3_1_1.jts.GML311ToJTSGeometryConverter)3 SAXException (org.xml.sax.SAXException)3 LineString (com.vividsolutions.jts.geom.LineString)2 WKTReader (com.vividsolutions.jts.io.WKTReader)2 GMLReader (com.vividsolutions.jts.io.gml2.GMLReader)2 Serializable (java.io.Serializable)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 AbstractGeometryType (net.opengis.gml.v_3_1_1.AbstractGeometryType)2 ConversionFailedException (org.jvnet.ogc.gml.v_3_1_1.jts.ConversionFailedException)2 SimpleFeature (org.opengis.feature.simple.SimpleFeature)2 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)1 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)1 Value (ddf.catalog.transformer.xml.binding.GeometryElement.Value)1