src/main/java/de/blau/android/util/Geometry.java
/**
     * Calculate the centroid of a way
     * 
     * @param way way to calculate the centroid of
     * @return WGS84 coordinates of centroid, null if the way has problems and if the way has length or area zero return
     *         the coordinates of the first node
     */
Calculate the centroid of a way

@param way way to calculate the centroid of
@return WGS84 coordinates of centroid, null if the way has problems and if the way has length or area zero return
the coordinates of the first node
Calculate the centroid of a way @param way way to calculate the centroid of @return WGS84 coordinates of centroid null if the way has problems and if the way has length or area zero return the coordinates of the first node
@Nullable
    public static double[] centroidLonLat(@Nullable final Way way) {
        if (way == null || way.getNodes().isEmpty()) {
            return null;
        }
        List<Node> nodes = way.getNodes();
        Coordinates[] points = new Coordinates[nodes.size()];
        for (int i = 0; i < nodes.size(); i++) {
            points[i] = new Coordinates(0.0f, 0.0f);
            points[i].x = nodes.get(i).getLon() / 1E7D;
            points[i].y = GeoMath.latE7ToMercator(nodes.get(i).getLat());
        }
        Coordinates centroid = centroidXY(points, false);
        return new double[] { centroid.x, GeoMath.mercatorToLat(centroid.y) };
    }
@ Nullable public static double [ ] centroidLonLat ( @ Nullable final Way way ) { if ( way == null || way . getNodes ( ) . isEmpty ( ) ) { return null ; } List < Node > nodes = way . getNodes ( ) ; Coordinates [ ] points = new Coordinates [ nodes . size ( ) ] ; for ( int i = 0 ; i < nodes . size ( ) ; i ++ ) { points [ i ] = new Coordinates ( 0.0f , 0.0f ) ; points [ i ] . x = nodes . get ( i ) . getLon ( ) / 1E7D ; points [ i ] . y = GeoMath . latE7ToMercator ( nodes . get ( i ) . getLat ( ) ) ; } Coordinates centroid = centroidXY ( points , false ) ; return new double [ ] { centroid . x , GeoMath . mercatorToLat ( centroid . y ) } ; }
Calculate the centroid of a way
Calculate the centroid of a way
// loop over all nodes //