GeometryUtility { public static Optional<String> createUnionOfGeometryAttribute( WKTReader wktReader, WKTWriter wktWriter, Attribute attribute, GeometryOperator.Context geometryOperatorContext) { return createUnionOfGeometryAttribute( wktReader, wktWriter, attribute, GeometryOperator.IDENTITY, GeometryOperator.IDENTITY, geometryOperatorContext); }  static Optional<String> createUnionOfGeometryAttribute(
      WKTReader wktReader,
      WKTWriter wktWriter,
      Attribute attribute,
      GeometryOperator.Context geometryOperatorContext); static Optional<String> createUnionOfGeometryAttribute(
      WKTReader wktReader,
      WKTWriter wktWriter,
      Attribute attribute,
      BiFunction<Geometry, GeometryOperator.Context, Geometry> postUnionGeometryOperator,
      BiFunction<Geometry, GeometryOperator.Context, Geometry> preUnionGeometryOperator,
      GeometryOperator.Context geometryOperatorContext); static Optional<Geometry> wktToGeometry(String wkt, WKTReader wktReader); static String attributeToLineString(
      Attribute attribute,
      GeometryOperator geometryOperator,
      GeometryOperator.Context geometryOperatorContext);  }
@Test public void testBasicUnion() throws ParseException { Attribute attribute = new AttributeImpl( FIELD, Arrays.asList( "POLYGON (( 0 0, 10 0, 10 10, 0 10, 0 0))", "POLYGON (( 5 5, 15 5, 15 15, 5 15, 5 5))")); Optional<String> optionalWkt = GeometryUtility.createUnionOfGeometryAttribute( wktReader, wktWriter, attribute, new GeometryOperator.Context()); Geometry actual = wktReader.read(optionalWkt.get()).norm(); Geometry expected = wktReader.read("POLYGON (( 0 0, 10 0, 10 5, 15 5, 15 15, 5 15, 5 10, 0 10, 0 0 ))").norm(); assertThat(actual, is(expected)); }
@Test public void testEmptyData() { Attribute attribute = new AttributeImpl(FIELD, Collections.emptyList()); Optional<String> optionalWkt = GeometryUtility.createUnionOfGeometryAttribute( wktReader, wktWriter, attribute, new GeometryOperator.Context()); assertThat(optionalWkt.isPresent(), is(false)); }
@Test public void testBadData() { Attribute attribute = new AttributeImpl( FIELD, Collections.singletonList("POLYGON (( x 0, 10 0, 10 10, 0 10, 0 0))")); Optional<String> optionalWkt = GeometryUtility.createUnionOfGeometryAttribute( wktReader, wktWriter, attribute, new GeometryOperator.Context()); assertThat(optionalWkt.isPresent(), is(false)); }
@Test public void testGoodDataFollowedByBadData() throws ParseException { Attribute attribute = new AttributeImpl( FIELD, Arrays.asList( "POLYGON (( 0 0, 10 0, 10 10, 0 10, 0 0))", "POLYGON (( x 5, 15 5, 15 15, 5 15, 5 5))")); Optional<String> optionalWkt = GeometryUtility.createUnionOfGeometryAttribute( wktReader, wktWriter, attribute, new GeometryOperator.Context()); Geometry actual = wktReader.read(optionalWkt.get()).norm(); Geometry expected = wktReader.read("POLYGON (( 0 0, 10 0, 10 10, 0 10, 0 0))").norm(); assertThat(actual, is(expected)); }
@Test public void testBadDataFollowedByGoodData() throws ParseException { Attribute attribute = new AttributeImpl( FIELD, Arrays.asList( "POLYGON (( x 0, 10 0, 10 10, 0 10, 0 0))", "POLYGON (( 5 5, 15 5, 15 15, 5 15, 5 5))")); Optional<String> optionalWkt = GeometryUtility.createUnionOfGeometryAttribute( wktReader, wktWriter, attribute, new GeometryOperator.Context()); Geometry actual = wktReader.read(optionalWkt.get()).norm(); Geometry expected = wktReader.read("POLYGON (( 5 5, 15 5, 15 15, 5 15, 5 5))").norm(); assertThat(actual, is(expected)); }
@Test public void testBadDataFollowedByBadData() throws ParseException { Attribute attribute = new AttributeImpl( FIELD, Arrays.asList( "POLYGON (( x 0, 10 0, 10 10, 0 10, 0 0))", "POLYGON (( x 5, 15 5, 15 15, 5 15, 5 5))")); Optional<String> optionalWkt = GeometryUtility.createUnionOfGeometryAttribute( wktReader, wktWriter, attribute, new GeometryOperator.Context()); assertThat(optionalWkt.isPresent(), is(false)); }
@Test public void testUnionWithInvalidGeo() throws ParseException { String polygonWithHole = "POLYGON ((-2.009211 51.199649, -1.99911 51.231578, -1.915058 51.240884, " + "-1.9201379049078626 51.228738313629776, -1.895395 51.226235, " + "-1.9781007533907866 51.196335611502384, -2.009211 51.199649), " + "(-1.9880383632176948 51.194513502505224, -1.9848251778950785 " + "51.19299587819516, -1.9838038434104859 51.1939685777043, " + "-1.9880383632176948 51.194513502505224))"; Attribute attribute = new AttributeImpl(FIELD, Arrays.asList(polygonWithHole)); Optional<String> optionalWkt = GeometryUtility.createUnionOfGeometryAttribute( wktReader, wktWriter, attribute, new GeometryOperator.Context()); Geometry actual = wktReader.read(optionalWkt.get()).norm(); assertThat(actual.isValid(), is(true)); }