Search in sources :

Example 1 with GeometryBuilder

use of org.geotools.geometry.GeometryBuilder in project ddf by codice.

the class OpenSearchQueryTest method testWktParserPolygon.

@Test
@Ignore
public void testWktParserPolygon() throws Exception {
    String geometryWkt = "POLYGON(( 0 10, 0 30, 20 30, 20 10, 0 10 ))";
    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);
    double[] coords = geometry.getCentroid().getCoordinate();
    LOGGER.debug("coords[0] = {},   coords[1] = {}", coords[0], coords[1]);
    // String geometryWkt2 = "POINT( 10 20 )";
    String geometryWkt2 = "POLYGON(( 10 15, 10 25, 15 25, 15 15, 10 15 ))";
    builder = new GeometryBuilder(DefaultGeographicCRS.WGS84);
    WKTParser parser2 = new WKTParser(builder);
    // This fixed the NPE in parser.parse() - seems GeoTools has bug with
    // keeping the CRS hint set ...
    parser2.setFactory(new PrimitiveFactoryImpl(DefaultGeographicCRS.WGS84));
    Geometry geometry2 = parser2.parse(geometryWkt2);
    double[] coords2 = geometry2.getCentroid().getCoordinate();
    LOGGER.debug("coords[0] = {},   coords[1] = {}", coords2[0], coords2[1]);
    // This fails - why?
    assertTrue(geometry.contains(geometry2));
}
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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with GeometryBuilder

use of org.geotools.geometry.GeometryBuilder 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

GeometryBuilder (org.geotools.geometry.GeometryBuilder)2 PrimitiveFactoryImpl (org.geotools.geometry.jts.spatialschema.geometry.primitive.PrimitiveFactoryImpl)2 WKTParser (org.geotools.geometry.text.WKTParser)2 Test (org.junit.Test)2 Geometry (org.opengis.geometry.Geometry)2 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)2 Ignore (org.junit.Ignore)1