s2/ 0000755 0001750 0001751 00000000000 15014114452 010726 5 ustar nilesh nilesh s2/man/ 0000755 0001750 0001751 00000000000 14737212474 011517 5 ustar nilesh nilesh s2/man/s2_cell.Rd 0000644 0001750 0001751 00000004523 14737212474 013335 0 ustar nilesh nilesh % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/s2-cell.R
\name{s2_cell}
\alias{s2_cell}
\alias{s2_cell_sentinel}
\alias{s2_cell_invalid}
\alias{as_s2_cell}
\alias{as_s2_cell.s2_cell}
\alias{as_s2_cell.character}
\alias{as_s2_cell.s2_geography}
\alias{as_s2_cell.wk_xy}
\alias{as_s2_cell.integer64}
\alias{new_s2_cell}
\title{Create S2 Cell vectors}
\usage{
s2_cell(x = character())
s2_cell_sentinel()
s2_cell_invalid()
as_s2_cell(x, ...)
\method{as_s2_cell}{s2_cell}(x, ...)
\method{as_s2_cell}{character}(x, ...)
\method{as_s2_cell}{s2_geography}(x, ...)
\method{as_s2_cell}{wk_xy}(x, ...)
\method{as_s2_cell}{integer64}(x, ...)
new_s2_cell(x)
}
\arguments{
\item{x}{The canonical S2 cell identifier as a character vector.}
\item{...}{Passed to methods}
}
\value{
An object of class s2_cell
}
\description{
The S2 cell indexing system forms the basis for spatial indexing
in the S2 library. On their own, S2 cells can represent points
or areas. As a union, a vector of S2 cells can approximate a
line or polygon. These functions allow direct access to the
S2 cell indexing system and are designed to have minimal overhead
such that looping and recursion have acceptable performance
when used within R code.
}
\details{
Under the hood, S2 cell vectors are represented in R as vectors
of type \code{\link[=double]{double()}}. This works because S2 cell identifiers are
64 bits wide, as are \code{double}s on all systems where R runs (The
same trick is used by the bit64 package to represent signed
64-bit integers). As a happy accident, \code{NA_real_} is not a valid
or meaningful cell identifier, so missing value support in the
way R users might expect is preserved. It is worth noting that
the underlying value of \code{s2_cell_sentinel()} would normally be
considered \code{NA}; however, as it is meaningful and useful when
programming with S2 cells, custom \code{is.na()} and comparison methods
are implemented such that \code{s2_cell_sentinel()} is greater than
all valid S2 cells and not considered missing. Users can and should
implement compiled code that uses the underlying bytes of the
vector, ensuring that the class of any returned object that should
be interpreted in this way is constructed with \code{new_s2_cell()}.
}
\examples{
s2_cell("4b59a0cd83b5de49")
as_s2_cell(s2_lnglat(-64, 45))
as_s2_cell(s2_data_cities("Ottawa"))
}
s2/man/s2_closest_feature.Rd 0000644 0001750 0001751 00000010671 14737212474 015606 0 ustar nilesh nilesh % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/s2-matrix.R
\name{s2_closest_feature}
\alias{s2_closest_feature}
\alias{s2_closest_edges}
\alias{s2_farthest_feature}
\alias{s2_distance_matrix}
\alias{s2_max_distance_matrix}
\alias{s2_contains_matrix}
\alias{s2_within_matrix}
\alias{s2_covers_matrix}
\alias{s2_covered_by_matrix}
\alias{s2_intersects_matrix}
\alias{s2_disjoint_matrix}
\alias{s2_equals_matrix}
\alias{s2_touches_matrix}
\alias{s2_dwithin_matrix}
\alias{s2_may_intersect_matrix}
\title{Matrix Functions}
\usage{
s2_closest_feature(x, y)
s2_closest_edges(
x,
y,
k,
min_distance = -1,
max_distance = Inf,
radius = s2_earth_radius_meters()
)
s2_farthest_feature(x, y)
s2_distance_matrix(x, y, radius = s2_earth_radius_meters())
s2_max_distance_matrix(x, y, radius = s2_earth_radius_meters())
s2_contains_matrix(x, y, options = s2_options(model = "open"))
s2_within_matrix(x, y, options = s2_options(model = "open"))
s2_covers_matrix(x, y, options = s2_options(model = "closed"))
s2_covered_by_matrix(x, y, options = s2_options(model = "closed"))
s2_intersects_matrix(x, y, options = s2_options())
s2_disjoint_matrix(x, y, options = s2_options())
s2_equals_matrix(x, y, options = s2_options())
s2_touches_matrix(x, y, options = s2_options())
s2_dwithin_matrix(x, y, distance, radius = s2_earth_radius_meters())
s2_may_intersect_matrix(x, y, max_edges_per_cell = 50, max_feature_cells = 4)
}
\arguments{
\item{x, y}{Geography vectors, coerced using \code{\link[=as_s2_geography]{as_s2_geography()}}.
\code{x} is considered the source, where as \code{y} is considered the target.}
\item{k}{The number of closest edges to consider when searching. Note
that in S2 a point is also considered an edge.}
\item{min_distance}{The minimum distance to consider when searching for
edges. This filter is applied after the search is complete (i.e.,
may cause fewer than \code{k} values to be returned).}
\item{max_distance}{The maximum distance to consider when searching for
edges. This filter is applied before the search.}
\item{radius}{Radius of the earth. Defaults to the average radius of
the earth in meters as defined by \code{\link[=s2_earth_radius_meters]{s2_earth_radius_meters()}}.}
\item{options}{An \code{\link[=s2_options]{s2_options()}} object describing the polygon/polyline
model to use and the snap level.}
\item{distance}{A distance on the surface of the earth in the same units
as \code{radius}.}
\item{max_edges_per_cell}{For \code{\link[=s2_may_intersect_matrix]{s2_may_intersect_matrix()}},
this values controls the nature of the index on \code{y}, with higher values
leading to coarser index. Values should be between 10 and 50; the default
of 50 is adequate for most use cases, but for specialized operations users
may wish to use a lower value to increase performance.}
\item{max_feature_cells}{For \code{\link[=s2_may_intersect_matrix]{s2_may_intersect_matrix()}}, this value
controls the approximation of \code{x} used to identify potential intersections
on \code{y}. The default value of 4 gives the best performance for most operations,
but for specialized operations users may wish to use a higher value to increase
performance.}
}
\value{
A vector of length \code{x}.
}
\description{
These functions are similar to accessors and predicates, but instead of
recycling \code{x} and \code{y} to a common length and returning a vector of that
length, these functions return a vector of length \code{x} with each element
\code{i} containing information about how the entire vector \code{y} relates to
the feature at \code{x[i]}.
}
\examples{
city_names <- c("Vatican City", "San Marino", "Luxembourg")
cities <- s2_data_cities(city_names)
country_names <- s2_data_tbl_countries$name
countries <- s2_data_countries()
# closest feature returns y indices of the closest feature
# for each feature in x
country_names[s2_closest_feature(cities, countries)]
# farthest feature returns y indices of the farthest feature
# for each feature in x
country_names[s2_farthest_feature(cities, countries)]
# use s2_closest_edges() to find the k-nearest neighbours
nearest <- s2_closest_edges(cities, cities, k = 2, min_distance = 0)
city_names
city_names[unlist(nearest)]
# predicate matrices
country_names[s2_intersects_matrix(cities, countries)[[1]]]
# distance matrices
s2_distance_matrix(cities, cities)
s2_max_distance_matrix(cities, countries[1:4])
}
\seealso{
See pairwise predicate functions (e.g., \code{\link[=s2_intersects]{s2_intersects()}}).
}
s2/man/s2_cell_union_normalize.Rd 0000644 0001750 0001751 00000003020 14737212474 016614 0 ustar nilesh nilesh % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/s2-cell-union.R
\name{s2_cell_union_normalize}
\alias{s2_cell_union_normalize}
\alias{s2_cell_union_contains}
\alias{s2_cell_union_intersects}
\alias{s2_cell_union_intersection}
\alias{s2_cell_union_union}
\alias{s2_cell_union_difference}
\alias{s2_covering_cell_ids}
\alias{s2_covering_cell_ids_agg}
\title{S2 cell union operators}
\usage{
s2_cell_union_normalize(x)
s2_cell_union_contains(x, y)
s2_cell_union_intersects(x, y)
s2_cell_union_intersection(x, y)
s2_cell_union_union(x, y)
s2_cell_union_difference(x, y)
s2_covering_cell_ids(
x,
min_level = 0,
max_level = 30,
max_cells = 8,
buffer = 0,
interior = FALSE,
radius = s2_earth_radius_meters()
)
s2_covering_cell_ids_agg(
x,
min_level = 0,
max_level = 30,
max_cells = 8,
buffer = 0,
interior = FALSE,
radius = s2_earth_radius_meters(),
na.rm = FALSE
)
}
\arguments{
\item{x, y}{An \link[=as_s2_geography]{s2_geography} or \code{\link[=s2_cell_union]{s2_cell_union()}}.}
\item{min_level, max_level}{The minimum and maximum levels to constrain the
covering.}
\item{max_cells}{The maximum number of cells in the covering. Defaults to
8.}
\item{buffer}{A distance to buffer outside the geography}
\item{interior}{Use \code{TRUE} to force the covering inside the geography.}
\item{radius}{The radius to use (e.g., \code{\link[=s2_earth_radius_meters]{s2_earth_radius_meters()}})}
\item{na.rm}{Remove NAs prior to computing aggregate?}
}
\description{
S2 cell union operators
}
s2/man/s2_geog_point.Rd 0000644 0001750 0001751 00000011764 14737212474 014555 0 ustar nilesh nilesh % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/s2-constructors-formatters.R
\name{s2_geog_point}
\alias{s2_geog_point}
\alias{s2_make_line}
\alias{s2_make_polygon}
\alias{s2_geog_from_text}
\alias{s2_geog_from_wkb}
\alias{s2_as_text}
\alias{s2_as_binary}
\alias{s2_tessellate_tol_default}
\title{Create and Format Geography Vectors}
\usage{
s2_geog_point(longitude, latitude)
s2_make_line(longitude, latitude, feature_id = 1L)
s2_make_polygon(
longitude,
latitude,
feature_id = 1L,
ring_id = 1L,
oriented = FALSE,
check = TRUE
)
s2_geog_from_text(
wkt_string,
oriented = FALSE,
check = TRUE,
planar = FALSE,
tessellate_tol_m = s2_tessellate_tol_default()
)
s2_geog_from_wkb(
wkb_bytes,
oriented = FALSE,
check = TRUE,
planar = FALSE,
tessellate_tol_m = s2_tessellate_tol_default()
)
s2_as_text(
x,
precision = 16,
trim = TRUE,
planar = FALSE,
tessellate_tol_m = s2_tessellate_tol_default()
)
s2_as_binary(
x,
endian = wk::wk_platform_endian(),
planar = FALSE,
tessellate_tol_m = s2_tessellate_tol_default()
)
s2_tessellate_tol_default()
}
\arguments{
\item{longitude, latitude}{Vectors of latitude and longitude}
\item{feature_id, ring_id}{Vectors for which a change in
sequential values indicates a new feature or ring. Use \code{\link[=factor]{factor()}}
to convert from a character vector.}
\item{oriented}{TRUE if polygon ring directions are known to be correct
(i.e., exterior rings are defined counter clockwise and interior
rings are defined clockwise).}
\item{check}{Use \code{check = FALSE} to skip error on invalid geometries}
\item{wkt_string}{Well-known text}
\item{planar}{Use \code{TRUE} to force planar edges in import or export.}
\item{tessellate_tol_m}{The maximum number of meters to that a point must
be moved to satisfy the planar edge constraint.}
\item{wkb_bytes}{A \code{list()} of \code{raw()}}
\item{x}{An object that can be converted to an s2_geography vector}
\item{precision}{The number of significant digits to export when
writing well-known text. If \code{trim = FALSE}, the number of
digits after the decimal place.}
\item{trim}{Should trailing zeroes be included after the decimal place?}
\item{endian}{The endian-ness of the well-known binary. See \code{\link[wk:deprecated]{wk::wkb_translate_wkb()}}.}
}
\description{
These functions create and export \link[=as_s2_geography]{geography vectors}.
Unlike the BigQuery geography constructors, these functions do not sanitize
invalid or redundant input using \code{\link[=s2_union]{s2_union()}}. Note that when creating polygons
using \code{\link[=s2_make_polygon]{s2_make_polygon()}}, rings can be open or closed.
}
\examples{
# create point geographies using coordinate values:
s2_geog_point(-64, 45)
# create line geographies using coordinate values:
s2_make_line(c(-64, 8), c(45, 71))
# optionally, separate features using feature_id:
s2_make_line(
c(-64, 8, -27, -27), c(45, 71, 0, 45),
feature_id = c(1, 1, 2, 2)
)
# create polygon geographies using coordinate values:
# (rings can be open or closed)
s2_make_polygon(c(-45, 8, 0), c(64, 71, 90))
# optionally, separate rings and/or features using
# ring_id and/or feature_id
s2_make_polygon(
c(20, 10, 10, 30, 45, 30, 20, 20, 40, 20, 45),
c(35, 30, 10, 5, 20, 20, 15, 25, 40, 45, 30),
feature_id = c(rep(1, 8), rep(2, 3)),
ring_id = c(1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1)
)
# import and export well-known text
(geog <- s2_geog_from_text("POINT (-64 45)"))
s2_as_text(geog)
# import and export well-known binary
(geog <- s2_geog_from_wkb(wk::as_wkb("POINT (-64 45)")))
s2_as_binary(geog)
# import geometry from planar space
s2_geog_from_text(
"POLYGON ((0 0, 1 0, 0 1, 0 0))",
planar = TRUE,
tessellate_tol_m = 1
)
# export geographies into planar space
geog <- s2_make_polygon(c(179, -179, 179), c(10, 10, 11))
s2_as_text(geog, planar = TRUE)
# polygons containing a pole need an extra step
geog <- s2_data_countries("Antarctica")
geom <- s2_as_text(
s2_intersection(geog, s2_world_plate_carree()),
planar = TRUE
)
}
\seealso{
See \code{\link[=as_s2_geography]{as_s2_geography()}} for other ways to construct geography vectors.
BigQuery's geography function reference:
\itemize{
\item \href{https://cloud.google.com/bigquery/docs/reference/standard-sql/geography_functions#st_geogpoint}{ST_GEOGPOINT}
\item \href{https://cloud.google.com/bigquery/docs/reference/standard-sql/geography_functions#st_makeline}{ST_MAKELINE}
\item \href{https://cloud.google.com/bigquery/docs/reference/standard-sql/geography_functions#st_makepolygon}{ST_MAKEPOLYGON}
\item \href{https://cloud.google.com/bigquery/docs/reference/standard-sql/geography_functions#st_geogfromtext}{ST_GEOGFROMTEXT}
\item \href{https://cloud.google.com/bigquery/docs/reference/standard-sql/geography_functions#st_geogfromwkb}{ST_GEOGFROMWKB}
\item \href{https://cloud.google.com/bigquery/docs/reference/standard-sql/geography_functions#st_astext}{ST_ASTEXT}
\item \href{https://cloud.google.com/bigquery/docs/reference/standard-sql/geography_functions#st_asbinary}{ST_ASBINARY}
}
}
s2/man/figures/ 0000755 0001750 0001751 00000000000 14737212474 013163 5 ustar nilesh nilesh s2/man/figures/rc300.png 0000644 0001750 0001751 00000036526 14737212474 014534 0 ustar nilesh nilesh PNG
IHDR , D ; sRGB pHYs .# .#x?v iTXtXML:com.adobe.xmp
Adobe ImageReady
1
).= ;$IDATx E;k&d!B!NC yB5O}$, "Ld\6$3dL2۽]wzٲ`fvuթSN:}jm{YΊى.~_ys\'Z Usy9PoߐARVg,}[R7Y*eEiJV 3^g0Z1Oʯ~U.rȁ{W'뻮^$-u+XR9N1!m;n3o9ZJ͑r8Nj`0W/rȁ{/3RV˗?XNܗŃBAǯ 2]JR\+pQ٣P:&>.㤙;*hmsEW ʺ|ٳnx7]3uܭt~Z;}A{Mdd
2Wrҝ'79Ac5E#(0S0ʾ6R9sPV9PAā=
Z]%}æ' G8E7T^x/rȁ4hT
)X}Rẫ\,{5u]Y^@JTۇ1Qȁ"0e~O
ee碵e9Q9pppU"`MIΗX?p/dMwYel4>Hn2P!]o9|WZ_J)A"j%sǾԭ"eU=c[|7WZUI
| jdRvTpX\u^MpêFhok)Nζm/|^pSڰ+rݶfVqY8Ӟ4
e#m&Na?:jTYZ{12ܯTU-Ͱ'irWE-˙Z__ߐ6*wpr*Dmm6F2ӦM+4iұGuFŅS7kh'u,:.F.e^MFte:ڻ&X:p7
vT%FTRC@AWeQSWW%\h]imIx vرUr؇Iill֑dNᅜZ%@sPsTC/suJz֕R
RSc OL
+,VЀ)@!fNxXu5'IKX:-uE52EyEئNKp]tE K}ܸqDbd*;!^ٰaßB+,[SS3J1?%.8Nu`%
KkeK$;#*˱>%A(/c,6?cٿb;TWѧe4jn[ngZ?GR).sMR::v"(WTTctAk]{Ɓ:MA|