Search in sources :

Example 1 with WKTWriter

use of org.locationtech.jts.io.WKTWriter in project arctic-sea by 52North.

the class ODataFesParserTest method setup.

@Before
public void setup() {
    this.parser = new ODataFesParser();
    this.geometryFactory = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING_SINGLE), 4326);
    this.polygon = this.geometryFactory.createPolygon(new Coordinate[] { new Coordinate(-15.46, 77.98), new Coordinate(-93.51, 38.27), new Coordinate(47.10, -1.05), new Coordinate(58.71, 70.61), new Coordinate(-15.46, 77.98) });
    this.wktGeometry = new WKTWriter().write(polygon).replaceFirst(" ", "").replaceAll(", ", ",");
}
Also used : WKTWriter(org.locationtech.jts.io.WKTWriter) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) PrecisionModel(org.locationtech.jts.geom.PrecisionModel) Before(org.junit.Before)

Example 2 with WKTWriter

use of org.locationtech.jts.io.WKTWriter 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(org.locationtech.jts.io.gml2.GMLReader) Geometry(org.locationtech.jts.geom.Geometry) WKTWriter(org.locationtech.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 3 with WKTWriter

use of org.locationtech.jts.io.WKTWriter in project ddf by codice.

the class WfsFilterDelegate method bufferGeometry.

private String bufferGeometry(String wkt, double distance) {
    LOGGER.debug("Buffering WKT {} by distance {} meter(s).", wkt, distance);
    String bufferedWkt = null;
    try {
        Geometry geometry = getGeometryFromWkt(wkt);
        double bufferInDegrees = metersToDegrees(distance);
        LOGGER.debug("Buffering {} by {} degree(s).", geometry.getClass().getSimpleName(), bufferInDegrees);
        Geometry bufferedGeometry = geometry.buffer(bufferInDegrees);
        bufferedWkt = new WKTWriter().write(bufferedGeometry);
        LOGGER.debug("Buffered WKT: {}.", bufferedWkt);
    } catch (ParseException e) {
        throw new IllegalArgumentException("Unable to parse WKT String", e);
    }
    return bufferedWkt;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) WKTWriter(org.locationtech.jts.io.WKTWriter) LineString(org.locationtech.jts.geom.LineString) ParseException(org.locationtech.jts.io.ParseException)

Example 4 with WKTWriter

use of org.locationtech.jts.io.WKTWriter in project ddf by codice.

the class CatalogFeatureIndexerTest method getExampleMetacard.

private Metacard getExampleMetacard() {
    Metacard metacard = new MetacardImpl();
    List<Serializable> tags = Arrays.asList(GAZETTEER_METACARD_TAG, GeoCodingConstants.COUNTRY_TAG);
    metacard.setAttribute(new AttributeImpl(Core.METACARD_TAGS, tags));
    WKTWriter writer = new WKTWriter();
    String wkt = writer.write((Geometry) getExampleFeature().getDefaultGeometry());
    metacard.setAttribute(new AttributeImpl(Core.LOCATION, wkt));
    metacard.setAttribute(new AttributeImpl(Core.TITLE, TITLE));
    metacard.setAttribute(new AttributeImpl(Location.COUNTRY_CODE, COUNTRY_CODE));
    return metacard;
}
Also used : WKTWriter(org.locationtech.jts.io.WKTWriter) Metacard(ddf.catalog.data.Metacard) Serializable(java.io.Serializable) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

Example 5 with WKTWriter

use of org.locationtech.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(org.locationtech.jts.io.gml2.GMLReader) Geometry(org.locationtech.jts.geom.Geometry) WKTWriter(org.locationtech.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)

Aggregations

WKTWriter (org.locationtech.jts.io.WKTWriter)9 Geometry (org.locationtech.jts.geom.Geometry)7 Serializable (java.io.Serializable)3 XmlNode (org.codice.ddf.spatial.ogc.catalog.common.converter.XmlNode)3 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 GMLReader (org.locationtech.jts.io.gml2.GMLReader)2 SAXException (org.xml.sax.SAXException)2 Metacard (ddf.catalog.data.Metacard)1 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)1 Value (ddf.catalog.transformer.xml.binding.GeometryElement.Value)1 ValidationExceptionImpl (ddf.catalog.validation.impl.ValidationExceptionImpl)1 ArrayList (java.util.ArrayList)1 AbstractGeometryType (net.opengis.gml.v_3_1_1.AbstractGeometryType)1 GeoFormatException (org.codice.ddf.libs.geo.GeoFormatException)1 Before (org.junit.Before)1 DefaultRootObjectLocator (org.jvnet.jaxb2_commons.locator.DefaultRootObjectLocator)1 ConversionFailedException (org.jvnet.ogc.gml.v_3_1_1.jts.ConversionFailedException)1