Learn R Programming

icosa (version 0.12.0)

surfacecentroid: Surface centroid point of a spherical point cloud

Description

This function calculated the projected place of the centroid from a pointset on the sphere.

Usage

surfacecentroid(x, ...)

# S4 method for matrix surfacecentroid( x, output = "polar", center = c(0, 0, 0), radius = authRadius, w = NULL )

# S4 method for data.frame surfacecentroid(x, ...)

# S4 method for SpatialPoints surfacecentroid(x, ...)

Value

Either an XYZ or a long-lat numeric vector.

Arguments

x

(matrix or data.frame) Numeric data, XYZ or longitude-latitude coordinates of the set of points.

...

Arguments passed to the matrix-method.

output

(character) The coordinate system of the output points. Can either be "polar" for longitude-latitude or "cartesian" for XYZ data.

center

(numeric) The center of the sphere in XYZ coordinates (default is 0,0,0).

radius

(numeric) The radius of the circle in case the input points have only polar coordinates. Unused when XYZ coordinates are entered. Defaults to the authalic radius of Earth ca. 6371.007km.

w

(numeric) If the points need to be weighed differently, then this can be indicated here. The argument is passed to weighted.mean.

Details

The function calculates the position of the centroid in 3D space (inside the sphere/Earth), which is then projected to the surface.

Examples

Run this code
# generate some random points
allData <- rpsphere(1000)
# select only a subset
points<-allData[allData[,3]>1500,]
# transform to 2d
 points2 <- CarToPol(points, norad=TRUE)
# the spherical centroid
sc <- surfacecentroid(points2, output="polar")
sc

#3d plot
plot(points2, xlim=c(-180, 180), ylim=c(-90, 90))
points(sc[1], sc[2], col="red", cex=5, pch=3)

Run the code above in your browser using DataLab