Skip to content

Commit 78028e5

Browse files
committed
add bottom/top/left/right fields to graticule; #828
1 parent 40ea4d2 commit 78028e5

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

R/graticule.R

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#' (E: meridian, N: parallel) degree value, label, start and end coordinates and angle;
2929
#' see example. The \code{plot12} is a logical attribute that is \code{TRUE}
3030
#' for meridians crossing the bottom or parallels crossing the left side of the plot.
31+
#' The four attributes \code{bottom}, \code{top}, \code{left}, \code{right} indicate
32+
#' whether graticules touch that side at its begin, end, with both sides, or not at all (none).
3133
#' @examples
3234
#' library(sf)
3335
#' library(maps)
@@ -191,12 +193,31 @@ graticule_attributes = function(df) {
191193
function(x) { y = x[[length(x)]]; n = nrow(y); apply(y[(n-1):n,], 2, diff) } ))
192194
df$angle_end = apply(dxdy, 1, function(x) atan2(x[2], x[1])*180/pi)
193195
bb = st_bbox(df)
194-
selE = df$type == "E" & df$y_start < min(df$y_start) + 0.001 * (bb[3] - bb[1])
195-
selN = df$type == "N" & df$x_start < min(df$x_start) + 0.001 * (bb[4] - bb[2])
196+
197+
selE = df$type == "E" & df$y_start < min(df$y_start) + 0.001 * (bb[4] - bb[2])
198+
selN = df$type == "N" & df$x_start < min(df$x_start) + 0.001 * (bb[3] - bb[1])
196199
df$plot12 = selE | selN
200+
201+
begin_end_both_none = function(begin, end)
202+
ifelse(begin & end, "both", ifelse(begin, "begin", ifelse(end, "end", "none")))
203+
204+
df$bottom = begin_end_both_none(
205+
df$y_start < min(df$y_start) + 0.001 * (bb[4] - bb[2]),
206+
df$y_end < min(df$y_start) + 0.001 * (bb[4] - bb[2]))
207+
df$top = begin_end_both_none(
208+
df$y_start > max(df$y_start) - 0.001 * (bb[4] - bb[2]),
209+
df$y_end > max(df$y_start) - 0.001 * (bb[4] - bb[2]))
210+
df$left = begin_end_both_none(
211+
df$x_start < min(df$x_start) + 0.001 * (bb[3] - bb[1]),
212+
df$x_end < min(df$x_start) + 0.001 * (bb[3] - bb[1]))
213+
df$right = begin_end_both_none(
214+
df$x_start > max(df$x_start) - 0.001 * (bb[3] - bb[1]),
215+
df$x_end > max(df$x_start) - 0.001 * (bb[3] - bb[1]))
216+
197217
df
198218
}
199219

220+
200221
trim_bb = function(bb = c(-180, -90, 180, 90), margin, wrap = c(-180, 180)) {
201222
stopifnot(margin > 0 && margin <= 1.0)
202223
fr = 1.0 - margin

man/st_graticule.Rd

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)