Skip to content

Commit

Permalink
error in defining COG sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbertocamara committed Aug 7, 2024
1 parent 27f4410 commit e326ccb
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 40 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Authors@R: c(person('Rolf', 'Simoes', role = c('aut'), email = 'rolf.simoes@inpe
person('Gilberto', 'Camara', role = c('aut', 'cre', 'ths'), email = '[email protected]'),
person('Felipe', 'Souza', role = c('aut'), email = '[email protected]'),
person('Felipe', 'Carlos', role = c('aut'), email = "[email protected]"),
person('Lorena', 'Santos', role = c('aut'), email = '[email protected]'),
person('Lorena', 'Santos', role = c('ctb'), email = '[email protected]'),
person('Karine', 'Ferreira', role = c('ctb', 'ths'), email = '[email protected]'),
person('Charlotte', 'Pelletier', role = c('ctb'), email = '[email protected]'),
person('Pedro', 'Andrade', role = c('ctb'), email = '[email protected]'),
Expand Down
5 changes: 1 addition & 4 deletions R/api_colors.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,10 @@
# grDevices does not work with one color missing
}
colors_pal <- grDevices::hcl.colors(
n = max(2, length(missing)),
n = length(missing),
palette = palette,
alpha = 1,
rev = rev
)
# if there is only one color, get it
colors_pal <- colors_pal[seq_len(length(missing))]
names(colors_pal) <- missing
# put all colors together
colors <- c(colors, colors_pal)
Expand Down
23 changes: 8 additions & 15 deletions R/api_plot_raster.R
Original file line number Diff line number Diff line change
Expand Up @@ -304,19 +304,12 @@
palette = palette,
rev = TRUE
)
# prepare labels
labels <- tibble::rownames_to_column(
as.data.frame(labels), var = "label_id"
) |>
dplyr::mutate(label_id = as.numeric(.data[["label_id"]])) |>
dplyr::rename("label" = "labels")
# prepare colors
colors <- tibble::rownames_to_column(
as.data.frame(colors), var = "label"
# prepare colors, labels and ids for plotting
colors_plot <- tibble::tibble(
label_id = names(labels),
label = unname(labels),
color = unname(colors)
)
# merge colors and labels
colors <- dplyr::inner_join(colors, labels, by = "label") |>
dplyr::rename("color" = "colors")
# size of data to be read
sizes <- .tile_overview_size(tile = tile, max_cog_size)
# select the image to be plotted
Expand All @@ -334,12 +327,12 @@
st <- stats::setNames(st, "labels")
st[["labels"]] <- factor(
st[["labels"]],
labels = colors[["label"]],
levels = colors[["label_id"]]
labels = colors_plot[["label"]],
levels = colors_plot[["label_id"]]
)
p <- .tmap_class_map(
st = st,
colors = colors,
colors = colors_plot,
scale = scale,
tmap_params = tmap_params
)
Expand Down
25 changes: 12 additions & 13 deletions R/api_tile.R
Original file line number Diff line number Diff line change
Expand Up @@ -1593,20 +1593,19 @@ NULL
# check if the tile is a COG file
cog_sizes <- .tile_cog_sizes(tile)
if (.has(cog_sizes)) {
small_cog_sizes <- purrr::map(cog_sizes, function(cog_size){
xsize <- cog_size[["xsize"]]
ysize <- cog_size[["ysize"]]
if (xsize <= max_size && ysize <= max_size)
return(cog_size)
else
return(NULL)
})
small_cog_sizes <- purrr::compact(small_cog_sizes)
nrows_cog <- small_cog_sizes[[1]][[1]]
ncols_cog <- small_cog_sizes[[1]][[2]]
# find out the first cog size smaller than max_size
i <- 1
while (i < length(cog_sizes)) {
if (cog_sizes[[i]][["xsize"]] < max_size ||
cog_sizes[[i]][["ysize"]] < max_size)
break;
i <- i + 1
}
# determine the best COG size
best_cog_size <- cog_sizes[[i]]
return(c(
xsize = nrows_cog,
ysize = ncols_cog)
xsize = best_cog_size[["xsize"]],
ysize = best_cog_size[["ysize"]])
)
} else {
# get the maximum number of bytes for the tiles
Expand Down
12 changes: 6 additions & 6 deletions inst/extdata/tmap/api_tmap_v4.R
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@
col.legend = tmap::tm_legend(
show = TRUE,
frame = TRUE,
title = "val",
position = tmap::tm_pos_in("left", "bottom"),
title = label_plot,
title.size = tmap_params[["legend_title_size"]],
text.size = tmap_params[["legend_text_size"]],
bg.color = tmap_params[["legend_bg_color"]],
Expand Down Expand Up @@ -456,7 +456,7 @@
}
#' @export
.tmap_vector_probs.tmap_v4 <- function(sf_seg, palette, rev,
labels, label_plot,
labels, labels_plot,
scale, tmap_params){

cols4all_name <- cols4all::c4a_info(palette)$fullname
Expand All @@ -466,20 +466,20 @@
# plot the segments
p <- tmap::tm_shape(sf_seg) +
tmap::tm_polygons(
fill = label_plot,
fill = labels_plot,
fill.scale = tmap::tm_scale_continuous(
values = cols4all_name,
midpoint = NA),
fill.legend = tmap::tm_legend(
frame = TRUE,
position = tmap::tm_pos_in("left", "bottom"),
title = label_plot,
title.size = tmap_params[["legend_title_size"]],
text.size = tmap_params[["legend_text_size"]],
bg.color = tmap_params[["legend_bg_color"]],
bg.alpha = tmap_params[["legend_bg_alpha"]]
)
) +
tmap::tm_facets() +
tmap::tm_graticules(
labels.size = tmap_params[["graticules_labels_size"]]
) +
Expand Down Expand Up @@ -544,7 +544,7 @@
labels = colors[["label"]]
),
col.legend = tmap::tm_legend(
position = tmap::tm_pos_in("left", "bottom"),
position = tmap::tm_pos_out(),
frame = TRUE,
text.size = tmap_params[["legend_text_size"]],
bg.color = tmap_params[["legend_bg_color"]],
Expand Down Expand Up @@ -629,7 +629,7 @@
title = "class",
title.size = tmap_params[["legend_title_size"]],
text.size = tmap_params[["legend_text_size"]],
position = tmap::tm_pos_in("left", "bottom"),
position = tmap::tm_pos_out(),
bg.color = tmap_params[["legend_bg_color"]],
bg.alpha = tmap_params[["legend_bg_alpha"]]
)
Expand Down
2 changes: 1 addition & 1 deletion man/sits-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e326ccb

Please sign in to comment.