Skip to content

Commit

Permalink
Error in st_cast.POINT(X[[i]], ...): cannot create MULTILINESTRING fr…
Browse files Browse the repository at this point in the history
…om POINT fix
  • Loading branch information
MikkoVihtakari committed Nov 8, 2023
1 parent 44628cc commit e7feb0d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 56 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: ggOceanMaps
Type: Package
Title: Plot Data on Oceanographic Maps using 'ggplot2'
Version: 2.1.7
Date: 2023-11-02
Version: 2.1.8
Date: 2023-11-08
Authors@R: c(person("Mikko", "Vihtakari", email = "mikko.vihtakari@hi.no",
role = c("aut", "cre"),
comment = c(affiliation = "Institute of Marine Research",
Expand Down
2 changes: 1 addition & 1 deletion R/basemap.R
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
## Test parameters

# limits = c(160, -160, 60, 80); bathymetry = TRUE
# x = NULL; limits = NULL; data = NULL; shapefiles = NULL; crs = NULL; bathymetry = FALSE; glaciers = FALSE; rotate = FALSE; legends = TRUE; legend.position = "right"; lon.interval = NULL; lat.interval = NULL; bathy.style = NULL; downsample = 0; bathy.border.col = NA; bathy.size = 0.1; bathy.alpha = 1; land.col = "grey60"; land.border.col = "black"; land.size = 0.1; gla.col = "grey95"; gla.border.col = "black"; gla.size = 0.1; grid.col = "grey70"; grid.size = 0.1; base_size = 11; projection.grid = FALSE; verbose = TRUE
# x = NULL; limits = NULL; data = NULL; shapefiles = NULL; crs = NULL; bathymetry = FALSE; glaciers = FALSE; rotate = FALSE; legends = TRUE; legend.position = "right"; lon.interval = NULL; lat.interval = NULL; bathy.style = NULL; downsample = 0; bathy.border.col = NA; bathy.size = 0.1; bathy.alpha = 1; land.col = "grey60"; land.border.col = "black"; land.size = 0.1; gla.col = "grey95"; gla.border.col = "black"; gla.size = 0.1; grid.col = "grey70"; grid.size = 0.1; base_size = 11; projection.grid = FALSE; expand.factor = 1; verbose = TRUE

basemap <- function(x = NULL, limits = NULL, data = NULL, shapefiles = NULL, crs = NULL, bathymetry = FALSE, glaciers = FALSE, rotate = FALSE, legends = TRUE, legend.position = "right", lon.interval = NULL, lat.interval = NULL, bathy.style = NULL, downsample = 0, bathy.border.col = NA, bathy.size = 0.1, bathy.alpha = 1, land.col = "grey60", land.border.col = "black", land.size = 0.1, gla.col = "grey95", gla.border.col = "black", gla.size = 0.1, grid.col = "grey70", grid.size = 0.1, base_size = 11, projection.grid = FALSE, expand.factor = 1, verbose = FALSE) {

Expand Down
75 changes: 23 additions & 52 deletions R/basemap_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -543,9 +543,9 @@ basemap_data_define_shapefiles <- function(limits = NULL, data = NULL, shapefile
sf::st_bbox(
sf::st_buffer(
clip_shape, dist = (expand.factor-1)*sqrt(sf::st_area(clip_shape))
)
)
)
)
}

} else if(case %in% c("limits_proj", "data_proj")) { ## Projected limits/data ####
Expand Down Expand Up @@ -784,61 +784,29 @@ basemap_data_crop <- function(x, bathymetry = FALSE, glaciers = FALSE, crs = NUL

basemap_define_grid_lines <- function(x, lon.interval = NULL, lat.interval = NULL) {

## A quick fix. Improve later

# if(!is.null(x$clipLimits)) {
# if(abs(x$clipLimits$ddLimits[4]) != 90) {
# tmp <- sf::st_bbox(sf::st_transform(x$clipLimits$projBound, 4326))
# x$clipLimits$ddLimits <- tmp[c("xmin", "xmax", "ymin", "ymax")]
# }
# }

## Define intervals if not specified

if(is.null(lat.interval)) {

if(x$polarMap) {
latDist <- 90 - abs(x$decLimits)
} else {
limits <- sf::st_bbox(sf::st_transform(x$limit_shape, 4326))[c("xmin", "xmax", "ymin", "ymax")]

latDist <- abs(diff(round(limits)[3:4]))
lat.interval <-
ifelse(latDist >= 30, 10,
ifelse(latDist >= 15, 5,
ifelse(latDist >= 10, 4,
ifelse(latDist >= 6, 3,
ifelse(latDist > 4, 2, 1)
))))
} else {
lat.breaks <- ggplot2::waiver()
}
lat.interval <-
ifelse(latDist >= 30, 10,
ifelse(latDist >= 15, 5,
ifelse(latDist >= 10, 4,
ifelse(latDist >= 6, 3,
ifelse(latDist > 4, 2, 1)
))))
}

if(is.null(lon.interval)) {

if(x$polarMap) {
lon.interval <- 45
} else {
limits <- sf::st_bbox(sf::st_transform(x$limit_shape, 4326))[c("xmin", "xmax", "ymin", "ymax")]

if(diff(limits[1:2]) == 360) {
lonDist <- 360
} else {
tmp <- dd_to_deg(round(x$decLimits)[1:2])

if(tmp[1] > tmp[2]) {
lonDist <- 360 - tmp[1] + tmp[2]
} else {
lonDist <- tmp[2] - tmp[1]
}
}

lon.interval <-
ifelse(lonDist > 180, 45,
ifelse(lonDist > 90, 30,
ifelse(lonDist >= 40, 10,
ifelse(lonDist > 10, 5,
ifelse(lonDist > 4, 2, 1)
))))
lon.breaks <- ggplot2::waiver()
}
}

Expand Down Expand Up @@ -886,16 +854,19 @@ basemap_define_grid_lines <- function(x, lon.interval = NULL, lat.interval = NUL

} else {

limits <- sf::st_bbox(sf::st_transform(x$limit_shape, 4326))[c("xmin", "xmax", "ymin", "ymax")]

minLat <- min(limits[3:4])
maxLat <- max(limits[3:4])
if(!is.null(lat.interval)) {
limits <- sf::st_bbox(sf::st_transform(x$limit_shape, 4326))[c("xmin", "xmax", "ymin", "ymax")]
minLat <- min(limits[3:4])
minLat <- ifelse(minLat < 0, -90, round_any(minLat, 10, floor))
maxLat <- max(limits[3:4])
maxLat <- ifelse(maxLat > 0, 90, round_any(maxLat, 10, ceiling))
lat.breaks <- seq(minLat, maxLat, lat.interval)
}

minLat <- ifelse(minLat < 0, -90, round_any(minLat, 10, floor))
maxLat <- ifelse(maxLat > 0, 90, round_any(maxLat, 10, ceiling))
if(!is.null(lon.interval)) {
lon.breaks <- unique(c(seq(0, 180, lon.interval), seq(-180, 0, lon.interval)))
}

lat.breaks <- seq(minLat, maxLat, lat.interval)
lon.breaks <- unique(c(seq(0, 180, lon.interval), seq(-180, 0, lon.interval)))
mapGrid <- list(lon.breaks = lon.breaks, lat.breaks = lat.breaks)
}

Expand All @@ -905,4 +876,4 @@ basemap_define_grid_lines <- function(x, lon.interval = NULL, lat.interval = NUL
limit_shape = x$limit_shape, map_limits = x$map_limits,
crs = x$crs, mapGrid = mapGrid)

}
}
2 changes: 1 addition & 1 deletion R/map_cmd.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ map_cmd <- function(command, alternative = FALSE) {
ggplot2::scale_y_continuous(breaks = X$map.grid$lat.breaks, expand = c(0,0.1)) +
ggplot2::scale_x_continuous(breaks = X$map.grid$lon.breaks, expand = c(0,0.1)) +
ggplot2::labs(y = "Latitude (decimal degrees)", x = "Longitude (decimal degrees)") +
ggplot2::coord_sf(xlim = X$map.limits[1:2], ylim = X$map.limits[3:4], expand = FALSE,
ggplot2::coord_sf(xlim = X$map.limits[1:2], ylim = X$map.limits[3:4],
crs = sf::st_crs(X$proj), default = TRUE) +
theme_map(base_size = base_size, grid.col = grid.col, grid.size = grid.size) +
ggplot2::theme(legend.position = legend.position,
Expand Down

0 comments on commit e7feb0d

Please sign in to comment.