Description Sorting Duplicates Comparisons Author(s) Examples
Implements comparison methods for sp classes including ordering and matching.
order(..., na.last=TRUE, decreasing=FALSE, method=c("auto", "shell", "radix"))
returns an integer permutation vector that arranges the first argument of ...
in ascending or descending order,
see ?"base::order"
for more details.
...
should contain one or more SpatialPoints objects of the same dimensionality;
or one or more SpatialPolygons objects.
sort(x, decreasing=FALSE, ...)
returns x
in sorted order, see ?"base::sort"
for more details.
x
may be a SpatialPoints or SpatialPolygons object.
Ordering of points inside a SpatialPoints object is determined by the value of the first dimension; and then the second dimension, if the first is tied; and so on for all available dimensions. Ordering of polygons inside a SpatialPolygons object is determined by the coordinates of the polygon centroid, with comparisons between successive dimensions as described above.
duplicated(x, incomparables=FALSE, ...)
returns a logical vector indicating whether each entry of x
is a duplicate of a previous elemen, see ?"base::duplicated"
for more details.
x
may be a SpatialPoints or SpatialPolygons object.
unique(x, incomparables=FALSE, ...)
returns x
after removing all of the duplicated points, see ?"base::unique"
for more details.
x
may be a SpatialPoints or SpatialPolygons object.
In a SpatialPoints object, a point is considered as duplicate of another point if they have exactly the same coordinates. No consideration is given towards numerical imprecision. In a SpatialPolygons object, polygons are considered to be duplicated if they have the same coordinates and other attributes (e.g., ring direction, whether or not it is a hole).
Boolean operations like x == y
can be performed if both x
and y
are:
two SpatialPoints objects of the same dimensionality.
two SpatialPolygons objects.
This returns a logical vector indicating whether each point in x
is equal to, less than or greater than
(depending on the operator) the corresponding point in y
.
If x
and y
are not of the same length, the shorter object is recycled.
match(x, table, nomatch=NA_integer, incomparables=FALSE, ...)
returns an integer vector of length equal to that of x
.
Each element of this vector specifies an entry in table
that is equal to the corresponding entry in x
.
In SpatialPoints objects, points are compared to each other by considering the vectors of their coordinates. If all coordinates are exactly equal, so are the points; the first unequal coordinate is used to determine which point is “greater than” or “less than” the other. In SpatialPolygons objects, polygons are compared to each other by considering the vectors of their centroid coordinates.
Aaron Lun
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | # For SpatialPoints:
coords <- matrix(runif(30), nrow=10)
X <- sp::SpatialPoints(coords)
order(X)
sort(X)
match(X, X[2:5])
unique(X[c(1,1,1,2,2,3)])
X==X
coords2 <- matrix(runif(15), nrow=5)
Y <- sp::SpatialPoints(coords2)
X < Y
X > Y
# For SpatialPolygons:
spm <- makeSpatialPolygons(
rbind(c(0,0), c(0.5, 0.2), c(0.2, 0.6), c(0.9, 0.8)),
rbind(c(1,1), c(0.3, 0.7), c(0.1, 0.2), c(0.8, 0.3))
)
order(spm)
sort(spm)
match(spm, spm[2:1])
unique(c(spm, spm))
spm==spm
spm2 <- makeSpatialPolygons(
rbind(c(0,0), c(0.4, 0.2), c(0.2, 0.6), c(0.9, 0.8)),
rbind(c(1,1.1), c(0.3, 0.7), c(0.1, 0.2), c(0.8, 0.3))
)
spm < spm2
spm > spm2
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.