|
| 1 | +packagecom.esri.hadoop.hive; |
| 2 | + |
| 3 | +importstaticorg.junit.Assert.*; |
| 4 | +importorg.junit.Test; |
| 5 | + |
| 6 | +importorg.apache.hadoop.io.BytesWritable; |
| 7 | +importorg.apache.hadoop.io.Text; |
| 8 | +importorg.apache.hadoop.hive.serde2.io.DoubleWritable; |
| 9 | + |
| 10 | +importcom.esri.core.geometry.Point; |
| 11 | + |
| 12 | + |
| 13 | +publicclassTestStCentroid { |
| 14 | + |
| 15 | +privatefinalstaticdoubleEpsilon =0.0001; |
| 16 | + |
| 17 | +@Test |
| 18 | +publicvoidTestSimplePointCentroid()throwsException { |
| 19 | +finalST_CentroidstCtr =newST_Centroid(); |
| 20 | +finalST_PointstPt =newST_Point(); |
| 21 | +BytesWritablebwGeom =stPt.evaluate(newText("point (2 3)")); |
| 22 | +BytesWritablebwCentroid =stCtr.evaluate(bwGeom); |
| 23 | +validatePoint(newPoint(2,3),bwCentroid); |
| 24 | +} |
| 25 | + |
| 26 | +@Test |
| 27 | +publicvoidTestMultiPointCentroid()throwsException { |
| 28 | +finalST_CentroidstCtr =newST_Centroid(); |
| 29 | +finalST_MultiPointstMp =newST_MultiPoint(); |
| 30 | +BytesWritablebwGeom =stMp.evaluate(newText("multipoint ((0 0), (1 1), (1 -1), (6 0))")); |
| 31 | +BytesWritablebwCentroid =stCtr.evaluate(bwGeom); |
| 32 | +validatePoint(newPoint(2,0),bwCentroid); |
| 33 | +} |
| 34 | + |
| 35 | +@Test |
| 36 | +publicvoidTestLineCentroid()throwsException { |
| 37 | +finalST_CentroidstCtr =newST_Centroid(); |
| 38 | +finalST_LineStringstLn =newST_LineString(); |
| 39 | +BytesWritablebwGeom =stLn.evaluate(newText("linestring (0 0, 6 0)")); |
| 40 | +BytesWritablebwCentroid =stCtr.evaluate(bwGeom); |
| 41 | +validatePoint(newPoint(3,0),bwCentroid); |
| 42 | +bwGeom =stLn.evaluate(newText("linestring (0 0, 2 4, 6 8)")); |
| 43 | +bwCentroid =stCtr.evaluate(bwGeom); |
| 44 | +validatePoint(newPoint(3,4),bwCentroid); |
| 45 | +} |
| 46 | + |
| 47 | +@Test |
| 48 | +publicvoidTestPolygonCentroid()throwsException { |
| 49 | +finalST_CentroidstCtr =newST_Centroid(); |
| 50 | +finalST_PolygonstPoly =newST_Polygon(); |
| 51 | +BytesWritablebwGeom =stPoly.evaluate(newText("polygon ((0 0, 0 8, 8 8, 8 0, 0 0))")); |
| 52 | +BytesWritablebwCentroid =stCtr.evaluate(bwGeom); |
| 53 | +validatePoint(newPoint(4,4),bwCentroid); |
| 54 | +bwGeom =stPoly.evaluate(newText("polygon ((1 1, 5 1, 3 4))")); |
| 55 | +bwCentroid =stCtr.evaluate(bwGeom); |
| 56 | +validatePoint(newPoint(3,2),bwCentroid); |
| 57 | +} |
| 58 | + |
| 59 | +/** |
| 60 | + * Validates the geometry writable. |
| 61 | + * |
| 62 | + * @param point |
| 63 | + * the represented point location. |
| 64 | + * @param geometryAsWritable |
| 65 | + * the geometry represented as {@link BytesWritable}. |
| 66 | + */ |
| 67 | +privatestaticvoidvalidatePoint(Pointpoint,BytesWritablegeometryAsWritable) { |
| 68 | +ST_XgetX =newST_X(); |
| 69 | +DoubleWritablexAsWritable =getX.evaluate(geometryAsWritable); |
| 70 | +assertNotNull("The x writable must not be null!",xAsWritable); |
| 71 | + |
| 72 | +ST_YgetY =newST_Y(); |
| 73 | +DoubleWritableyAsWritable =getY.evaluate(geometryAsWritable); |
| 74 | +assertNotNull("The y writable must not be null!",yAsWritable); |
| 75 | + |
| 76 | +assertEquals("Longitude is different!",point.getX(),xAsWritable.get(),Epsilon); |
| 77 | +assertEquals("Latitude is different!",point.getY(),yAsWritable.get(),Epsilon); |
| 78 | +} |
| 79 | + |
| 80 | +} |