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:
Nicholas Knize 2014-12-16 10:15:22 -06:00
parent ac0e37449e
commit 18d56f154c
2 changed files with 103 additions and 9 deletions

View File

@ -212,7 +212,7 @@ public class GeoJSONShapeParserTests extends ElasticsearchTestCase {
@Test @Test
public void testParse_OGCPolygonWithoutHoles() throws IOException { 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") String polygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Polygon")
.startArray("coordinates") .startArray("coordinates")
.startArray() .startArray()
@ -232,7 +232,7 @@ public class GeoJSONShapeParserTests extends ElasticsearchTestCase {
ElasticsearchGeoAssertions.assertPolygon(shape); ElasticsearchGeoAssertions.assertPolygon(shape);
// test ccw poly crossing dateline // test 2: ccw poly crossing dateline
polygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Polygon") polygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Polygon")
.startArray("coordinates") .startArray("coordinates")
.startArray() .startArray()
@ -251,11 +251,51 @@ public class GeoJSONShapeParserTests extends ElasticsearchTestCase {
shape = ShapeBuilder.parse(parser).build(); shape = ShapeBuilder.parse(parser).build();
ElasticsearchGeoAssertions.assertMultiPolygon(shape); 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 @Test
public void testParse_OGCPolygonWithHoles() throws IOException { 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") String polygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Polygon")
.startArray("coordinates") .startArray("coordinates")
.startArray() .startArray()
@ -281,7 +321,7 @@ public class GeoJSONShapeParserTests extends ElasticsearchTestCase {
ElasticsearchGeoAssertions.assertPolygon(shape); ElasticsearchGeoAssertions.assertPolygon(shape);
// test ccw poly crossing dateline // test 2: ccw poly crossing dateline
polygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Polygon") polygonGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "Polygon")
.startArray("coordinates") .startArray("coordinates")
.startArray() .startArray()
@ -306,6 +346,58 @@ public class GeoJSONShapeParserTests extends ElasticsearchTestCase {
shape = ShapeBuilder.parse(parser).build(); shape = ShapeBuilder.parse(parser).build();
ElasticsearchGeoAssertions.assertMultiPolygon(shape); 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 @Test
@ -538,7 +630,7 @@ public class GeoJSONShapeParserTests extends ElasticsearchTestCase {
@Test @Test
public void testParse_geometryCollection() throws IOException { public void testParse_geometryCollection() throws IOException {
String geometryCollectionGeoJson = XContentFactory.jsonBuilder().startObject() String geometryCollectionGeoJson = XContentFactory.jsonBuilder().startObject()
.field("type","GeometryCollection") .field("type", "GeometryCollection")
.startArray("geometries") .startArray("geometries")
.startObject() .startObject()
.field("type", "LineString") .field("type", "LineString")

View File

@ -241,8 +241,9 @@ public class ShapeBuilderTests extends ElasticsearchTestCase {
@Test @Test
public void testDatelineOGC() { public void testDatelineOGC() {
// view shape at https://gist.github.com/anonymous/7f1bb6d7e9cd72f5977c // tests that the following shape (defined in counterclockwise OGC order)
// expect 3 polygons, 1 with a hole // https://gist.github.com/anonymous/7f1bb6d7e9cd72f5977c crosses the dateline
// expected results: 3 polygons, 1 with a hole
// a giant c shape // a giant c shape
PolygonBuilder builder = ShapeBuilder.newPolygon() PolygonBuilder builder = ShapeBuilder.newPolygon()
@ -283,8 +284,9 @@ public class ShapeBuilderTests extends ElasticsearchTestCase {
@Test @Test
public void testDateline() { public void testDateline() {
// view shape at https://gist.github.com/anonymous/7f1bb6d7e9cd72f5977c // tests that the following shape (defined in clockwise non-OGC order)
// expect 3 polygons, 1 with a hole // https://gist.github.com/anonymous/7f1bb6d7e9cd72f5977c crosses the dateline
// expected results: 3 polygons, 1 with a hole
// a giant c shape // a giant c shape
PolygonBuilder builder = ShapeBuilder.newPolygon() PolygonBuilder builder = ShapeBuilder.newPolygon()