Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit93cb31c

Browse files
ST_Centroid: Centroid not Envelope Center (#153)
1 parent40aaa6b commit93cb31c

File tree

7 files changed

+551
-467
lines changed

7 files changed

+551
-467
lines changed

‎build.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<dependencygroupId="org.apache.hadoop"artifactId="hadoop-client"version="2.2.0"/>
77
<dependencygroupId="org.apache.hive"artifactId="hive-exec"version="0.12.0"/>
88
<dependencygroupId="org.apache.hive"artifactId="hive-serde"version="0.12.0"/>
9-
<dependencygroupId="com.esri.geometry"artifactId="esri-geometry-api"version="2.0.0"/>
9+
<dependencygroupId="com.esri.geometry"artifactId="esri-geometry-api"version="2.1.99"/><!-- 2.2.0-SNAPSHOT-->
1010
<dependencygroupId="com.fasterxml.jackson.core"artifactId="jackson-core"version="2.6.5"/>
1111
<dependencygroupId="com.fasterxml.jackson.core"artifactId="jackson-databind"version="2.6.5"/>
1212
</artifact:dependencies>

‎hive/src/main/java/com/esri/hadoop/hive/ST_Centroid.java‎

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@
1212

1313
@Description(
1414
name ="ST_Centroid",
15-
value ="_FUNC_(polygon) - returns thepoint that is the centerof thepolygon's envelope",
15+
value ="_FUNC_(geometry) - returns thecentroidof thegeometry",
1616
extended ="Example:\n"
17-
+" > SELECT _FUNC_(ST_GeomFromText('polygon ((0 0, 3 6, 6 0, 0 0))')) FROM src LIMIT 1; -- POINT(3 3)\n"
18-
+" > SELECT _FUNC_(ST_GeomFromText('polygon ((0 0, 0 8, 8 0, 0 0))')) FROM src LIMIT 1; -- POINT(4 4)\n"
17+
+" > SELECT _FUNC_(ST_GeomFromText('point (2 3)')); -- POINT(2 3)\n"
18+
+" > SELECT _FUNC_(ST_GeomFromText('multipoint ((0 0), (1 1), (1 -1), (6 0))')); -- POINT(2 0)\n"
19+
+" > SELECT _FUNC_(ST_GeomFromText('linestring ((0 0, 6 0))')); -- POINT(3 0)\n"
20+
+" > SELECT _FUNC_(ST_GeomFromText('linestring ((0 0, 2 4, 6 8))')); -- POINT(3 4)\n"
21+
+" > SELECT _FUNC_(ST_GeomFromText('polygon ((0 0, 0 8, 8 8, 8 0, 0 0))')); -- POINT(4 4)\n"
22+
+" > SELECT _FUNC_(ST_GeomFromText('polygon ((1 1, 5 1, 3 4))')); -- POINT(3 2)\n"
1923
)
2024

2125
publicclassST_CentroidextendsST_GeometryAccessor {
@@ -33,25 +37,7 @@ public BytesWritable evaluate(BytesWritable geomref) {
3337
returnnull;
3438
}
3539

36-
GeometryUtils.OGCTypeogcType =GeometryUtils.getType(geomref);
37-
switch(ogcType) {
38-
caseST_MULTIPOLYGON:
39-
caseST_POLYGON:
40-
intwkid =GeometryUtils.getWKID(geomref);
41-
SpatialReferencespatialReference =null;
42-
if (wkid !=GeometryUtils.WKID_UNKNOWN) {
43-
spatialReference =SpatialReference.create(wkid);
44-
}
45-
EnvelopeenvBound =newEnvelope();
46-
ogcGeometry.getEsriGeometry().queryEnvelope(envBound);
47-
Pointcentroid =newPoint((envBound.getXMin() +envBound.getXMax()) /2.,
48-
(envBound.getYMin() +envBound.getYMax()) /2.);
49-
returnGeometryUtils.geometryToEsriShapeBytesWritable(OGCGeometry.createFromEsriGeometry(centroid,
50-
spatialReference));
51-
default:
52-
LogUtils.Log_InvalidType(LOG,GeometryUtils.OGCType.ST_POLYGON,ogcType);
53-
returnnull;
54-
}
40+
returnGeometryUtils.geometryToEsriShapeBytesWritable(ogcGeometry.centroid());
5541
}
5642

5743
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp