Search in sources :

Example 6 with WKTParser

use of org.geotools.geometry.text.WKTParser in project ddf by codice.

the class CopyFilterDelegateTest method wktToGeometry.

private Geometry wktToGeometry(String wkt) {
    GeometryBuilder geometryBuilder = new GeometryBuilder(DefaultGeographicCRS.WGS84);
    WKTParser wktParser = new WKTParser(geometryBuilder);
    wktParser.setFactory(new PrimitiveFactoryImpl(DefaultGeographicCRS.WGS84));
    Geometry geometry = null;
    try {
        geometry = wktParser.parse(wkt);
    } catch (ParseException e) {
        fail();
    }
    return geometry;
}
Also used : Geometry(org.opengis.geometry.Geometry) PrimitiveFactoryImpl(org.geotools.geometry.jts.spatialschema.geometry.primitive.PrimitiveFactoryImpl) WKTParser(org.geotools.geometry.text.WKTParser) ParseException(java.text.ParseException) GeometryBuilder(org.geotools.geometry.GeometryBuilder)

Example 7 with WKTParser

use of org.geotools.geometry.text.WKTParser in project ddf by codice.

the class OpenSearchQueryTest method testWktParser.

@Test
public void testWktParser() throws Exception {
    String geometryWkt = "POINT( 48.44 -123.37)";
    GeometryBuilder builder = new GeometryBuilder(DefaultGeographicCRS.WGS84);
    WKTParser parser = new WKTParser(builder);
    // This fixed the NPE in parser.parse() - seems GeoTools has bug with
    // keeping the CRS hint set ...
    parser.setFactory(new PrimitiveFactoryImpl(DefaultGeographicCRS.WGS84));
    Geometry geometry = parser.parse(geometryWkt);
    CoordinateReferenceSystem crs = geometry.getCoordinateReferenceSystem();
    assertNotNull(crs);
    String geometryWkt2 = "POINT( 48.44 -123.37)";
    builder = new GeometryBuilder(DefaultGeographicCRS.WGS84);
    WKTParser parser2 = new WKTParser(builder);
    Geometry geometry2 = parser2.parse(geometryWkt2);
    assertTrue(geometry2.intersects(geometry));
    double[] coords = geometry.getCentroid().getCoordinate();
    LOGGER.debug("coords[0] = {},   coords[1] = {}", coords[0], coords[1]);
}
Also used : Geometry(org.opengis.geometry.Geometry) PrimitiveFactoryImpl(org.geotools.geometry.jts.spatialschema.geometry.primitive.PrimitiveFactoryImpl) WKTParser(org.geotools.geometry.text.WKTParser) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) GeometryBuilder(org.geotools.geometry.GeometryBuilder) Test(org.junit.Test)

Aggregations

WKTParser (org.geotools.geometry.text.WKTParser)7 Geometry (org.opengis.geometry.Geometry)6 GeometryBuilder (org.geotools.geometry.GeometryBuilder)5 PrimitiveFactoryImpl (org.geotools.geometry.jts.spatialschema.geometry.primitive.PrimitiveFactoryImpl)5 Test (org.junit.Test)4 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)4 ParseException (java.text.ParseException)2 Hints (org.geotools.factory.Hints)2 Ignore (org.junit.Ignore)2 PositionFactory (org.opengis.geometry.PositionFactory)2 AggregateFactory (org.opengis.geometry.aggregate.AggregateFactory)2 GeometryFactory (org.opengis.geometry.coordinate.GeometryFactory)2 PrimitiveFactory (org.opengis.geometry.primitive.PrimitiveFactory)2 ExpressionPanelv2 (com.sldeditor.filter.v2.expression.ExpressionPanelv2)1 FilterNode (com.sldeditor.filter.v2.expression.FilterNode)1 FilterConfigInterface (com.sldeditor.filter.v2.function.FilterConfigInterface)1 Overlaps (com.sldeditor.filter.v2.function.geometry.Overlaps)1 And (com.sldeditor.filter.v2.function.logic.And)1 IsLike (com.sldeditor.filter.v2.function.misc.IsLike)1 IsNull (com.sldeditor.filter.v2.function.misc.IsNull)1