Skip to content

Commit

Permalink
TestLineCentroid - hand-verifiable test (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
randallwhitman authored Sep 25, 2020
1 parent 657b42c commit 28cc6ab
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Find a bug or want to request a new feature? Please let us know by submitting a
Esri welcomes contributions from anyone and everyone. Please see our [guidelines for contributing](https://github.com/esri/contributing)

## Licensing
Copyright 2013-2019 Esri
Copyright 2013-2020 Esri

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
26 changes: 18 additions & 8 deletions hive/src/test/java/com/esri/hadoop/hive/TestStCentroid.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ public void TestLineCentroid() throws Exception {
BytesWritable bwGeom = stLn.evaluate(new Text("linestring (0 0, 6 0)"));
BytesWritable bwCentroid = stCtr.evaluate(bwGeom);
validatePoint(new Point(3,0), bwCentroid);
bwGeom = stLn.evaluate(new Text("linestring (0 0, 2 4, 6 8)"));
bwGeom = stLn.evaluate(new Text("linestring (0 0, 0 4, 12 4)"));
bwCentroid = stCtr.evaluate(bwGeom);
validatePoint(new Point(3,4), bwCentroid);
// L1 = 4, L2 = 12, W1 = 0.25, W2 = 0.75, X = W1 * 0 + W2 * 6, Y = W1 * 2 + W2 * 4
// Or like centroid of multipoint of 1 of (0 2) and 3 of (6 4)
validatePoint(new Point(4.5, 3.5), bwCentroid);
}

@Test
Expand All @@ -51,13 +53,16 @@ public void TestPolygonCentroid() throws Exception {
BytesWritable bwGeom = stPoly.evaluate(new Text("polygon ((0 0, 0 8, 8 8, 8 0, 0 0))"));
BytesWritable bwCentroid = stCtr.evaluate(bwGeom);
validatePoint(new Point(4,4), bwCentroid);
bwGeom = stPoly.evaluate(new Text("polygon ((1 1, 5 1, 3 4))"));
bwGeom = stPoly.evaluate(new Text("polygon ((1 1, 5 1, 3 4, 1 1))"));
bwCentroid = stCtr.evaluate(bwGeom);
validatePoint(new Point(3,2), bwCentroid);
bwGeom = stPoly.evaluate(new Text("polygon ((14 0, -14 0, -2 24, 2 24, 14 0))"));
bwCentroid = stCtr.evaluate(bwGeom); // Cross-checked with ...
validatePoint(new Point(0,9), bwCentroid); // ... omnicalculator.com/math/centroid
}

/**
* Validates the geometry writable.
* Validates the centroid geometry writable.
*
* @param point
* the represented point location.
Expand All @@ -66,13 +71,18 @@ public void TestPolygonCentroid() throws Exception {
*/
private static void validatePoint(Point point, BytesWritable geometryAsWritable) {
ST_X getX = new ST_X();
DoubleWritable xAsWritable = getX.evaluate(geometryAsWritable);
assertNotNull("The x writable must not be null!", xAsWritable);

ST_Y getY = new ST_Y();
DoubleWritable xAsWritable = getX.evaluate(geometryAsWritable);
DoubleWritable yAsWritable = getY.evaluate(geometryAsWritable);
assertNotNull("The y writable must not be null!", yAsWritable);

if (null == xAsWritable || null == yAsWritable ||
Math.abs(point.getX() - xAsWritable.get()) > Epsilon ||
Math.abs(point.getY() - yAsWritable.get()) > Epsilon)
System.err.println("validateCentroid: " + (new ST_AsText()).evaluate(geometryAsWritable)
+ " ~ " + point);

assertNotNull("The x writable must not be null!", xAsWritable);
assertNotNull("The y writable must not be null!", yAsWritable);
assertEquals("Longitude is different!", point.getX(), xAsWritable.get(), Epsilon);
assertEquals("Latitude is different!", point.getY(), yAsWritable.get(), Epsilon);
}
Expand Down
20 changes: 13 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,19 @@
<profile>
<id>jackson-2.9</id>
<properties>
<jackson.version>2.9.9</jackson.version>
<jackson.version>2.9.10</jackson.version>
</properties>
</profile>
<profile>
<id>jackson-2.10</id>
<properties>
<jackson.version>2.10.4</jackson.version>
<jackson.version>2.10.5</jackson.version>
</properties>
</profile>
<profile>
<id>jackson-2.11</id>
<properties>
<jackson.version>2.11.0</jackson.version>
<jackson.version>2.11.2</jackson.version>
</properties>
</profile>

Expand Down Expand Up @@ -163,6 +163,12 @@
<geometry.version>2.2.3</geometry.version>
</properties>
</profile>
<profile>
<id>geometry-2.2.4</id>
<properties>
<geometry.version>2.2.4</geometry.version>
</properties>
</profile>

<profile>
<id>hadoop-1.1</id>
Expand Down Expand Up @@ -227,7 +233,7 @@
<profile>
<id>hadoop-2.10</id>
<properties>
<hadoop.version>2.10.0</hadoop.version>
<hadoop.version>2.10.1</hadoop.version>
</properties>
</profile>
<profile>
Expand All @@ -239,7 +245,7 @@
<profile>
<id>hadoop-3.1</id>
<properties>
<hadoop.version>3.1.3</hadoop.version>
<hadoop.version>3.1.4</hadoop.version>
</properties>
</profile>
<profile>
Expand Down Expand Up @@ -410,9 +416,9 @@
<!-- Versions for dependencies -->
<hadoop.version>3.2.0</hadoop.version>
<hive.version>3.1.2</hive.version>
<jackson.version>2.9.9</jackson.version>
<jackson.version>2.10.5</jackson.version>
<logging.version>1.1.3</logging.version>
<geometry.version>2.2.3</geometry.version>
<geometry.version>2.2.4</geometry.version>
<junit.version>4.11</junit.version>

<!-- Versions for plugins -->
Expand Down

0 comments on commit 28cc6ab

Please sign in to comment.