Search in sources :

Example 1 with GeographyValidator

use of org.opensearch.geometry.utils.GeographyValidator in project OpenSearch by opensearch-project.

the class CircleTests method testInitValidation.

public void testInitValidation() {
    GeometryValidator validator = new GeographyValidator(true);
    IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> validator.validate(new Circle(20, 10, -1)));
    assertEquals("Circle radius [-1.0] cannot be negative", ex.getMessage());
    ex = expectThrows(IllegalArgumentException.class, () -> validator.validate(new Circle(20, 100, 1)));
    assertEquals("invalid latitude 100.0; must be between -90.0 and 90.0", ex.getMessage());
    ex = expectThrows(IllegalArgumentException.class, () -> validator.validate(new Circle(200, 10, 1)));
    assertEquals("invalid longitude 200.0; must be between -180.0 and 180.0", ex.getMessage());
    ex = expectThrows(IllegalArgumentException.class, () -> new StandardValidator(false).validate(new Circle(200, 10, 1, 20)));
    assertEquals("found Z value [1.0] but [ignore_z_value] parameter is [false]", ex.getMessage());
    new StandardValidator(true).validate(new Circle(200, 10, 1, 20));
}
Also used : GeometryValidator(org.opensearch.geometry.utils.GeometryValidator) GeographyValidator(org.opensearch.geometry.utils.GeographyValidator) StandardValidator(org.opensearch.geometry.utils.StandardValidator)

Example 2 with GeographyValidator

use of org.opensearch.geometry.utils.GeographyValidator in project OpenSearch by opensearch-project.

the class CircleTests method testBasicSerialization.

public void testBasicSerialization() throws IOException, ParseException {
    WellKnownText wkt = new WellKnownText(true, new GeographyValidator(true));
    assertEquals("CIRCLE (20.0 10.0 15.0)", wkt.toWKT(new Circle(20, 10, 15)));
    assertEquals(new Circle(20, 10, 15), wkt.fromWKT("circle (20.0 10.0 15.0)"));
    assertEquals("CIRCLE (20.0 10.0 15.0 25.0)", wkt.toWKT(new Circle(20, 10, 25, 15)));
    assertEquals(new Circle(20, 10, 25, 15), wkt.fromWKT("circle (20.0 10.0 15.0 25.0)"));
    assertEquals("CIRCLE EMPTY", wkt.toWKT(Circle.EMPTY));
    assertEquals(Circle.EMPTY, wkt.fromWKT("CIRCLE EMPTY)"));
}
Also used : GeographyValidator(org.opensearch.geometry.utils.GeographyValidator) WellKnownText(org.opensearch.geometry.utils.WellKnownText)

Example 3 with GeographyValidator

use of org.opensearch.geometry.utils.GeographyValidator in project OpenSearch by opensearch-project.

the class MultiPolygonTests method testBasicSerialization.

public void testBasicSerialization() throws IOException, ParseException {
    WellKnownText wkt = new WellKnownText(true, new GeographyValidator(true));
    assertEquals("MULTIPOLYGON (((3.0 1.0, 4.0 2.0, 5.0 3.0, 3.0 1.0)))", wkt.toWKT(new MultiPolygon(Collections.singletonList(new Polygon(new LinearRing(new double[] { 3, 4, 5, 3 }, new double[] { 1, 2, 3, 1 }))))));
    assertEquals(new MultiPolygon(Collections.singletonList(new Polygon(new LinearRing(new double[] { 3, 4, 5, 3 }, new double[] { 1, 2, 3, 1 })))), wkt.fromWKT("MULTIPOLYGON (((3.0 1.0, 4.0 2.0, 5.0 3.0, 3.0 1.0)))"));
    assertEquals("MULTIPOLYGON EMPTY", wkt.toWKT(MultiPolygon.EMPTY));
    assertEquals(MultiPolygon.EMPTY, wkt.fromWKT("MULTIPOLYGON EMPTY)"));
}
Also used : GeographyValidator(org.opensearch.geometry.utils.GeographyValidator) WellKnownText(org.opensearch.geometry.utils.WellKnownText)

Example 4 with GeographyValidator

use of org.opensearch.geometry.utils.GeographyValidator in project OpenSearch by opensearch-project.

the class PolygonTests method testBasicSerialization.

public void testBasicSerialization() throws IOException, ParseException {
    WellKnownText wkt = new WellKnownText(true, new GeographyValidator(true));
    assertEquals("POLYGON ((3.0 1.0, 4.0 2.0, 5.0 3.0, 3.0 1.0))", wkt.toWKT(new Polygon(new LinearRing(new double[] { 3, 4, 5, 3 }, new double[] { 1, 2, 3, 1 }))));
    assertEquals(new Polygon(new LinearRing(new double[] { 3, 4, 5, 3 }, new double[] { 1, 2, 3, 1 })), wkt.fromWKT("POLYGON ((3 1, 4 2, 5 3, 3 1))"));
    assertEquals("POLYGON ((3.0 1.0 5.0, 4.0 2.0 4.0, 5.0 3.0 3.0, 3.0 1.0 5.0))", wkt.toWKT(new Polygon(new LinearRing(new double[] { 3, 4, 5, 3 }, new double[] { 1, 2, 3, 1 }, new double[] { 5, 4, 3, 5 }))));
    assertEquals(new Polygon(new LinearRing(new double[] { 3, 4, 5, 3 }, new double[] { 1, 2, 3, 1 }, new double[] { 5, 4, 3, 5 })), wkt.fromWKT("POLYGON ((3 1 5, 4 2 4, 5 3 3, 3 1 5))"));
    // Auto closing in coerce mode
    assertEquals(new Polygon(new LinearRing(new double[] { 3, 4, 5, 3 }, new double[] { 1, 2, 3, 1 })), wkt.fromWKT("POLYGON ((3 1, 4 2, 5 3))"));
    assertEquals(new Polygon(new LinearRing(new double[] { 3, 4, 5, 3 }, new double[] { 1, 2, 3, 1 }, new double[] { 5, 4, 3, 5 })), wkt.fromWKT("POLYGON ((3 1 5, 4 2 4, 5 3 3))"));
    assertEquals(new Polygon(new LinearRing(new double[] { 3, 4, 5, 3 }, new double[] { 1, 2, 3, 1 }), Collections.singletonList(new LinearRing(new double[] { 0.5, 2.5, 2.0, 0.5 }, new double[] { 1.5, 1.5, 1.0, 1.5 }))), wkt.fromWKT("POLYGON ((3 1, 4 2, 5 3, 3 1), (0.5 1.5, 2.5 1.5, 2.0 1.0))"));
    assertEquals("POLYGON EMPTY", wkt.toWKT(Polygon.EMPTY));
    assertEquals(Polygon.EMPTY, wkt.fromWKT("POLYGON EMPTY)"));
}
Also used : GeographyValidator(org.opensearch.geometry.utils.GeographyValidator) WellKnownText(org.opensearch.geometry.utils.WellKnownText)

Example 5 with GeographyValidator

use of org.opensearch.geometry.utils.GeographyValidator in project OpenSearch by opensearch-project.

the class BaseGeometryTestCase method copyInstance.

@SuppressWarnings("unchecked")
@Override
protected T copyInstance(T instance, Version version) throws IOException {
    WellKnownText wkt = new WellKnownText(true, new GeographyValidator(true));
    String text = wkt.toWKT(instance);
    try {
        return (T) wkt.fromWKT(text);
    } catch (ParseException e) {
        throw new OpenSearchException(e);
    }
}
Also used : GeographyValidator(org.opensearch.geometry.utils.GeographyValidator) OpenSearchException(org.opensearch.OpenSearchException) ParseException(java.text.ParseException) WellKnownText(org.opensearch.geometry.utils.WellKnownText)

Aggregations

GeographyValidator (org.opensearch.geometry.utils.GeographyValidator)32 WellKnownText (org.opensearch.geometry.utils.WellKnownText)15 XContentParser (org.opensearch.common.xcontent.XContentParser)12 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)9 GeometryValidator (org.opensearch.geometry.utils.GeometryValidator)5 StandardValidator (org.opensearch.geometry.utils.StandardValidator)5 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1 LatLonPoint (org.apache.lucene.document.LatLonPoint)1 OpenSearchException (org.opensearch.OpenSearchException)1 OpenSearchParseException (org.opensearch.OpenSearchParseException)1 EffectivePoint (org.opensearch.common.geo.GeoUtils.EffectivePoint)1 Geometry (org.opensearch.geometry.Geometry)1 Line (org.opensearch.geometry.Line)1 LinearRing (org.opensearch.geometry.LinearRing)1 MultiLine (org.opensearch.geometry.MultiLine)1 MultiPolygon (org.opensearch.geometry.MultiPolygon)1 Point (org.opensearch.geometry.Point)1 Polygon (org.opensearch.geometry.Polygon)1 Rectangle (org.opensearch.geometry.Rectangle)1