pub trait Centroid {
    // Required method
    fn centroid(&self) -> PointArray;
}
Expand description

Calculation of the centroid. The centroid is the arithmetic mean position of all points in the shape. Informally, it is the point at which a cutout of the shape could be perfectly balanced on the tip of a pin. The geometric centroid of a convex object always lies in the object. A non-convex object might have a centroid that is outside the object itself.

Examples

use geoarrow2::algorithm::geo::Centroid;
use geoarrow2::array::PolygonArray;
use geoarrow2::trait_::GeoArrayAccessor;
use geo::{point, polygon};

// rhombus shaped polygon
let polygon = polygon![
    (x: -2., y: 1.),
    (x: 1., y: 3.),
    (x: 4., y: 1.),
    (x: 1., y: -1.),
    (x: -2., y: 1.),
];
let polygon_array: PolygonArray<i32> = vec![polygon].into();

assert_eq!(
    Some(point!(x: 1., y: 1.)),
    polygon_array.centroid().get_as_geo(0),
);

Required Methods§

source

fn centroid(&self) -> PointArray

See: https://en.wikipedia.org/wiki/Centroid

Examples
use geoarrow2::algorithm::geo::Centroid;
use geoarrow2::array::LineStringArray;
use geoarrow2::trait_::GeoArrayAccessor;
use geo::{line_string, point};

let line_string = line_string![
    (x: 40.02f64, y: 116.34),
    (x: 40.02f64, y: 118.23),
];
let line_string_array: LineStringArray<i32> = vec![line_string].into();

assert_eq!(
    Some(point!(x: 40.02, y: 117.285)),
    line_string_array.centroid().get_as_geo(0),
);

Implementors§