Skip to content

Commit 28cc6ab

Browse files
TestLineCentroid - hand-verifiable test (#176)
1 parent 657b42c commit 28cc6ab

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Find a bug or want to request a new feature? Please let us know by submitting a
7171
Esri welcomes contributions from anyone and everyone. Please see our [guidelines for contributing](https://github.com/esri/contributing)
7272

7373
## Licensing
74-
Copyright 2013-2019 Esri
74+
Copyright 2013-2020 Esri
7575

7676
Licensed under the Apache License, Version 2.0 (the "License");
7777
you may not use this file except in compliance with the License.

hive/src/test/java/com/esri/hadoop/hive/TestStCentroid.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ public void TestLineCentroid() throws Exception {
3939
BytesWritable bwGeom = stLn.evaluate(new Text("linestring (0 0, 6 0)"));
4040
BytesWritable bwCentroid = stCtr.evaluate(bwGeom);
4141
validatePoint(new Point(3,0), bwCentroid);
42-
bwGeom = stLn.evaluate(new Text("linestring (0 0, 2 4, 6 8)"));
42+
bwGeom = stLn.evaluate(new Text("linestring (0 0, 0 4, 12 4)"));
4343
bwCentroid = stCtr.evaluate(bwGeom);
44-
validatePoint(new Point(3,4), bwCentroid);
44+
// L1 = 4, L2 = 12, W1 = 0.25, W2 = 0.75, X = W1 * 0 + W2 * 6, Y = W1 * 2 + W2 * 4
45+
// Or like centroid of multipoint of 1 of (0 2) and 3 of (6 4)
46+
validatePoint(new Point(4.5, 3.5), bwCentroid);
4547
}
4648

4749
@Test
@@ -51,13 +53,16 @@ public void TestPolygonCentroid() throws Exception {
5153
BytesWritable bwGeom = stPoly.evaluate(new Text("polygon ((0 0, 0 8, 8 8, 8 0, 0 0))"));
5254
BytesWritable bwCentroid = stCtr.evaluate(bwGeom);
5355
validatePoint(new Point(4,4), bwCentroid);
54-
bwGeom = stPoly.evaluate(new Text("polygon ((1 1, 5 1, 3 4))"));
56+
bwGeom = stPoly.evaluate(new Text("polygon ((1 1, 5 1, 3 4, 1 1))"));
5557
bwCentroid = stCtr.evaluate(bwGeom);
5658
validatePoint(new Point(3,2), bwCentroid);
59+
bwGeom = stPoly.evaluate(new Text("polygon ((14 0, -14 0, -2 24, 2 24, 14 0))"));
60+
bwCentroid = stCtr.evaluate(bwGeom); // Cross-checked with ...
61+
validatePoint(new Point(0,9), bwCentroid); // ... omnicalculator.com/math/centroid
5762
}
5863

5964
/**
60-
* Validates the geometry writable.
65+
* Validates the centroid geometry writable.
6166
*
6267
* @param point
6368
* the represented point location.
@@ -66,13 +71,18 @@ public void TestPolygonCentroid() throws Exception {
6671
*/
6772
private static void validatePoint(Point point, BytesWritable geometryAsWritable) {
6873
ST_X getX = new ST_X();
69-
DoubleWritable xAsWritable = getX.evaluate(geometryAsWritable);
70-
assertNotNull("The x writable must not be null!", xAsWritable);
71-
7274
ST_Y getY = new ST_Y();
75+
DoubleWritable xAsWritable = getX.evaluate(geometryAsWritable);
7376
DoubleWritable yAsWritable = getY.evaluate(geometryAsWritable);
74-
assertNotNull("The y writable must not be null!", yAsWritable);
7577

78+
if (null == xAsWritable || null == yAsWritable ||
79+
Math.abs(point.getX() - xAsWritable.get()) > Epsilon ||
80+
Math.abs(point.getY() - yAsWritable.get()) > Epsilon)
81+
System.err.println("validateCentroid: " + (new ST_AsText()).evaluate(geometryAsWritable)
82+
+ " ~ " + point);
83+
84+
assertNotNull("The x writable must not be null!", xAsWritable);
85+
assertNotNull("The y writable must not be null!", yAsWritable);
7686
assertEquals("Longitude is different!", point.getX(), xAsWritable.get(), Epsilon);
7787
assertEquals("Latitude is different!", point.getY(), yAsWritable.get(), Epsilon);
7888
}

pom.xml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,19 @@
123123
<profile>
124124
<id>jackson-2.9</id>
125125
<properties>
126-
<jackson.version>2.9.9</jackson.version>
126+
<jackson.version>2.9.10</jackson.version>
127127
</properties>
128128
</profile>
129129
<profile>
130130
<id>jackson-2.10</id>
131131
<properties>
132-
<jackson.version>2.10.4</jackson.version>
132+
<jackson.version>2.10.5</jackson.version>
133133
</properties>
134134
</profile>
135135
<profile>
136136
<id>jackson-2.11</id>
137137
<properties>
138-
<jackson.version>2.11.0</jackson.version>
138+
<jackson.version>2.11.2</jackson.version>
139139
</properties>
140140
</profile>
141141

@@ -163,6 +163,12 @@
163163
<geometry.version>2.2.3</geometry.version>
164164
</properties>
165165
</profile>
166+
<profile>
167+
<id>geometry-2.2.4</id>
168+
<properties>
169+
<geometry.version>2.2.4</geometry.version>
170+
</properties>
171+
</profile>
166172

167173
<profile>
168174
<id>hadoop-1.1</id>
@@ -227,7 +233,7 @@
227233
<profile>
228234
<id>hadoop-2.10</id>
229235
<properties>
230-
<hadoop.version>2.10.0</hadoop.version>
236+
<hadoop.version>2.10.1</hadoop.version>
231237
</properties>
232238
</profile>
233239
<profile>
@@ -239,7 +245,7 @@
239245
<profile>
240246
<id>hadoop-3.1</id>
241247
<properties>
242-
<hadoop.version>3.1.3</hadoop.version>
248+
<hadoop.version>3.1.4</hadoop.version>
243249
</properties>
244250
</profile>
245251
<profile>
@@ -410,9 +416,9 @@
410416
<!-- Versions for dependencies -->
411417
<hadoop.version>3.2.0</hadoop.version>
412418
<hive.version>3.1.2</hive.version>
413-
<jackson.version>2.9.9</jackson.version>
419+
<jackson.version>2.10.5</jackson.version>
414420
<logging.version>1.1.3</logging.version>
415-
<geometry.version>2.2.3</geometry.version>
421+
<geometry.version>2.2.4</geometry.version>
416422
<junit.version>4.11</junit.version>
417423

418424
<!-- Versions for plugins -->

0 commit comments

Comments
 (0)