Search in sources :

Example 1 with GMLWriter

use of com.vividsolutions.jts.io.gml2.GMLWriter in project incubator-rya by apache.

the class GeoIndexerSfTest method geoToGmlUseJtsLib.

/**
 * JTS library conversion from geometry to GML.
 * @param geo base Geometry gets delegated
 * @return String gml encoding of the geomoetry
 */
private static String geoToGmlUseJtsLib(final Geometry geo) {
    final int srid = geo.getSRID();
    final GMLWriter gmlWriter = new GMLWriter();
    gmlWriter.setNamespace(false);
    gmlWriter.setPrefix(null);
    if (srid != -1 || srid != 0) {
        gmlWriter.setSrsName("EPSG:" + geo.getSRID());
    }
    final String gml = gmlWriter.write(geo);
    // It should tolerate this as it does other depreciated elements like <gml:coordinates>.
    return gml.replace("outerBoundaryIs", "exterior");
}
Also used : GMLWriter(com.vividsolutions.jts.io.gml2.GMLWriter) LineString(com.vividsolutions.jts.geom.LineString) Point(com.vividsolutions.jts.geom.Point)

Example 2 with GMLWriter

use of com.vividsolutions.jts.io.gml2.GMLWriter in project teiid by teiid.

the class GeometryUtils method geometryToGml.

public static ClobType geometryToGml(CommandContext ctx, GeometryType geometry, boolean withGmlPrefix) throws FunctionExecutionException {
    Geometry jtsGeometry = getGeometry(geometry);
    GMLWriter writer = new GMLWriter();
    if (!withGmlPrefix) {
        if (geometry.getSrid() != SRID_4326) {
            if (geometry.getSrid() == GeometryType.UNKNOWN_SRID) {
                throw new FunctionExecutionException(QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31161));
            }
            jtsGeometry = GeometryTransformUtils.transform(ctx, jtsGeometry, SRID_4326);
        }
        writer.setPrefix(null);
    } else if (geometry.getSrid() != GeometryType.UNKNOWN_SRID) {
    // TODO: should include the srsName
    // writer.setSrsName(String.valueOf(geometry.getSrid()));
    }
    String gmlText = writer.write(jtsGeometry);
    return new ClobType(new ClobImpl(gmlText));
}
Also used : ClobType(org.teiid.core.types.ClobType) FunctionExecutionException(org.teiid.api.exception.query.FunctionExecutionException) GMLWriter(com.vividsolutions.jts.io.gml2.GMLWriter) ClobImpl(org.teiid.core.types.ClobImpl)

Example 3 with GMLWriter

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

the class Wfs20JTStoGML321Converter method convertGeometryToGML.

public static String convertGeometryToGML(Geometry geometry) throws JAXBException {
    GMLWriter gmlWriter = new GMLWriter(true);
    String gml = gmlWriter.write(geometry);
    return gml;
}
Also used : GMLWriter(org.locationtech.jts.io.gml2.GMLWriter) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString)

Example 4 with GMLWriter

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

the class GmlGeometryConverter method marshal.

@Override
public void marshal(Object value, HierarchicalStreamWriter writer, MarshallingContext context) {
    Geometry geometry = (Geometry) value;
    GMLWriter gmlWriter = new GMLWriter();
    String gmlXml = gmlWriter.write(geometry);
    // Copy the GML XML into the writer
    XmlPullParser parser = null;
    try {
        parser = XppFactory.createDefaultParser();
        new HierarchicalStreamCopier().copy(new XppReader(new StringReader(gmlXml), parser), writer);
    } catch (XmlPullParserException e) {
        LOGGER.debug(ERROR_SERIALIZING_MSG, e);
    }
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GMLWriter(org.locationtech.jts.io.gml2.GMLWriter) XppReader(com.thoughtworks.xstream.io.xml.XppReader) XmlPullParser(org.xmlpull.v1.XmlPullParser) StringReader(java.io.StringReader) HierarchicalStreamCopier(com.thoughtworks.xstream.io.copy.HierarchicalStreamCopier) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 5 with GMLWriter

use of com.vividsolutions.jts.io.gml2.GMLWriter in project incubator-rya by apache.

the class GeoWaveIndexerSfTest method geoToGmlUseJtsLib.

/**
 * JTS library conversion from geometry to GML.
 * @param geo base Geometry gets delegated
 * @return String gml encoding of the geomoetry
 */
private static String geoToGmlUseJtsLib(final Geometry geo) {
    final int srid = geo.getSRID();
    final GMLWriter gmlWriter = new GMLWriter();
    gmlWriter.setNamespace(false);
    gmlWriter.setPrefix(null);
    if (srid != -1 || srid != 0) {
        gmlWriter.setSrsName("EPSG:" + geo.getSRID());
    }
    final String gml = gmlWriter.write(geo);
    // It should tolerate this as it does other depreciated elements like <gml:coordinates>.
    return gml.replace("outerBoundaryIs", "exterior");
}
Also used : GMLWriter(com.vividsolutions.jts.io.gml2.GMLWriter) LineString(com.vividsolutions.jts.geom.LineString) Point(com.vividsolutions.jts.geom.Point)

Aggregations

GMLWriter (com.vividsolutions.jts.io.gml2.GMLWriter)4 LineString (com.vividsolutions.jts.geom.LineString)2 Point (com.vividsolutions.jts.geom.Point)2 GMLWriter (org.locationtech.jts.io.gml2.GMLWriter)2 HierarchicalStreamCopier (com.thoughtworks.xstream.io.copy.HierarchicalStreamCopier)1 XppReader (com.thoughtworks.xstream.io.xml.XppReader)1 StringReader (java.io.StringReader)1 Geometry (org.locationtech.jts.geom.Geometry)1 LineString (org.locationtech.jts.geom.LineString)1 MultiLineString (org.locationtech.jts.geom.MultiLineString)1 FunctionExecutionException (org.teiid.api.exception.query.FunctionExecutionException)1 ClobImpl (org.teiid.core.types.ClobImpl)1 ClobType (org.teiid.core.types.ClobType)1 XmlPullParser (org.xmlpull.v1.XmlPullParser)1 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)1