private static Cell getCentroidCell ( Polygon polygon ) { double area = 0.0 ; double x = 0.0 ; double y = 0.0 ; LineString exterior = polygon . getExteriorRing ( ) ; for ( int i = 0 , n = exterior . getNumPoints ( ) - 1 , j = n - 1 ; i < n ; j = i , i ++ ) { Coordinate a = exterior . getCoordinateN ( i ) ; Coordinate b = exterior . getCoordinateN ( j ) ; double f = a . x * b . y - b . x * a . y ; x += ( a . x + b . x ) * f ; y += ( a . y + b . y ) * f ; area += f * 3.0 ; } return new Cell ( x / area , y / area , 0.0 , polygon ) ; }
Get polygon centroid