Adding unit tests for clockwise non-OGC ordering
Adding unit tests to validate cw defined polys not-crossing and crossing the dateline, respectively
This commit is contained in:
parent
ac0e37449e
commit
18d56f154c
|
@ -212,7 +212,7 @@ public class GeoJSONShapeParserTests extends ElasticsearchTestCase {
|
|||
|
||||
@Test
|
||||
public void testParse_OGCPolygonWithoutHoles() throws IOException {
|
||||
// test ccw poly not crossing dateline
|
||||
// test 1: ccw poly not crossing dateline
|
||||
String polygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Polygon")
|
||||
.startArray("coordinates")
|
||||
.startArray()
|
||||
|
@ -232,7 +232,7 @@ public class GeoJSONShapeParserTests extends ElasticsearchTestCase {
|
|||
|
||||
ElasticsearchGeoAssertions.assertPolygon(shape);
|
||||
|
||||
// test ccw poly crossing dateline
|
||||
// test 2: ccw poly crossing dateline
|
||||
polygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Polygon")
|
||||
.startArray("coordinates")
|
||||
.startArray()
|
||||
|
@ -251,11 +251,51 @@ public class GeoJSONShapeParserTests extends ElasticsearchTestCase {
|
|||
shape = ShapeBuilder.parse(parser).build();
|
||||
|
||||
ElasticsearchGeoAssertions.assertMultiPolygon(shape);
|
||||
|
||||
// test 3: cw poly not crossing dateline
|
||||
polygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Polygon")
|
||||
.startArray("coordinates")
|
||||
.startArray()
|
||||
.startArray().value(176.0).value(15.0).endArray()
|
||||
.startArray().value(180.0).value(10.0).endArray()
|
||||
.startArray().value(180.0).value(-10.0).endArray()
|
||||
.startArray().value(176.0).value(-15.0).endArray()
|
||||
.startArray().value(172.0).value(0.0).endArray()
|
||||
.startArray().value(176.0).value(15.0).endArray()
|
||||
.endArray()
|
||||
.endArray()
|
||||
.endObject().string();
|
||||
|
||||
parser = JsonXContent.jsonXContent.createParser(polygonGeoJson);
|
||||
parser.nextToken();
|
||||
shape = ShapeBuilder.parse(parser).build();
|
||||
|
||||
ElasticsearchGeoAssertions.assertPolygon(shape);
|
||||
|
||||
// test 4: cw poly crossing dateline
|
||||
polygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Polygon")
|
||||
.startArray("coordinates")
|
||||
.startArray()
|
||||
.startArray().value(176.0).value(15.0).endArray()
|
||||
.startArray().value(184.0).value(15.0).endArray()
|
||||
.startArray().value(184.0).value(0.0).endArray()
|
||||
.startArray().value(176.0).value(-15.0).endArray()
|
||||
.startArray().value(174.0).value(-10.0).endArray()
|
||||
.startArray().value(176.0).value(15.0).endArray()
|
||||
.endArray()
|
||||
.endArray()
|
||||
.endObject().string();
|
||||
|
||||
parser = JsonXContent.jsonXContent.createParser(polygonGeoJson);
|
||||
parser.nextToken();
|
||||
shape = ShapeBuilder.parse(parser).build();
|
||||
|
||||
ElasticsearchGeoAssertions.assertMultiPolygon(shape);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParse_OGCPolygonWithHoles() throws IOException {
|
||||
// test ccw poly not crossing dateline
|
||||
// test 1: ccw poly not crossing dateline
|
||||
String polygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Polygon")
|
||||
.startArray("coordinates")
|
||||
.startArray()
|
||||
|
@ -281,7 +321,7 @@ public class GeoJSONShapeParserTests extends ElasticsearchTestCase {
|
|||
|
||||
ElasticsearchGeoAssertions.assertPolygon(shape);
|
||||
|
||||
// test ccw poly crossing dateline
|
||||
// test 2: ccw poly crossing dateline
|
||||
polygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Polygon")
|
||||
.startArray("coordinates")
|
||||
.startArray()
|
||||
|
@ -306,6 +346,58 @@ public class GeoJSONShapeParserTests extends ElasticsearchTestCase {
|
|||
shape = ShapeBuilder.parse(parser).build();
|
||||
|
||||
ElasticsearchGeoAssertions.assertMultiPolygon(shape);
|
||||
|
||||
// test 3: cw poly not crossing dateline
|
||||
polygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Polygon")
|
||||
.startArray("coordinates")
|
||||
.startArray()
|
||||
.startArray().value(176.0).value(15.0).endArray()
|
||||
.startArray().value(180.0).value(10.0).endArray()
|
||||
.startArray().value(179.0).value(-10.0).endArray()
|
||||
.startArray().value(176.0).value(-15.0).endArray()
|
||||
.startArray().value(172.0).value(0.0).endArray()
|
||||
.startArray().value(176.0).value(15.0).endArray()
|
||||
.endArray()
|
||||
.startArray()
|
||||
.startArray().value(177.0).value(8.0).endArray()
|
||||
.startArray().value(179.0).value(10.0).endArray()
|
||||
.startArray().value(179.0).value(-8.0).endArray()
|
||||
.startArray().value(177.0).value(8.0).endArray()
|
||||
.endArray()
|
||||
.endArray()
|
||||
.endObject().string();
|
||||
|
||||
parser = JsonXContent.jsonXContent.createParser(polygonGeoJson);
|
||||
parser.nextToken();
|
||||
shape = ShapeBuilder.parse(parser).build();
|
||||
|
||||
ElasticsearchGeoAssertions.assertPolygon(shape);
|
||||
|
||||
// test 4: cw poly crossing dateline
|
||||
polygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Polygon")
|
||||
.startArray("coordinates")
|
||||
.startArray()
|
||||
.startArray().value(183.0).value(10.0).endArray()
|
||||
.startArray().value(183.0).value(-10.0).endArray()
|
||||
.startArray().value(176.0).value(-15.0).endArray()
|
||||
.startArray().value(172.0).value(0.0).endArray()
|
||||
.startArray().value(176.0).value(15.0).endArray()
|
||||
.startArray().value(183.0).value(10.0).endArray()
|
||||
.endArray()
|
||||
.startArray()
|
||||
.startArray().value(178.0).value(8.0).endArray()
|
||||
.startArray().value(182.0).value(8.0).endArray()
|
||||
.startArray().value(180.0).value(-8.0).endArray()
|
||||
.startArray().value(178.0).value(8.0).endArray()
|
||||
.endArray()
|
||||
.endArray()
|
||||
.endObject().string();
|
||||
|
||||
parser = JsonXContent.jsonXContent.createParser(polygonGeoJson);
|
||||
parser.nextToken();
|
||||
shape = ShapeBuilder.parse(parser).build();
|
||||
|
||||
ElasticsearchGeoAssertions.assertMultiPolygon(shape);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -241,8 +241,9 @@ public class ShapeBuilderTests extends ElasticsearchTestCase {
|
|||
|
||||
@Test
|
||||
public void testDatelineOGC() {
|
||||
// view shape at https://gist.github.com/anonymous/7f1bb6d7e9cd72f5977c
|
||||
// expect 3 polygons, 1 with a hole
|
||||
// tests that the following shape (defined in counterclockwise OGC order)
|
||||
// https://gist.github.com/anonymous/7f1bb6d7e9cd72f5977c crosses the dateline
|
||||
// expected results: 3 polygons, 1 with a hole
|
||||
|
||||
// a giant c shape
|
||||
PolygonBuilder builder = ShapeBuilder.newPolygon()
|
||||
|
@ -283,8 +284,9 @@ public class ShapeBuilderTests extends ElasticsearchTestCase {
|
|||
|
||||
@Test
|
||||
public void testDateline() {
|
||||
// view shape at https://gist.github.com/anonymous/7f1bb6d7e9cd72f5977c
|
||||
// expect 3 polygons, 1 with a hole
|
||||
// tests that the following shape (defined in clockwise non-OGC order)
|
||||
// https://gist.github.com/anonymous/7f1bb6d7e9cd72f5977c crosses the dateline
|
||||
// expected results: 3 polygons, 1 with a hole
|
||||
|
||||
// a giant c shape
|
||||
PolygonBuilder builder = ShapeBuilder.newPolygon()
|
||||
|
|
Loading…
Reference in New Issue