Title: | Smallest Enclosing Disc for Latitude and Longitude Points |
---|---|
Description: | Find the smallest circle that contains all longitude and latitude input points. From the generated center and radius, variable side polygons can be created, navigation based on bearing and distance can be applied, and more. Based on a modified version of Welzl's algorithm for smallest circle. Distance calculations are based on the haversine formula. Calculations for distance, midpoint, bearing and more are derived from <https://www.movable-type.co.uk>. |
Authors: | Shant Sukljian <[email protected]> |
Maintainer: | Shant Sukljian <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.1 |
Built: | 2024-10-31 22:11:22 UTC |
Source: | CRAN |
Generates a latitude and longitude point that is equidistant to up to three latitude and longitude points
geo_midpoint(coordinate_matrix, alternative = FALSE)
geo_midpoint(coordinate_matrix, alternative = FALSE)
coordinate_matrix |
A matrix of latitude and longitude columns and up to three rows |
alternative |
Whether to use alternative line creation method. Could be needed when nearly inverse angles cause intersections to be ambiguous. |
Returns a vector of length 2 containing a latitude and longitude point.
Shant Sukljian
# Load required packages require(mapview) require(sp) # Create sample geo dataset sample_coord <- matrix( c( sample(327131680:419648450, 3) / 10000000, sample(-1147301410:-1241938690, 3) / 10000000 ), ncol = 2 ) # Generate circumcenter and radius gmp <- geo_midpoint(sample_coord) # Find distance to circumcenter radius <- geo_point_dist(rbind(sample_coord[1, ], gmp)) # Create 80 sided polygon based on gmp's center and radius gmp_poly <- geo_surround_poly(gmp, radius, 80) # Join all the points into a single matrix bound_poly <- rbind(sample_coord, as.vector(gmp), gmp_poly) # Create SpacialPoints object and pass to mapview for visualization mapview( SpatialPoints( bound_poly[,c(2, 1)], proj4string = CRS("+proj=longlat +datum=WGS84") ) )
# Load required packages require(mapview) require(sp) # Create sample geo dataset sample_coord <- matrix( c( sample(327131680:419648450, 3) / 10000000, sample(-1147301410:-1241938690, 3) / 10000000 ), ncol = 2 ) # Generate circumcenter and radius gmp <- geo_midpoint(sample_coord) # Find distance to circumcenter radius <- geo_point_dist(rbind(sample_coord[1, ], gmp)) # Create 80 sided polygon based on gmp's center and radius gmp_poly <- geo_surround_poly(gmp, radius, 80) # Join all the points into a single matrix bound_poly <- rbind(sample_coord, as.vector(gmp), gmp_poly) # Create SpacialPoints object and pass to mapview for visualization mapview( SpatialPoints( bound_poly[,c(2, 1)], proj4string = CRS("+proj=longlat +datum=WGS84") ) )
Creates a new latitude, longitude point based on an origin point, bearing and distance
geo_move_point(coordinates, bearing, distance)
geo_move_point(coordinates, bearing, distance)
coordinates |
A vector contaning one latitude and longitude point |
bearing |
The angle relative to north to move towards |
distance |
The distance in kilometers to move away from the origin point |
Returns a vector of length 2 containing a latitude and longitude point.
Shant Sukljian
# Load required packages require(mapview) require(sp) # Create sample geo dataset sample_coord <- matrix( c( sample(327131680:419648450, 1) / 10000000, sample(-1147301410:-1241938690, 1) / 10000000 ), ncol = 2 ) # Create new point (gmp <- geo_move_point(sample_coord, sample(0:359, 1), 500)) # Join all the points into a single matrix bound_poly <- rbind(sample_coord, gmp) # Create SpacialPoints object and pass to mapview for visualization mapview( SpatialPoints( bound_poly[,c(2, 1)], proj4string = CRS("+proj=longlat +datum=WGS84") ) )
# Load required packages require(mapview) require(sp) # Create sample geo dataset sample_coord <- matrix( c( sample(327131680:419648450, 1) / 10000000, sample(-1147301410:-1241938690, 1) / 10000000 ), ncol = 2 ) # Create new point (gmp <- geo_move_point(sample_coord, sample(0:359, 1), 500)) # Join all the points into a single matrix bound_poly <- rbind(sample_coord, gmp) # Create SpacialPoints object and pass to mapview for visualization mapview( SpatialPoints( bound_poly[,c(2, 1)], proj4string = CRS("+proj=longlat +datum=WGS84") ) )
Calculates the distance in kilometers between up to a combination of three latitude, longitude points
geo_point_dist(coordinate_matrix, matrix = FALSE)
geo_point_dist(coordinate_matrix, matrix = FALSE)
coordinate_matrix |
A matrix of latitude and longitude columns and up to three rows of points |
matrix |
Generates a matrix that shows/preseves the relationship between point combinations and the respective distance between them |
An input matrix with two rows returns a vector of length 1 containing the calculated distance. If the matrix argument is set to FALSE and an input matrix with three rows is given as the coordinate_matrix argument a vector of length 3 containing the calculated distances is returned. If the matrix argument is set to TRUE and an input matrix with three rows is given as the coordinate_matrix argument a 3 by 3 matrix of distances is returned.
Shant Sukljian
# Load required packages require(mapview) require(sp) # Create sample geo dataset sample_coord <- matrix( c( sample(327131680:419648450, 3) / 10000000, sample(-1147301410:-1241938690, 3) / 10000000 ), ncol = 2 ) # Calculate distances (gpd <- geo_point_dist(sample_coord)) # Calculate distances and preserve relationship (Useful for three input points) (gpd <- geo_point_dist(sample_coord, matrix = TRUE)) # Create SpacialPoints object and pass to mapview for visualization mapview( SpatialPoints( sample_coord[,c(2, 1)], proj4string = CRS("+proj=longlat +datum=WGS84") ) )
# Load required packages require(mapview) require(sp) # Create sample geo dataset sample_coord <- matrix( c( sample(327131680:419648450, 3) / 10000000, sample(-1147301410:-1241938690, 3) / 10000000 ), ncol = 2 ) # Calculate distances (gpd <- geo_point_dist(sample_coord)) # Calculate distances and preserve relationship (Useful for three input points) (gpd <- geo_point_dist(sample_coord, matrix = TRUE)) # Create SpacialPoints object and pass to mapview for visualization mapview( SpatialPoints( sample_coord[,c(2, 1)], proj4string = CRS("+proj=longlat +datum=WGS84") ) )
Calculates the bearing angle in degrees between two latitude, longitude points
geo_points_bearing(coordinate_pair)
geo_points_bearing(coordinate_pair)
coordinate_pair |
A matrix of latitude and longitude columns and two rows of points |
A vector of length 1 containing a bearing
Shant Sukljian
# Load required packages require(mapview) require(sp) # Create sample geo dataset sample_coord <- matrix( c( sample(327131680:419648450, 2) / 10000000, sample(-1147301410:-1241938690, 2) / 10000000 ), ncol = 2 ) # Calculate bearing (gpb <- geo_points_bearing(sample_coord)) # Create SpacialPoints object and pass to mapview for visualization mapview( SpatialPoints( sample_coord[,c(2, 1)], proj4string = CRS("+proj=longlat +datum=WGS84") ) )
# Load required packages require(mapview) require(sp) # Create sample geo dataset sample_coord <- matrix( c( sample(327131680:419648450, 2) / 10000000, sample(-1147301410:-1241938690, 2) / 10000000 ), ncol = 2 ) # Calculate bearing (gpb <- geo_points_bearing(sample_coord)) # Create SpacialPoints object and pass to mapview for visualization mapview( SpatialPoints( sample_coord[,c(2, 1)], proj4string = CRS("+proj=longlat +datum=WGS84") ) )
Generates a center point and radius that represent the smallest circle that contains all input points
geo_sed(coordinate_matrix)
geo_sed(coordinate_matrix)
coordinate_matrix |
A matrix of latitude and longitude columns and any chosen number of rows to generate a smallest circle arround |
Returns a list of three elements named radius, center and making. Radius contains a single value representing the circle radius. Center contains a vector of length 2 representing the circle center latitude and longitude. Making contains a matrix of the latitude and longitude points that lie on the final smallest circle circumference.
Shant Sukljian
geo_trivial_circle
geo_point_dist
# Load required packages require(mapview) require(sp) # Create sample geo dataset sample_coord <- matrix( c( sample(327131680:419648450, 10) / 10000000, sample(-1147301410:-1241938690, 10) / 10000000 ), ncol = 2 ) # Generate sed center and radius gsc <- geo_sed(sample_coord) # Create 80 sided polygon based on gsc's center and radius gsc_poly <- geo_surround_poly(gsc$center, gsc$radius, 80) # Join all the points into a single matrix bound_poly <- rbind(sample_coord, gsc$center, gsc_poly) # Create SpacialPoints object and pass to mapview for visualization mapview( SpatialPoints( bound_poly[,c(2, 1)], proj4string = CRS("+proj=longlat +datum=WGS84") ) )
# Load required packages require(mapview) require(sp) # Create sample geo dataset sample_coord <- matrix( c( sample(327131680:419648450, 10) / 10000000, sample(-1147301410:-1241938690, 10) / 10000000 ), ncol = 2 ) # Generate sed center and radius gsc <- geo_sed(sample_coord) # Create 80 sided polygon based on gsc's center and radius gsc_poly <- geo_surround_poly(gsc$center, gsc$radius, 80) # Join all the points into a single matrix bound_poly <- rbind(sample_coord, gsc$center, gsc_poly) # Create SpacialPoints object and pass to mapview for visualization mapview( SpatialPoints( bound_poly[,c(2, 1)], proj4string = CRS("+proj=longlat +datum=WGS84") ) )
Generates a collection of points that are equidistant to the center coordinates given and are distributed equally around the center
geo_surround_poly(coordinates, distance, sides)
geo_surround_poly(coordinates, distance, sides)
coordinates |
A vector of the center latitude and longitude point |
distance |
Distance to move away from center for each bearing |
sides |
Number of polygon sides |
Returns a matrix of latitude and longitude points.
Shant Sukljian
# Load required packages library(mapview) library(sp) # Create sample geo dataset sample_coord <- matrix( c( sample(327131680:419648450, 1) / 10000000, sample(-1147301410:-1241938690, 1) / 10000000 ), ncol = 2 ) # Create 80 sided polygon based on a random center and radius geo_poly <- geo_surround_poly(sample_coord, sample(50:500, 1), 80) # Join all the points into a single matrix bound_poly <- rbind(sample_coord, geo_poly) # Create SpacialPoints object and pass to mapview for visualization mapview( SpatialPoints( bound_poly[,c(2, 1)], proj4string = CRS("+proj=longlat +datum=WGS84") ) )
# Load required packages library(mapview) library(sp) # Create sample geo dataset sample_coord <- matrix( c( sample(327131680:419648450, 1) / 10000000, sample(-1147301410:-1241938690, 1) / 10000000 ), ncol = 2 ) # Create 80 sided polygon based on a random center and radius geo_poly <- geo_surround_poly(sample_coord, sample(50:500, 1), 80) # Join all the points into a single matrix bound_poly <- rbind(sample_coord, geo_poly) # Create SpacialPoints object and pass to mapview for visualization mapview( SpatialPoints( bound_poly[,c(2, 1)], proj4string = CRS("+proj=longlat +datum=WGS84") ) )
Generates a center point and radius that represent the smallest circle that contains up to three input points
geo_trivial_circle(coordinate_matrix, ...)
geo_trivial_circle(coordinate_matrix, ...)
coordinate_matrix |
A matrix of latitude and longitude columns and up to three rows |
... |
'alternative' argument to be used when calling |
Returns a list of three elements named radius, center and making. Radius contains a single value representing the circle radius. Center contains a vector of length 2 representing the circle center latitude and longitude. Making contains a matrix of the latitude and longitude points were used as the coordinate_matrix argument.
Shant Sukljian
# Load required packages require(mapview) require(sp) # Create sample geo dataset sample_coord <- matrix( c( sample(327131680:419648450, 3) / 10000000, sample(-1147301410:-1241938690, 3) / 10000000 ), ncol = 2 ) # Generate sed center and radius gtc <- geo_trivial_circle(sample_coord) # Create 80 sided polygon based on gtc's center and radius gtc_poly <- geo_surround_poly(gtc$center, gtc$radius, 80) # Join all the points into a single matrix bound_poly <- rbind(sample_coord, gtc$center, gtc_poly) # Create SpacialPoints object and pass to mapview for visualization mapview( SpatialPoints( bound_poly[,c(2, 1)], proj4string = CRS("+proj=longlat +datum=WGS84") ) )
# Load required packages require(mapview) require(sp) # Create sample geo dataset sample_coord <- matrix( c( sample(327131680:419648450, 3) / 10000000, sample(-1147301410:-1241938690, 3) / 10000000 ), ncol = 2 ) # Generate sed center and radius gtc <- geo_trivial_circle(sample_coord) # Create 80 sided polygon based on gtc's center and radius gtc_poly <- geo_surround_poly(gtc$center, gtc$radius, 80) # Join all the points into a single matrix bound_poly <- rbind(sample_coord, gtc$center, gtc_poly) # Create SpacialPoints object and pass to mapview for visualization mapview( SpatialPoints( bound_poly[,c(2, 1)], proj4string = CRS("+proj=longlat +datum=WGS84") ) )