Title: | An Interface to Rust's 'geo' Library |
---|---|
Description: | An R interface to the GeoRust crates 'geo' and 'geo-types' providing access to geometry primitives and algorithms. |
Authors: | Josiah Parry [aut, cre] |
Maintainer: | Josiah Parry <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.8 |
Built: | 2024-11-02 05:12:54 UTC |
Source: | https://github.com/josiahparry/rsgeo |
An R interface to the GeoRust crates 'geo' and 'geo-types' providing access to geometry primitives and algorithms.
Maintainer: Josiah Parry [email protected] (ORCID)
Useful links:
rsgeo
vectorGiven an vector of geometries, cast it as an rsgeo
class object.
as_rsgeo(x)
as_rsgeo(x)
x |
a geometry vector |
an object of class rsgeo
x <- sf::st_sfc(sf::st_point(c(0,0))) as_rsgeo(x)
x <- sf::st_sfc(sf::st_point(c(0,0))) as_rsgeo(x)
Calculates the bearing between two point geometries.
bearing_geodesic(x, y) bearing_haversine(x, y)
bearing_geodesic(x, y) bearing_haversine(x, y)
x |
an object of class |
y |
an object of class |
A vector of doubles of the calculated bearing for between x and y
x <- geom_point(runif(10, 0, 90), rnorm(10, 1, 90)) y <- geom_point(runif(10, 0, 90), rnorm(10, 1, 90)) bearing_geodesic(x, y) bearing_haversine(x, y)
x <- geom_point(runif(10, 0, 90), rnorm(10, 1, 90)) y <- geom_point(runif(10, 0, 90), rnorm(10, 1, 90)) bearing_geodesic(x, y) bearing_haversine(x, y)
From a vector of geometries identify different types of boundaries.
bounding_boxes(x) bounding_rect(x) minimum_rotated_rect(x) convex_hull(x) concave_hull(x, concavity) extreme_coords(x) bounding_box(x)
bounding_boxes(x) bounding_rect(x) minimum_rotated_rect(x) convex_hull(x) concave_hull(x, concavity) extreme_coords(x) bounding_box(x)
x |
an object of class |
concavity |
a value between 0 and 1 specifying the concavity of the convex hull |
Note that if you want a convex or concave hull over an entire vector of geometries
you must first union or combine them using either combine_geoms()
or union_geoms()
bounding_box()
returns a named vector of xmin, ymin, xmax, and ymax
bounding_boxes()
returns a list of bounding box numeric vectors for each geometry
bounding_rect()
returns an rs_POLYGON
of the bounding rectangle of each geometry
convex_hull()
returns an rs_POLYGON
of the convex hull for each geometry
concave_hull()
returns an rs_POLYGON
of the specified concavity for each geometry
extreme_coords()
returns the extreme coordinates of each geometry as a list where each element
is a named vector of xmin, ymin, xmax, and ymax where each element is a Point
geometry of the extreme value
minimum_rotated_rect()
returns the minimum rotated rectangle covering a geometry as an rs_POLYGON
lns <- geom_linestring( 1:20, runif(20, -5, 5), rep.int(1:5, 4) ) bounding_box(lns) bounding_boxes(lns) minimum_rotated_rect(lns) convex_hull(lns) concave_hull(lns, 0.5) extreme_coords(lns)
lns <- geom_linestring( 1:20, runif(20, -5, 5), rep.int(1:5, 4) ) bounding_box(lns) bounding_boxes(lns) minimum_rotated_rect(lns) convex_hull(lns) concave_hull(lns, 0.5) extreme_coords(lns)
Cast geometries to another type
cast_geoms(x, to)
cast_geoms(x, to)
x |
an object of class |
to |
a character scalar of the target geometry type. Must be one of
|
The below conversions are made available. The left hand column indicates the originating vector class and the right hand column indicates the class that it will can be cast to.
Note that correctness of conversions will not be checked or verified. If you
cast an rs_MULTIPOINT
to an rs_POLYGON
, the validity of the polygon
cannot be guaranteed.
Conversions from an rs_POLYGON
into an rs_LINESTRING
will result in only
the exterior ring of the polygon ignoring any interior rings if there are any.
From | To |
rs_POINT |
rs_MULTIPOINT |
rs_MULTIPOINT |
rs_POLYGON , rs_MULTIPOLYGON , rs_LINESTRING , rs_MULTILINESTRING |
rs_POLYGON |
rs_MULTIPOINT , rs_MULTIPOLYGON , rs_LINESTRING , rs_MULTILINESTRING |
rs_MULTIPOLYGON |
rs_MULTIPOINT , rs_MULTILINESTRING |
rs_LINESTRING |
rs_MULTIPOINT , rs_MULTILINESTRING , rs_POLYGON |
rs_MULTILINESTRING |
rs_MULTIPOINT , rs_MULTIPOLYGON |
An object of class rsgeo
ply <- geom_polygon(c(0, 1, 1, 0, 0), c(0, 0, 1, 1, 0)) cast_geoms(ply, "linestring") cast_geoms(ply, "multipoint")
ply <- geom_polygon(c(0, 1, 1, 0, 0), c(0, 0, 1, 1, 0)) cast_geoms(ply, "linestring") cast_geoms(ply, "multipoint")
Given a vector of geometries, extract their centroids.
centroids(x)
centroids(x)
x |
an object of class |
an object of class rs_POINT
lns <- geom_linestring(1:100, runif(100, -10, 10), rep.int(1:5, 20)) centroids(lns)
lns <- geom_linestring(1:100, runif(100, -10, 10), rep.int(1:5, 20)) centroids(lns)
For a given geometry, find the closest point on that geometry to a point. The closest point may be an intersection, a single point, or unable to be determined.
closest_point(x, y) closest_point_haversine(x, y)
closest_point(x, y) closest_point_haversine(x, y)
x |
an object of class |
y |
an object of class |
An rs_POINT
vector
x <- geom_linestring(1:100, runif(100, 0, 90), rep.int(1:10, 10)) y <- geom_point(runif(10, 0, 90), rnorm(10, 1, 90)) closest_point(x, y) closest_point_haversine(x, y)
x <- geom_linestring(1:100, runif(100, 0, 90), rep.int(1:10, 10)) y <- geom_point(runif(10, 0, 90), rnorm(10, 1, 90)) closest_point(x, y) closest_point_haversine(x, y)
Given a vector of geometries combine them into a single geometry.
combine_geoms(x) union_geoms(x)
combine_geoms(x) union_geoms(x)
x |
an object of class |
combine_geoms()
combine_geoms()
combines a vector of geometries into a vector of length one
their MULTI
counterpart.
rs_POINT
and rs_MULTIPOINT
-> rs_MULTIPOINT
rs_LINESTRING
and rs_MULTILINESTRING
-> rs_MULTILINESTRING
rs_POLYGON
and rs_MULTIPOLYGON
-> rs_MULTIPOLYGON
rs_GEOMETRYCOLLECTION
is not supported
union_geoms()
union_geoms()
creates a union of all geometries removing repeated points
or dissolving shared boundaries.
rs_POINT
- combines and removes repeated points
rs_MULTIPOINT
- combines removes repeated points
rs_LINESTRING
- combines and removes duplicated points
rs_MULTILINESTRING
- combines and removes duplicated points
rs_POLYGON
- unions geometries into a single geometry
rs_MULTIPOLYGON
- unions geometries into a single geometry
An object of class rsgeo
of length one.
pnts <- geom_point(runif(10), runif(10)) combine_geoms(pnts) lns <- geom_linestring(1:100, runif(100, -10, 10), rep.int(1:5, 20)) union_geoms(lns) x <- c(0, 1, 1, 0, 0) y <- c(0, 0, 1, 1, 0) p1 <- geom_polygon(x, y) p2 <- geom_polygon(x - 1, y + 0.5) z <- c(p1, p2) res <- union_geoms(z) res if (rlang::is_installed(c("sf", "wk"))) { plot(z) plot(res, lty = 3, border = "blue", add = TRUE, lwd = 4) }
pnts <- geom_point(runif(10), runif(10)) combine_geoms(pnts) lns <- geom_linestring(1:100, runif(100, -10, 10), rep.int(1:5, 20)) union_geoms(lns) x <- c(0, 1, 1, 0, 0) y <- c(0, 0, 1, 1, 0) p1 <- geom_polygon(x, y) p2 <- geom_polygon(x - 1, y + 0.5) z <- c(p1, p2) res <- union_geoms(z) res if (rlang::is_installed(c("sf", "wk"))) { plot(z) plot(res, lty = 3, border = "blue", add = TRUE, lwd = 4) }
Utility functions for accessing coordinates from a geometry.
coord_n(x, n) n_coords(x) coord_first(x) coord_last(x)
coord_n(x, n) n_coords(x) coord_first(x) coord_last(x)
x |
an object of class |
n |
the index position of the coordinate |
n_coords
returns the total number of coordinates in a geometry
coord_first()
returns the first coordinate in a geometry
coord_last()
returns the last coordinate in a geometry
coord_n()
returns the nth coordinate in a geometry
an object of class rs_POINT
.
Whereas n_coords()
returns an integer vector of the same length as x
.
lines <- geom_linestring(1:10, 1:10) n_coords(lines) coord_first(lines) coord_last(lines) coord_n(lines, 5)
lines <- geom_linestring(1:10, 1:10) n_coords(lines) coord_first(lines) coord_last(lines) coord_n(lines, 5)
Given an rsgeo
class object, extract the object's coordinates as a data frame.
Empty or missing geometries are ignored.
coords(x)
coords(x)
x |
an object of class |
A data.frame
with columns x
, y
. Additional columns are returned based
on the geometry type. Additional columns are:
id
line_id
: refers to the LineString
ID for rs_LINESTRING
, or the component LineString
in a MultiLineString
, or as the ring ID for a Polygon
.
multilinestring_id
polygon_id
multipolygon_id
pnt <- geom_point(3, 0.14) mpnt <- geom_multipoint(1:10, 10:1) ln <- geom_linestring(1:10, 10:1) ply <- geom_polygon(c(0, 1, 1, 0, 0), c(0, 0, 1, 1, 0)) coords(pnt) coords(mpnt) coords(ln) coords(union_geoms(rep(ln, 2))) coords(ply) coords(union_geoms(rep(ply, 2)))
pnt <- geom_point(3, 0.14) mpnt <- geom_multipoint(1:10, 10:1) ln <- geom_linestring(1:10, 10:1) ply <- geom_polygon(c(0, 1, 1, 0, 0), c(0, 0, 1, 1, 0)) coords(pnt) coords(mpnt) coords(ln) coords(union_geoms(rep(ln, 2))) coords(ply) coords(union_geoms(rep(ply, 2)))
Adds coordinates along a LineString
ensuring that no two coordinates are
further than a maximum distance apart from eachother.
densify_euclidean(x, max_distance) densify_haversine(x, max_distance)
densify_euclidean(x, max_distance) densify_haversine(x, max_distance)
x |
an object with linear geometries. Can be an |
max_distance |
the maximum allowed distance between coordinates. |
max_distance
expects meters for densify_haversine()
whereas
densify_euclidean()
expects the units of the geometry.
Be sure to use the appropriate densification function based on the type of geometries you have. rsgeo does not check if your coordinates are geographic or planar. It is up to you to choose the correct algorithm.
line <- geom_linestring(1:10, 10:1) densify_euclidean(line, 0.5) densify_haversine(line, 100000)
line <- geom_linestring(1:10, 10:1) densify_euclidean(line, 0.5) densify_haversine(line, 100000)
Calculates distances between two vectors of geometries. There are a number of different distance methods that can be utilized.
distance_euclidean_pairwise(x, y) distance_hausdorff_pairwise(x, y) distance_vicenty_pairwise(x, y) distance_geodesic_pairwise(x, y) distance_haversine_pairwise(x, y) distance_euclidean_matrix(x, y) distance_hausdorff_matrix(x, y) distance_vicenty_matrix(x, y) distance_geodesic_matrix(x, y) distance_haversine_matrix(x, y)
distance_euclidean_pairwise(x, y) distance_hausdorff_pairwise(x, y) distance_vicenty_pairwise(x, y) distance_geodesic_pairwise(x, y) distance_haversine_pairwise(x, y) distance_euclidean_matrix(x, y) distance_hausdorff_matrix(x, y) distance_vicenty_matrix(x, y) distance_geodesic_matrix(x, y) distance_haversine_matrix(x, y)
x |
and object of class |
y |
and object of class |
There are _pairwise()
and _matrix()
suffixed functions to
generate distances pairwise or as a dense matrix respectively.
The pairwise functions calculate distances between the ith element
of each vector. Whereas the matrix functions calculate the distance
between each and every geometry.
Euclidean distance should be used for planar geometries. Haversine, Geodesic, and Vicenty are all methods of calculating distance based on spherical geometries. There is no concept of spherical geometries in rsgeo, so choose your distance measure appropriately.
Hausdorff distance is calculated using Euclidean distance.
Haversine, Geodesic, and Vicenty distances only work with rs_POINT
geometries.
For _matrix
functions, returns a dense matrix of distances whereas _pairwise
functions return a numeric vector.
set.seed(1) x <- geom_point(runif(5, -1, 1), runif(5, -1, 1)) y <- rev(x) distance_euclidean_matrix(x, y) distance_hausdorff_matrix(x, y) distance_vicenty_matrix(x, y) distance_geodesic_matrix(x, y) distance_haversine_matrix(x, y) distance_euclidean_pairwise(x, y) distance_hausdorff_pairwise(x, y) distance_vicenty_pairwise(x, y) distance_geodesic_pairwise(x, y) distance_haversine_pairwise(x, y)
set.seed(1) x <- geom_point(runif(5, -1, 1), runif(5, -1, 1)) y <- rev(x) distance_euclidean_matrix(x, y) distance_hausdorff_matrix(x, y) distance_vicenty_matrix(x, y) distance_geodesic_matrix(x, y) distance_haversine_matrix(x, y) distance_euclidean_pairwise(x, y) distance_hausdorff_pairwise(x, y) distance_vicenty_pairwise(x, y) distance_geodesic_pairwise(x, y) distance_haversine_pairwise(x, y)
Expands geometries into a list of vectors of their components.
expand_geoms(x)
expand_geoms(x)
x |
an object of class |
rs_MULTIPOINT
expands into a vector of points
rs_LINESTRING
expands into a vector points
rs_MULTILINESTRING
expands into a vector of linestrings
rs_POLYGON
expands into a vector of linestrings
rs_MULTIPOLYGON
expands into a vector of polygons
If you wish to have a single vector returned, pass the results
into flatten_geoms()
.
A list of rsgeo
vectors containing each original geometry's
components as a new vector.
mpnts <- geom_multipoint(runif(10), runif(10), rep.int(1:5, 2)) expand_geoms(mpnts)
mpnts <- geom_multipoint(runif(10), runif(10), rep.int(1:5, 2)) expand_geoms(mpnts)
Given a LineString or MultiLineString, expand the geometry into each and every component Line.
explode_lines(x)
explode_lines(x)
x |
an object of class |
A LineString
is composed of one or more Line
s. A Line is a connected
by a start and end coordinate only.
an object of class rs_LINESTRING
x <- geom_linestring(1:10, 10:1) length(x) explode_lines(x)
x <- geom_linestring(1:10, 10:1) length(x) explode_lines(x)
Flatten a list of rsgeo vectors
flatten_geoms(x)
flatten_geoms(x)
x |
list object where each element is an object of class |
Returns an object of class rsgeo
pnts <- replicate( 10, geom_point(runif(1), runif(1)), simplify = FALSE ) flatten_geoms(pnts)
pnts <- replicate( 10, geom_point(runif(1), runif(1)), simplify = FALSE ) flatten_geoms(pnts)
Given two LineStrings compare thier similarity by calculating the Fréchet distance.
frechet_distance(x, y)
frechet_distance(x, y)
x |
an object of class |
y |
an object of class |
A numeric vector
x <- geom_linestring(1:10, runif(10, -1, 1)) y <- geom_linestring(1:10, runif(10, -3, 3)) frechet_distance(x, y)
x <- geom_linestring(1:10, runif(10, -1, 1)) y <- geom_linestring(1:10, runif(10, -3, 3)) frechet_distance(x, y)
Constructs geometries from numeric vectors.
geom_point(x, y) geom_multipoint(x, y, id = 1) geom_linestring(x, y, id = 1) geom_polygon(x, y, id = 1, ring = 1) geom_line(x, y)
geom_point(x, y) geom_multipoint(x, y, id = 1) geom_linestring(x, y, id = 1) geom_polygon(x, y, id = 1, ring = 1) geom_line(x, y)
x |
a vector of x coordinates |
y |
a vector of y coordinates |
id |
the feature identifier |
ring |
the id of the polygon ring |
In the case of geom_line()
, both x
and y
are vectors of rs_POINT
geometries. geom_line()
creates a straight line between two points.
an object of class rsgeo
geom_point(3, 0.14) geom_multipoint(1:10, 10:1) geom_linestring(1:10, 10:1) geom_polygon(c(0, 1, 1, 0, 0), c(0, 0, 1, 1, 0)) x <- geom_point(0, 0) y <- geom_point(5, 0) geom_line(x, y)
geom_point(3, 0.14) geom_multipoint(1:10, 10:1) geom_linestring(1:10, 10:1) geom_polygon(c(0, 1, 1, 0, 0), c(0, 0, 1, 1, 0)) x <- geom_point(0, 0) y <- geom_point(5, 0) geom_line(x, y)
Given a vector of point geometries, bearings, and distances, identify a destination location.
haversine_destination(x, bearing, distance)
haversine_destination(x, bearing, distance)
x |
an object of class |
bearing |
a numeric vector specifying the degree of the direction where 0 is north |
distance |
a numeric vector specifying the distance to travel in the direction specified by |
an object of class rs_POINT
# create 10 points at the origin pnts <- geom_point(rep(0, 10), rep(0, 10)) # set seed for reproducibiliy set.seed(1) # generate random bearings bearings <- runif(10, 0, 360) # generate random distances distances <- runif(10, 10000, 100000) # find the destinations dests <- haversine_destination(pnts, bearings, distances) # plot points if (rlang::is_installed(c("sf", "wk"))) { plot(pnts, pch = 3) plot(dests, add = TRUE, pch = 17) }
# create 10 points at the origin pnts <- geom_point(rep(0, 10), rep(0, 10)) # set seed for reproducibiliy set.seed(1) # generate random bearings bearings <- runif(10, 0, 360) # generate random distances distances <- runif(10, 10000, 100000) # find the destinations dests <- haversine_destination(pnts, bearings, distances) # plot points if (rlang::is_installed(c("sf", "wk"))) { plot(pnts, pch = 3) plot(dests, add = TRUE, pch = 17) }
Identifies the location between two points on a great circle along a specified fraction of the distance.
haversine_intermediate(x, y, distance)
haversine_intermediate(x, y, distance)
x |
an |
y |
an |
distance |
a numeric vector of either length 1 or the same length as x and y |
an object of class rs_POINT
x <- geom_point(1:10, rep(5, 10)) y <- geom_point(1:10, rep(0, 10)) res <- haversine_intermediate(x, y, 0.5) if (rlang::is_installed(c("wk", "sf"))) { plot( c(x, y, res), col = sort(rep.int(c("red", "blue", "purple"), 10)), pch = 16 ) }
x <- geom_point(1:10, rep(5, 10)) y <- geom_point(1:10, rep(0, 10)) res <- haversine_intermediate(x, y, 0.5) if (rlang::is_installed(c("wk", "sf"))) { plot( c(x, y, res), col = sort(rep.int(c("red", "blue", "purple"), 10)), pch = 16 ) }
Functions to ascertain the binary relationship between two geometry vectors. Binary predicates are provided both pairwise as a sparse matrix.
intersects_sparse(x, y) intersects_pairwise(x, y) contains_sparse(x, y) contains_pairwise(x, y) within_sparse(x, y) within_pairwise(x, y)
intersects_sparse(x, y) intersects_pairwise(x, y) contains_sparse(x, y) contains_pairwise(x, y) within_sparse(x, y) within_pairwise(x, y)
x |
an object of class |
y |
an object of class |
For _sparse
a list of integer vectors containing the position
of the geometry in y
For _pairwise
a logical vector
if (rlang::is_installed("sf")) { nc <- sf::st_read( system.file("shape/nc.shp", package = "sf"), quiet = TRUE ) x <- as_rsgeo(nc$geometry[1:5]) y <- rev(x) # intersects intersects_sparse(x, y) intersects_pairwise(x, y) # contains contains_sparse(x, y) contains_pairwise(x, y) # within within_sparse(x, y) within_pairwise(x, y) }
if (rlang::is_installed("sf")) { nc <- sf::st_read( system.file("shape/nc.shp", package = "sf"), quiet = TRUE ) x <- as_rsgeo(nc$geometry[1:5]) y <- rev(x) # intersects intersects_sparse(x, y) intersects_pairwise(x, y) # contains contains_sparse(x, y) contains_pairwise(x, y) # within within_sparse(x, y) within_pairwise(x, y) }
For a given rs_LINESTRING
vector, test its convexity. Convexity can be tested
strictly or strongly, as well as based on winding.
is_convex(x) is_ccw_convex(x) is_cw_convex(x) is_strictly_convex(x) is_strictly_ccw_convex(x) is_strictly_cw_convex(x)
is_convex(x) is_ccw_convex(x) is_cw_convex(x) is_strictly_convex(x) is_strictly_ccw_convex(x) is_strictly_cw_convex(x)
x |
an object of class |
a logical vector
lns <- geom_linestring( 1:20, runif(20, -5, 5), rep.int(1:5, 4) ) is_convex(lns) is_cw_convex(lns) is_ccw_convex(lns) is_strictly_convex(lns) is_strictly_cw_convex(lns) is_strictly_ccw_convex(lns)
lns <- geom_linestring( 1:20, runif(20, -5, 5), rep.int(1:5, 4) ) is_convex(lns) is_cw_convex(lns) is_ccw_convex(lns) is_strictly_convex(lns) is_strictly_cw_convex(lns) is_strictly_ccw_convex(lns)
For a given LineString or MultiLineString geometry, calculate its length.
Other geometries will return a value of NA
.
length_euclidean(x) length_geodesic(x) length_vincenty(x) length_haversine(x)
length_euclidean(x) length_geodesic(x) length_vincenty(x) length_haversine(x)
x |
an object of class |
Vicenty, Geodesic, and Haversine methods will return in units of meters.
Geodesic length will always converge and is more accurate than the Vicenty methods.
Haversine uses a mean earth radius of 6371.088 km.
See geo
docs for more details.
A numeric vector
set.seed(0) y <- runif(25, -5, 5) x <- 1:25 ln <- geom_linestring(x, y) length_euclidean(ln) length_geodesic(ln) length_vincenty(ln) length_haversine(ln)
set.seed(0) y <- runif(25, -5, 5) x <- 1:25 ln <- geom_linestring(x, y) length_euclidean(ln) length_geodesic(ln) length_vincenty(ln) length_haversine(ln)
Finds the point that lies a given fraction along a line.
line_interpolate_point(x, fraction)
line_interpolate_point(x, fraction)
x |
an object of class |
fraction |
a numeric vector of length 1 or the same length as |
An object of class rs_POINT
x <- geom_linestring(c(-1, 0, 0), c(0, 0, 1)) line_interpolate_point(x, 0.5)
x <- geom_linestring(c(-1, 0, 0), c(0, 0, 1)) line_interpolate_point(x, 0.5)
n
equal length LineStringsGiven a LineString, segment it into n
equal length LineStrings.
The n
LineStrings are provided as a MultiLineString
which can
be expanded using expand_geoms()
and consequently flattened
using flatten_geoms()
if desired.
line_segmentize(x, n) line_segmentize_haversine(x, n)
line_segmentize(x, n) line_segmentize_haversine(x, n)
x |
and object of class |
n |
an integer vector determining the number of equal length LineStrings to create |
line_segmentize()
will segment a LineString using a Euclidean length
calculation. line_segmentize_haversine()
will use a Haversine length
calculation instead. If you have geometries in a geographic cooridnate
system such as EPSG:4326 use the Haversine variant. Otherwise, prefer
the euclidean variant.
A vector of class rs_MULTILINESTRING
x <- geom_linestring(1:10, runif(10, -1, 1)) segs <- line_segmentize(x, 3) flatten_geoms( expand_geoms(segs) )
x <- geom_linestring(1:10, runif(10, -1, 1)) segs <- line_segmentize(x, 3) flatten_geoms( expand_geoms(segs) )
Calculates the fraction of a LineString's length to a point
that is closes to a corresponding point in y
.
locate_point_on_line(x, y)
locate_point_on_line(x, y)
x |
an object of class |
y |
an object of class |
A numeric vector containing the fraction of of the LineString that would need to be traveled to reach the closest point.
x <- geom_linestring(c(-1, 0, 0), c(0, 0, 1)) y <- geom_point(-0.5, 0) locate_point_on_line(x, y)
x <- geom_linestring(c(-1, 0, 0), c(0, 0, 1)) y <- geom_point(-0.5, 0) locate_point_on_line(x, y)
Plot Geometries
## S3 method for class 'rsgeo' plot(x, ...)
## S3 method for class 'rsgeo' plot(x, ...)
x |
an object of class |
... |
arguments passed to |
Plotting geometries utilizes wk::wk_plot()
. The rust geometries are
handled by first converting to an sfc
object in the wk::wk_handle()
method thus requiring both packages for plotting.
Nothing.
if (rlang::is_installed(c("sf", "wk"))) { plot(geom_linestring(1:10, runif(10))) }
if (rlang::is_installed(c("sf", "wk"))) { plot(geom_linestring(1:10, runif(10))) }
Functions to calculate different types of area for polygons.
signed_area(x) unsigned_area(x) signed_area_cd(x) unsigned_area_cd(x) signed_area_geodesic(x) unsigned_area_geodesic(x)
signed_area(x) unsigned_area(x) signed_area_cd(x) unsigned_area_cd(x) signed_area_geodesic(x) unsigned_area_geodesic(x)
x |
an object of class |
functions assume counter clock-wise winding in accordance with the simple feature access standard
functions ending in _cd
use the Chamberlain-Duquette algorithm for spherical area
Chamberlain-Duquette and Geodesic areas are returned in meters squared and assume non-planar geometries
See geo docs for more:
a numeric vector of the area contained by the geometry
x <- c(0, 1, 1, 0, 0) y <- c(0, 0, 1, 1, 0) p <- geom_polygon(x, y) signed_area(p) unsigned_area(p) signed_area_cd(p) unsigned_area_cd(p) signed_area_geodesic(p) unsigned_area_geodesic(p)
x <- c(0, 1, 1, 0, 0) y <- c(0, 0, 1, 1, 0) p <- geom_polygon(x, y) signed_area(p) unsigned_area(p) signed_area_cd(p) unsigned_area_cd(p) signed_area_geodesic(p) unsigned_area_geodesic(p)
Simplifies LineStrings, Polygons, and their Multi- counterparts.
simplify_geoms(x, epsilon) simplify_vw_geoms(x, epsilon) simplify_vw_preserve_geoms(x, epsilon)
simplify_geoms(x, epsilon) simplify_vw_geoms(x, epsilon) simplify_vw_preserve_geoms(x, epsilon)
x |
an object of class of |
epsilon |
a tolerance parameter. Cannot be equal to or less than 0. |
Simplify functions use the Ramer–Douglas–Peucker algorithm. Functions with vw
use
the Visvalingam-Whyatt algorithm.
For more see geo
docs.
an object of class rsgeo
x <- geom_linestring(1:100, runif(100, 5, 10)) simplify_geoms(x, 3) simplify_vw_geoms(x, 2) simplify_vw_preserve_geoms(x, 100)
x <- geom_linestring(1:100, runif(100, 5, 10)) simplify_geoms(x, 3) simplify_vw_geoms(x, 2) simplify_vw_preserve_geoms(x, 100)