Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: 4.1.0
Date: 2024-05-06 23:31:49 UTC
SHA: 8168f4bb1350977e417dda478e6a991d57bfe89d
Version: 4.1.1
Date: 2024-05-28 01:04:04 UTC
SHA: 29503e531bd21aff581f5595526b8d8a5c821734
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Type: Package
Package: CCAMLRGIS
Title: Antarctic Spatial Data Manipulation
Version: 4.1.1
Date: 2024-05-28
Version: 4.2.0
Date: 2024-10-15
Authors@R:
c(person("Stephane","Thanassekos",role = c("aut", "cre"), email = "[email protected]"),
person("Keith", "Reid", role = "aut"),
Expand All @@ -26,10 +26,10 @@ Imports:
graphics,
grDevices,
magrittr,
stars,
isoband,
bezier,
lwgeom
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Suggests:
knitr,
rmarkdown,
Expand Down
11 changes: 9 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export(add_col)
export(add_labels)
export(assign_areas)
export(create_Arrow)
export(create_CircularArrow)
export(create_Ellipse)
export(create_Hashes)
export(create_Lines)
export(create_Pies)
Expand Down Expand Up @@ -55,19 +57,21 @@ importFrom(graphics,plot)
importFrom(graphics,rect)
importFrom(graphics,segments)
importFrom(graphics,text)
importFrom(isoband,iso_to_sfg)
importFrom(isoband,isobands)
importFrom(lwgeom,st_linesubstring)
importFrom(lwgeom,st_transform_proj)
importFrom(magrittr,"%>%")
importFrom(stars,st_as_stars)
importFrom(stars,st_contour)
importFrom(stats,median)
importFrom(stats,quantile)
importFrom(stats,sd)
importFrom(terra,as.matrix)
importFrom(terra,as.polygons)
importFrom(terra,clamp)
importFrom(terra,classify)
importFrom(terra,click)
importFrom(terra,crop)
importFrom(terra,crs)
importFrom(terra,expanse)
importFrom(terra,ext)
importFrom(terra,extend)
Expand All @@ -77,10 +81,13 @@ importFrom(terra,plot)
importFrom(terra,project)
importFrom(terra,rast)
importFrom(terra,vect)
importFrom(terra,xFromCol)
importFrom(terra,yFromRow)
importFrom(utils,download.file)
importFrom(utils,edit)
importFrom(utils,globalVariables)
importFrom(utils,menu)
importFrom(utils,read.csv)
importFrom(utils,setTxtProgressBar)
importFrom(utils,tail)
importFrom(utils,txtProgressBar)
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# CCAMLRGIS 4.2.0

Added create_Ellipse() function,
Added create_CircularArrow() function,
Increased timeout in download within load_Bathy(),
Moved from stars to isoband in get_iso_polys() as the former wouldn't work with large rasters (Thanks to M. D. Sumner),
Updated bathymetry to GEBCO 2024 grid,
Added ellipses in add_Legend(),
Added custom path example in create_Arrow().

# CCAMLRGIS 4.1.1

Optimized create_Arrow() which should now be faster and less prone to errors,
Expand Down
6 changes: 3 additions & 3 deletions R/CCAMLRGIS-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ utils::globalVariables(c('CCAMLRp','Coast','Depth_cols','Depth_cuts','Depth_cols
#' @importFrom grDevices colorRampPalette recordPlot replayPlot chull col2rgb rgb
#' @importFrom graphics abline legend lines par plot rect segments text
#' @importFrom stats median quantile sd
#' @importFrom terra as.polygons clamp classify click crop expanse ext extend extract mask plot project rast vect
#' @importFrom utils download.file edit globalVariables menu read.csv setTxtProgressBar txtProgressBar
#' @importFrom terra as.matrix as.polygons clamp classify click crop crs expanse ext extend extract mask plot project rast vect xFromCol yFromRow
#' @importFrom utils download.file edit globalVariables menu read.csv setTxtProgressBar tail txtProgressBar
#' @importFrom magrittr %>%
#' @importFrom stars st_as_stars st_contour
#' @importFrom isoband isobands iso_to_sfg
#' @importFrom bezier bezier
#' @importFrom lwgeom st_transform_proj st_linesubstring
## usethis namespace: end
Expand Down
4 changes: 2 additions & 2 deletions R/CCAMLRGIS_DataDescription.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' CCAMLRGIS Projection
#'
#' The CCAMLRGIS package uses the Lambert azimuthal equal-area projection (see \url{https://en.wikipedia.org/wiki/Lambert_azimuthal_equal-area_projection}).
#' Source: \url{http://gis.ccamlr.org/}.
#' Source: \url{https://gis.ccamlr.org/}.
#' In order to align with recent developments within Geographic Information Software, this projection
#' will be accessed via EPSG code 6932 (see \url{https://epsg.org/crs_6932/WGS-84-NSIDC-EASE-Grid-2-0-South.html}).
#'
Expand All @@ -16,7 +16,7 @@ NULL
#'
#' Coastline polygons generated from \link{load_Coastline} and sub-sampled to only contain data that falls
#' within the boundaries of the Convention Area. This spatial object may be subsetted to plot the coastline for selected
#' ASDs or EEZs (see examples). Source: \url{http://gis.ccamlr.org/}
#' ASDs or EEZs (see examples). Source: \url{https://gis.ccamlr.org/}
#'
#' @docType data
#' @usage data(Coast)
Expand Down
73 changes: 66 additions & 7 deletions R/add_Legend.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#'
#' \itemize{
#' \item Text: character, text of the item.
#' \item Shape: character, shape description, one of "rectangle", "circle", "line",
#' \item Shape: character, shape description, one of "rectangle", "circle", "ellipse", "line",
#' "arrow" or "none". Using "none" will leave a blank space that can be filled by a user-defined shape.
#' \item ShpFill: character, fill color of shape, set to NA for no fill.
#' \item ShpBord: character, border color of shape, set to NA for no border.
Expand All @@ -70,6 +70,9 @@
#' \item RectW: numeric, width of rectangle shape.
#' \item RectH: numeric, height of rectangle shape.
#' \item CircD: numeric, diameter of circle shape.
#' \item EllW: numeric, width of ellipse shape.
#' \item EllH: numeric, height of ellipse shape.
#' \item EllA: numeric, angle of ellipse shape.
#' \item LineTyp: numeric, type of line shape (0=blank, 1=solid, 2=dashed, 3=dotted, 4=dotdash, 5=longdash, 6=twodash).
#' \item LineL: numeric, length of the line shape.
#' \item ArrL: numeric, length of the arrow shape.
Expand All @@ -91,8 +94,8 @@
#'
#'
#' @seealso
#' \code{\link{create_Hashes}}, \code{\link{create_Arrow}}, \code{\link{add_labels}},
#' \code{\link{add_Cscale}}, \code{\link{add_PieLegend}}.
#' \code{\link{create_Hashes}}, \code{\link{create_Arrow}}, \code{\link{create_Ellipse}},
#' \code{\link{add_labels}}, \code{\link{add_Cscale}}, \code{\link{add_PieLegend}}.
#'
#'
#' @examples
Expand All @@ -107,7 +110,7 @@
#' Subtitle="(Subtitle)",
#' Pos = "bottomright",
#' BoxW= 80,
#' BoxH= 140,
#' BoxH= 170,
#' Boxexp = c(5,-2,-4,-4),
#' Titlefontsize = 2
#' )
Expand Down Expand Up @@ -172,6 +175,37 @@
#' Hashwidth=2
#' )
#'
#' Ellipse1=list(
#' Text="Ellipse 1",
#' Shape="ellipse",
#' ShpFill="white",
#' ShpBord="darkblue",
#' Shplwd=2,
#' fontsize=1.2,
#' STSpace=3,
#' EllW=10,
#' EllH=6,
#' EllA=35
#' )
#'
#' Ellipse2=list(
#' Text="Ellipse 2",
#' Shape="ellipse",
#' ShpFill="red",
#' ShpBord="green",
#' ShpHash=TRUE,
#' Shplwd=2,
#' fontsize=1.2,
#' STSpace=3,
#' EllW=10,
#' EllH=7,
#' EllA=0,
#' Hashcol="black",
#' Hashangle=-45,
#' Hashspacing=1.5,
#' Hashwidth=1.5
#' )
#'
#' Line1=list(
#' Text="Line 1",
#' Shape="line",
Expand Down Expand Up @@ -268,7 +302,8 @@
#'
#' #Combine all items into a single list:
#'
#' Items=list(Rectangle1,Rectangle2,Circle1,Circle2,Line1,Line2,Arrow1,Arrow2,Arrow3,Arrow4,None)
#' Items=list(Rectangle1,Rectangle2,Circle1,Circle2,
#' Ellipse1,Ellipse2,Line1,Line2,Arrow1,Arrow2,Arrow3,Arrow4,None)
#'
#' #manually build a bounding box (same as st_bbox(load_ASDs())):
#'
Expand All @@ -287,7 +322,7 @@ add_Legend=function(bb,LegOpt,Items){

if(inherits(bb,"bbox")==FALSE){stop("bb is not an sf bounding box, use st_bbox() to create bb.")}
dx=as.numeric(bb['xmax']-bb['xmin']) #x scaler
dy=as.numeric(bb['ymax']-bb['ymin']) #x scaler
dy=as.numeric(bb['ymax']-bb['ymin']) #y scaler
d=min(c(round(dx/200),round(dy/200)))

#Set defaults
Expand Down Expand Up @@ -502,7 +537,7 @@ add_Legend=function(bb,LegOpt,Items){
#Loop over items and add them
for(i in seq(1,length(Items))){
item=Items[[i]]
if(!item$Shape%in%c("rectangle","circle","line","arrow","none")){stop(paste0("Argument 'Shape' mis-specified in add_Legend() for item ",i))}
if(!item$Shape%in%c("rectangle","circle","ellipse","line","arrow","none")){stop(paste0("Argument 'Shape' mis-specified in add_Legend() for item ",i))}

#Set defaults
if(is.null(item$ShpFill)){item$ShpFill="white"}
Expand All @@ -520,6 +555,9 @@ add_Legend=function(bb,LegOpt,Items){
if(is.null(item$RectW)){item$RectW=10}
if(is.null(item$RectH)){item$RectH=7}
if(is.null(item$CircD)){item$CircD=10}
if(is.null(item$EllW)){item$EllW=10}
if(is.null(item$EllH)){item$EllH=7}
if(is.null(item$EllA)){item$EllA=0}
if(is.null(item$LineTyp)){item$LineTyp=1}
if(is.null(item$LineL)){item$LineL=10}
if(is.null(item$ArrL)){item$ArrL=10}
Expand Down Expand Up @@ -574,6 +612,27 @@ add_Legend=function(bb,LegOpt,Items){
text(X+item$CircD*d+item$STSpace*d+item$ShiftX*d,Y,item$Text,cex=item$fontsize,adj=c(0,0.5),xpd=TRUE)
}

#Circle
if(item$Shape=="ellipse"){
#Get radius
R=item$EllW*d/2
#Get center
Cx=X+R+item$ShiftX*d
Cy=Y
#build shape
sh=create_Ellipse(Latc=Cy,Lonc=Cx,Lmaj=item$EllW*20,Lmin=item$EllH*20,Ang=item$EllA,yx=TRUE)
#plot shape
plot(st_geometry(sh),add=TRUE,lwd=item$Shplwd,col=item$ShpFill,border=item$ShpBord,xpd=TRUE)
#Hashed?
if(item$ShpHash==TRUE){
Hh=create_Hashes(pol=sh,angle=item$Hashangle,spacing=item$Hashspacing,width=item$Hashwidth)
plot(Hh,add=TRUE,col=item$Hashcol,xpd=TRUE,border=NA)
plot(st_geometry(sh),add=TRUE,lwd=item$Shplwd,border=item$ShpBord,xpd=TRUE)
}
#Add text
text(X+item$EllW*d+item$STSpace*d+item$ShiftX*d,Y,item$Text,cex=item$fontsize,adj=c(0,0.5),xpd=TRUE)
}

#Line
if(item$Shape=="line"){
#Build shape
Expand Down
10 changes: 7 additions & 3 deletions R/create.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,24 @@
#' \code{\link{create_Stations}}, \code{\link{add_RefGrid}}, \code{\link{add_Legend}}.
#'
#' @examples
#' \donttest{
#'
#' # For more examples, see:
#' # https://github.com/ccamlr/CCAMLRGIS#create-polygons
#'
#'
#' #Densified polygons (note the curvature of lines)
#'
#' MyPolys=create_Polys(Input=PolyData)
#' plot(st_geometry(MyPolys),col='red')
#' text(MyPolys$Labx,MyPolys$Laby,MyPolys$ID,col='white')
#'
#' #Convention Area outline
#' CA=data.frame(Name="CA",
#' Lat=c(-50,-50,-45,-45,-55,-55,-60,-60),
#' Lon=c(-50,30,30,80,80,150,150,-50))
#'
#' MyPoly=create_Polys(CA)
#' plot(st_geometry(MyPoly),col='blue',border='green',lwd=2)
#'
#' }
#'
#' @export

Expand Down
29 changes: 26 additions & 3 deletions R/create_Arrow.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#' intermediate rows are the locations of points towards which the arrow's path will bend.
#' Weights (third column) can be added to the intermediate points to make the arrow's path
#' bend more towards them. Projected coordinates may be used (Y then X) instead of Latitudes
#' and Longitudes by setting \code{yx} to \code{TRUE}.
#' and Longitudes by setting \code{yx} to \code{TRUE}. Coordinates may be extracted from a
#' spatial object and used as input (see Example 9 below).
#'
#' @param Np integer, number of additional points generated to create a curved path. If the
#' arrow's path appears too segmented, increase \code{Np}.
Expand Down Expand Up @@ -38,9 +39,10 @@
#' @return Spatial object in your environment with colors included in the dataframe (see examples).
#'
#' @seealso
#' \code{\link{create_CircularArrow}}, \code{\link{create_Ellipse}},\code{\link{add_Legend}},
#' \code{\link{create_Points}}, \code{\link{create_Lines}}, \code{\link{create_Polys}},
#' \code{\link{create_PolyGrids}}, \code{\link{create_Stations}}, \code{\link{create_Pies}},
#' \code{\link{add_Legend}}.
#' \code{\link{create_PolyGrids}}, \code{\link{create_Stations}}, \code{\link{create_Pies}}.
#'
#'
#' @examples
#'
Expand Down Expand Up @@ -104,6 +106,27 @@
#' Atrans = c(0,0.9,0),Atype = "dashed",dlength = 0)
#' plot(st_geometry(Arrow),col=Arrow$col,main="Example 8",border=NA)
#'
#' #Example 9 Path along isobath
#' Iso=st_as_sf(terra::as.contour(SmallBathy(),levels=-1000)) #Take isobath
#' Iso=suppressWarnings(st_cast(Iso,"LINESTRING")) #convert to individual lines
#' Iso$L=st_length(Iso) #Get line length
#' Iso=Iso[Iso$L==max(Iso$L),] #Keep longest line (circumpolar)
#' Iso=st_coordinates(Iso) #Extract coordinates
#' Iso=Iso[Iso[,1]>-2.1e6 & Iso[,1]<(-0.1e6) & Iso[,2]>0,] #crop line
#' Inp=data.frame(Y=Iso[,2],X=Iso[,1])
#' Inp=Inp[seq(nrow(Inp),1),] #Go westward
#' Third=nrow(Inp)/3 #Cut in thirds
#' Arr1=create_Arrow(Input=Inp[1:Third,],yx=TRUE)
#' Arr2=create_Arrow(Input=Inp[(Third+2):(2*Third),],yx=TRUE)
#' Arr3=create_Arrow(Input=Inp[(2*Third+2):nrow(Inp),],yx=TRUE)
#'
#' terra::plot(SmallBathy(),xlim=c(-2.5e6,0.5e6),ylim=c(0.25e6,2.75e6),breaks=Depth_cuts,
#' col=Depth_cols,axes=FALSE,box=FALSE,legend=FALSE,main="Example 9")
#' plot(st_geometry(Arr1),col="darkred",add=TRUE)
#' plot(st_geometry(Arr2),col="darkred",add=TRUE)
#' plot(st_geometry(Arr3),col="darkred",add=TRUE)
#' plot(st_geometry(Coast[Coast$ID=='All',]),col='grey',add=TRUE)
#'
#' @export

create_Arrow=function(Input,Np=50,Pwidth=5,Hlength=15,Hwidth=10,dlength=0,Atype="normal",Acol="green",Atrans=0,yx=FALSE){
Expand Down
Loading
Loading