diff --git a/DESCRIPTION b/DESCRIPTION index d8f7eea..d84939e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,6 @@ Package: asam -Title: Access, Download, Update, Process and Visualize Anti-shipping Activity - Messages ('ASAM') Database Files -Version: 0.1.0 +Title: Read and work with Anti-shipping Activity Messages (ASAM) database files +Version: 0.2.0 Authors@R: c( person("Bob", "Rudis", email = "bob@rud.is", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-5670-2640")) @@ -10,9 +9,9 @@ Maintainer: Bob Rudis Description: Anti-shipping Activity Messages ('ASAM') include the locations and descriptive accounts of specific hostile acts against ships and mariners. The reports may be useful for recognition, prevention and avoidance of - potential hostile activity. A snapshot of the official 'ASAM' database is - included along with utilities to update the local database and the - official polygons defining the 'ASAM' global regions and subregions. + potential hostile activity. Tools are provided to download the official 'ASAM' + database along with a geojson version of the official polygons defining the + 'ASAM' global regions and subregions. Data is from URL: http://gitlab.com/hrbrmstr/asam BugReports: https://gitlab.com/hrbrmstr/asam/issues Depends: R (>= 3.2.0) @@ -21,7 +20,9 @@ Suggests: testthat Imports: sf, - rgdal, - utils + utils, + httr, + XML, + memoise Encoding: UTF-8 -RoxygenNote: 6.0.1.9000 +RoxygenNote: 6.1.1 diff --git a/NAMESPACE b/NAMESPACE index b0d80ab..d6c035f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,8 +1,12 @@ # Generated by roxygen2: do not edit by hand -export(asam_refresh) export(asam_subregions) -import(rgdal) +export(read_asam) import(sf) +importFrom(XML,xmlParse) +importFrom(XML,xmlToDataFrame) +importFrom(httr,GET) +importFrom(httr,content) +importFrom(memoise,memoise) importFrom(utils,download.file) importFrom(utils,unzip) diff --git a/R/asam-package.r b/R/asam-package.r index 4df923d..c057096 100644 --- a/R/asam-package.r +++ b/R/asam-package.r @@ -1,20 +1,19 @@ -#' Access, download, update and work with Anti-shipping Activity Messages (ASAM) -#' database files +#' Read and work with Anti-shipping Activity Messages (ASAM) database files #' #' Anti-shipping Activity Messages ('ASAM') include the locations and #' descriptive accounts of specific hostile acts against ships and mariners. #' The reports may be useful for recognition, prevention and avoidance of -#' potential hostile activity. A snapshot of the official 'ASAM' database is -#' included along with utilities to update the local database and the -#' official polygons defining the 'ASAM' global regions and subregions. -#' -#' - URL: -#' - BugReports: +#' potential hostile activity. Tools are provided to download the official 'ASAM' +#' database along with a geojson version of the official polygons defining the +#' 'ASAM' global regions and subregions. Data is from #' #' @md #' @name asam #' @docType package #' @author Bob Rudis (bob@@rud.is) -#' @import sf rgdal +#' @import sf +#' @importFrom memoise memoise +#' @importFrom httr GET content +#' @importFrom XML xmlParse xmlToDataFrame #' @importFrom utils download.file unzip -NULL +"_PACKAGE" diff --git a/R/asam.r b/R/asam.r deleted file mode 100644 index e69de29..0000000 diff --git a/R/data.r b/R/data.r deleted file mode 100644 index 388093b..0000000 --- a/R/data.r +++ /dev/null @@ -1,68 +0,0 @@ -#' @title ASAM (Anti-shipping Activity Messages) Data (shapefile) -#' @description This dataset contains data from the National Geospatial -#' Intelligence Acency's Anti-shipping Activity Messages (ASAM) -#' database. This include the locations and descriptive accounts -#' of specific hostile acts against ships and mariners. The reports -#' may be useful for recognition, prevention and avoidance of -#' potential hostile activity. -#' -#' \itemize{ -#' \item \code{Reference}: ASAM Reference Number -#' \item \code{DateOfOcc}: Date of incident occurrence (a \code{Date} object) -#' \item \code{SubReg}: Geographical Subregion. See -#' \url{http://fas.org/irp/world/para/docs/geol_geo.htm} for a map of -#' the boundaries for these locations or the \code{\link{asam_subregions}} -#' function in this package. -#' \item \code{Aggressor}: Who was the aggressor -#' \item \code{Descript}: Description of the anti-shipping activity -#' \item \code{Desc1}: Description of the anti-shipping activity -#' \item \code{Desc2}: Description of the anti-shipping activity -#' \item \code{Desc3}: Description of the anti-shipping activity -#' \item \code{Desc4}: Description of the anti-shipping activity -#' \item \code{Desc5}: Description of the anti-shipping activity -#' \item \code{Desc6}: Description of the anti-shipping activity -#' } -#' @docType data -#' @keywords datasets -#' @name asam_shp -#' @seealso \code{\link{asam_refresh}} for updating the dataset, -#' @references \href{http://msi.nga.mil/NGAPortal/MSI.portal?_nfpb=true&_pageLabel=msi_portal_page_65}{ASAM home} -#' @usage data(asam_shp) -#' @note Last updated 2018-09-23 -#' @format A \code{SpatialPointsDataFrame} with 12 variables and 8,003 observations -NULL - - -#' @title ASAM (Anti-shipping Activity Messages) Data (simple features) -#' @description This dataset contains data from the National Geospatial -#' Intelligence Acency's Anti-shipping Activity Messages (ASAM) -#' database. This include the locations and descriptive accounts -#' of specific hostile acts against ships and mariners. The reports -#' may be useful for recognition, prevention and avoidance of -#' potential hostile activity. -#' -#' \itemize{ -#' \item \code{Reference}: ASAM Reference Number -#' \item \code{DateOfOcc}: Date of incident occurrence (a \code{Date} object) -#' \item \code{SubReg}: Geographical Subregion. See -#' \url{http://fas.org/irp/world/para/docs/geol_geo.htm} for a map of -#' the boundaries for these locations or the \code{\link{asam_subregions}} -#' function in this package. -#' \item \code{Aggressor}: Who was the aggressor -#' \item \code{Descript}: Description of the anti-shipping activity -#' \item \code{Desc1}: Description of the anti-shipping activity -#' \item \code{Desc2}: Description of the anti-shipping activity -#' \item \code{Desc3}: Description of the anti-shipping activity -#' \item \code{Desc4}: Description of the anti-shipping activity -#' \item \code{Desc5}: Description of the anti-shipping activity -#' \item \code{Desc6}: Description of the anti-shipping activity -#' } -#' @docType data -#' @keywords datasets -#' @name asam_sf -#' @seealso \code{\link{asam_refresh}} for updating the dataset, -#' @references \href{http://msi.nga.mil/NGAPortal/MSI.portal?_nfpb=true&_pageLabel=msi_portal_page_65}{ASAM home} -#' @usage data(asam_sf) -#' @note Last updated 2018-09-23 -#' @format A simple feature collection with 8,003 features and 12 fields -NULL diff --git a/R/geo.r b/R/geo.r index 03aa1c9..e242e75 100644 --- a/R/geo.r +++ b/R/geo.r @@ -1,3 +1,7 @@ +.asam_subregions <- function() { + sf::st_read(system.file("geojson/asam.geojson", package="asam"), quiet = TRUE) +} + #' Retrieve ASAM subregions polygons #' #' Returns the official ASAM Subregions polygons as a \code{SpatialPolygonsDataFrame} @@ -16,22 +20,8 @@ #' chart numbers refer to the geographic subregion. #' #' @md -#' @param sp if `TRUE` then return a `Spatial` object otherwise return a simple feature collection -#' @return \code{SpatialPolygonsDataFrame} #' @export #' @examples \dontrun{ #' plot(asam_subregions()) -# -#' plot(asam_subregions(FALSE)) #' } -asam_subregions <- function(sp = TRUE) { - - if (sp) { - rgdal::readOGR(system.file("geojson/asam.geojson", package="asam"), - "OGRGeoJSON", stringsAsFactors=FALSE, verbose=FALSE) - } else { - sf::st_read(system.file("geojson/asam.geojson", package="asam")) - } - -} - +asam_subregions <- memoise::memoise(.asam_subregions) diff --git a/R/read.r b/R/read.r new file mode 100644 index 0000000..d656204 --- /dev/null +++ b/R/read.r @@ -0,0 +1,29 @@ +.read_asam <- function(quiet = FALSE) { + + if (!quiet) message("Reading ASAM database (this may take a while)") + res <- httr::GET("https://msi.nga.mil/api/publications/asam?filter=none&sort=date&output=xml") + httr::stop_for_status(res) + out <- readBin(httr::content(res, as = "raw", encoding = "UTF-8"), "character") + out <- gsub("[^\u0009\u000a\u000d\u0020-\uD7FF\uE000-\uFFFD]", "", out) + out <- XML::xmlParse(out) + out <- XML::xmlToDataFrame(out, stringsAsFactors=FALSE) + out[["date"]] <- as.Date(out[["date"]]) + out[["latitude"]] <- as.numeric(out[["latitude"]]) + out[["longitude"]] <- as.numeric(out[["longitude"]]) + class(out) <- c("tbl_df", "tbl", "data.frame") + out + +} + +#' @title Read ASAM database +#' +#' The ASAM database is updated daily by the National Geospatial-Intelligence +#' Agency (NGIA) and this function provides a simple means to download it. +#' +#' @param quiet if `TRUE` no messages +#' @export +#' @rdname read_asam +#' @examples \dontrun{ +#' read_asam() +#' } +read_asam <- memoise::memoise(.read_asam) diff --git a/R/refresh.r b/R/refresh.r deleted file mode 100644 index cbab43e..0000000 --- a/R/refresh.r +++ /dev/null @@ -1,49 +0,0 @@ -#' @title Refresh ASAM database -#' -#' The \code{asam} pacakge comes with a snapshot of the official ASAM -#' database. This database is updated daily by the National Geospatial-Intelligence -#' Agency (NGIA) and this function provides a simple means to refresh it. -#' -#' @description \code{asam_refresh} will fetch the latest (the files are udated daily) -#' ASAM shapefile database and overwrite the one installed with the package -#' (or previously updated). -#' @return (invisible) \code{TRUE} or \code{FALSE} depending on the success of -#' the retrieval. -#' @export -#' @rdname asam_refresh -#' @examples \dontrun{ -#' asam_refresh() -#' } -asam_refresh <- function() { - - tryCatch({ - - tmp_f <- tempfile("asam", fileext=".zip") - on.exit({ unlink(tmp_f) }) - message("Refreshing ASAM database...") - download.file("http://msi.nga.mil/MSISiteContent/StaticFiles/Files/ASAM_shp.zip", - tmp_f, quiet=TRUE) - extr_f <- unzip(tmp_f, overwrite=TRUE, exdir=dirname(tmp_f)) - layer <- gsub("\\..*$", "", basename(extr_f[1])) - - asam_shp <- rgdal::readOGR(grep("shp", extr_f, value=TRUE), - layer, stringsAsFactors=FALSE, verbose=FALSE) - - asam_shp@data$DateOfOcc <- as.Date(asam_shp@data$DateOfOcc, "%Y/%m/%d") - - save(asam_shp, file=system.file("data/asam_shp.rda", package="asam"), - compress = 'xz') - - asam_sf <- sf::read_sf(grep("shp", extr_f, value=TRUE), quiet=TRUE) - - save(asam_sf, file=system.file("data/asam_sf.rda", package="asam"), - compress = 'xz') - - invisible(TRUE) - - }, error=function(err) { - warning("ASAM database refresh unsuccessful.") - invisible(FALSE) - }) - -} diff --git a/README.Rmd b/README.Rmd index 7af0891..66531ad 100644 --- a/README.Rmd +++ b/README.Rmd @@ -3,69 +3,46 @@ output: rmarkdown::github_document editor_options: chunk_output_type: console --- +```{r pkg-knitr-opts, include=FALSE} +hrbrpkghelpr::global_opts() +``` - - -```{r, echo = FALSE} -knitr::opts_chunk$set( - collapse = TRUE, - comment = "#>", - fig.path = "README-", - fig.retina=2 -) +```{r badges, results='asis', echo=FALSE, cache=FALSE} +hrbrpkghelpr::stinking_badges() ``` ![](asam.png) -`asam` is an R package providing tools to access, download, update, process and visualize [Anti-shipping Activity Messages](http://msi.nga.mil/NGAPortal/MSI.portal?_nfpb=true&_pageLabel=msi_portal_page_65) (ASAM) Database Files +```{r description, results='asis', echo=FALSE, cache=FALSE} +hrbrpkghelpr::yank_title_and_description() +``` -Anti-shipping Activity Messages (ASAM) include the locations and -descriptive accounts of specific hostile acts against ships and mariners. -The reports may be useful for recognition, prevention and avoidance of -potential hostile activity. The 'asam' package provides a snapshot of the -official ASAM database, utilities to update the local database and the -official polygons defining the ASAM global regions and subregions. +## What's Inside The Tin The following functions are implemented: -- `asam_refresh`: Refresh ASAM database -- `asam_subregions`: Retrieve ASAM subregions polygons as either a `SpatialPolygonsDataFrame` or simple features collection - -The following data sets are included: - -- `data(asam_shp)` : Snapshot of the ASAM dataset (spatial/shapefile) -- `data(asam_sf)` : Snapshot of the ASAM dataset (simple features collection) -- `system.file("geojson/asam.geojson", package="asam")` : Official ASAM regions & subregions shapefile - -### Installation - -```{r eval=FALSE} -devtools::install_github("hrbrmstr/asam") +```{r ingredients, results='asis', echo=FALSE, cache=FALSE} +hrbrpkghelpr::describe_ingredients() ``` -```{r echo=FALSE, message=FALSE, warning=FALSE, error=FALSE} -options(width=120) +## Installation + +```{r install-ex, results='asis', echo=FALSE, cache=FALSE} +hrbrpkghelpr::install_block() ``` -### Usage +## Usage -```{r} +```{r lib-ex} library(asam) -# current verison +# current version packageVersion("asam") ``` -### Test Results - -```{r message=FALSE} +```{r libs} library(asam) -library(testthat) -library(sp) -library(ggplot2) -library(ggthemes) -library(ggalt) library(tidyverse) date() @@ -73,51 +50,31 @@ date() *See the subregion map* -```{r} +```{r subregions} subregions <- asam_subregions() -plot(subregions) + +subregions + +suppressWarnings(plot(select(subregions, geometry))) ``` *Find all the incidents by pirates this year* ```{r} -data(asam_sf) +asam <- read_asam() -filter(asam_sf, grepl("(pira|rob|hie|band|aila|jack|trud)", - Aggressor, ignore.case=TRUE), - lubridate::year(DateOfOcc) == 2016) %>% - pull(geometry) %>% - as("Spatial") %>% - as_data_frame() -> pirates +asam -pirates +filter(asam, grepl("pirate", hostility, ignore.case=TRUE), lubridate::year(date) == lubridate::year(Sys.Date())) ``` -*and plot them* - -```{r map, fig.width=10, fig.height=4.5, warning=FALSE} -subregions_map <- fortify(subregions) -world <- map_data("world") - -gg <- ggplot() -gg <- gg + geom_cartogram(data=world, map=world, - aes(x=long, y=lat, map_id=region), - color="black", fill="#e7e7e7", size=0.15) -gg <- gg + geom_cartogram(data=subregions_map, map=subregions_map, - aes(x=long, y=lat, map_id=id), - color="white", fill="white", size=0.15, alpha=0) -gg <- gg + geom_point(data=pirates, color="black", fill="yellow", - aes(x=coords.x1, y=coords.x2), shape=21) -gg <- gg + xlim(-170, 170) -gg <- gg + ylim(-58, 75) -gg <- gg + coord_proj("+proj=wintri") -gg <- gg + theme_map() -gg <- gg + theme(panel.background=element_rect(fill="steelblue")) -gg -``` +## asam Metrics +```{r cloc, echo=FALSE} +cloc::cloc_pkg_md() +``` -### Code of Conduct +## Code of Conduct -Please note that this project is released with a [Contributor Code of Conduct](CONDUCT.md). +Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. diff --git a/README.md b/README.md index 6570020..ae08cec 100644 --- a/README.md +++ b/README.md @@ -1,122 +1,156 @@ - +[![Project Status: Active – The project has reached a stable, usable +state and is being actively +developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) +[![Signed +by](https://img.shields.io/badge/Keybase-Verified-brightgreen.svg)](https://keybase.io/hrbrmstr) +![Signed commit +%](https://img.shields.io/badge/Signed_Commits-25.0%25-lightgrey.svg) +[![Linux build +Status](https://travis-ci.org/hrbrmstr/asam.svg?branch=master)](https://travis-ci.org/hrbrmstr/asam) +[![Coverage +Status](https://codecov.io/gh/hrbrmstr/asam/branch/master/graph/badge.svg)](https://codecov.io/gh/hrbrmstr/asam) +![Minimal R +Version](https://img.shields.io/badge/R%3E%3D-3.2.0-blue.svg) +![License](https://img.shields.io/badge/License-MIT-blue.svg) + ![](asam.png) -`asam` is an R package providing tools to access, download, update, process and visualize [Anti-shipping Activity Messages](http://msi.nga.mil/NGAPortal/MSI.portal?_nfpb=true&_pageLabel=msi_portal_page_65) (ASAM) Database Files +# asam -Anti-shipping Activity Messages (ASAM) include the locations and descriptive accounts of specific hostile acts against ships and mariners. The reports may be useful for recognition, prevention and avoidance of potential hostile activity. The 'asam' package provides a snapshot of the official ASAM database, utilities to update the local database and the official polygons defining the ASAM global regions and subregions. +Read and work with Anti-shipping Activity Messages (ASAM) database files -The following functions are implemented: +## Description -- `asam_refresh`: Refresh ASAM database -- `asam_subregions`: Retrieve ASAM subregions polygons as either a `SpatialPolygonsDataFrame` or simple features collection +Anti-shipping Activity Messages (‘ASAM’) include the locations and +descriptive accounts of specific hostile acts against ships and +mariners. The reports may be useful for recognition, prevention and +avoidance of potential hostile activity. Tools are provided to download +the official ‘ASAM’ database along with a geojson version of the +official polygons defining the ‘ASAM’ global regions and subregions. +Data is from -The following data sets are included: +## What’s Inside The Tin -- `data(asam_shp)` : Snapshot of the ASAM dataset (spatial/shapefile) -- `data(asam_sf)` : Snapshot of the ASAM dataset (simple features collection) -- `system.file("geojson/asam.geojson", package="asam")` : Official ASAM regions & subregions shapefile +The following functions are implemented: -### Installation + - `asam_subregions`: Retrieve ASAM subregions polygons + - `read_asam`: Read ASAM database The ASAM database is updated daily + by the National Geospatial-Intelligence Agency (NGIA) and this + function provides a simple means to download it. + +## Installation ``` r -devtools::install_github("hrbrmstr/asam") +remotes::install_git("https://git.rud.is/hrbrmstr/asam.git") +# or +remotes::install_git("https://git.sr.ht/~hrbrmstr/asam") +# or +remotes::install_gitlab("hrbrmstr/asam") +# or +remotes::install_bitbucket("hrbrmstr/asam") +# or +remotes::install_github("hrbrmstr/asam") ``` -### Usage +NOTE: To use the ‘remotes’ install options you will need to have the +[{remotes} package](https://github.com/r-lib/remotes) installed. + +## Usage ``` r library(asam) -# current verison +# current version packageVersion("asam") -#> [1] '0.1.0' +## [1] '0.2.0' ``` -### Test Results - ``` r library(asam) -library(testthat) -library(sp) -library(ggplot2) -library(ggthemes) -library(ggalt) library(tidyverse) date() -#> [1] "Sun Jun 18 09:37:15 2017" +## [1] "Sun Nov 3 16:11:50 2019" ``` *See the subregion map* ``` r subregions <- asam_subregions() -plot(subregions) + +subregions +## Simple feature collection with 58 features and 6 fields +## geometry type: POLYGON +## dimension: XY +## bbox: xmin: -180 ymin: -90 xmax: 180 ymax: 90 +## epsg (SRID): 4326 +## proj4string: +proj=longlat +datum=WGS84 +no_defs +## First 10 features: +## OBJECTID ID SUBREGION REGION Shape_Leng Shape_Area geometry +## 1 1 1 83 8 275.90637 4513.12768 POLYGON ((-180 -26.98819, -... +## 2 2 2 19 1 144.08198 1216.84278 POLYGON ((-180 17.9181, -18... +## 3 3 3 17 1 66.67966 248.73010 POLYGON ((-150 45, -150 52,... +## 4 4 4 18 1 116.55910 692.64299 POLYGON ((-123.4279 50.3571... +## 5 5 5 21 2 123.27130 672.56328 POLYGON ((-116 32.75, -105.... +## 6 6 6 28 2 70.84287 180.14091 POLYGON ((-105.4171 28.9852... +## 7 7 7 27 2 25.87120 37.47341 POLYGON ((-86 23.5, -79.600... +## 8 8 8 11 1 107.27366 504.85999 POLYGON ((-116 32.75, -107.... +## 9 9 9 26 2 80.53508 219.35296 POLYGON ((-74.25001 32.9353... +## 10 10 10 25 2 89.06587 450.16167 POLYGON ((-64.00001 34.7272... + +suppressWarnings(plot(select(subregions, geometry))) ``` - + *Find all the incidents by pirates this year* ``` r -data(asam_sf) - -filter(asam_sf, grepl("(pira|rob|hie|band|aila|jack|trud)", - Aggressor, ignore.case=TRUE), - lubridate::year(DateOfOcc) == 2016) %>% - pull(geometry) %>% - as("Spatial") %>% - as_data_frame() -> pirates - -pirates -#> # A tibble: 473 x 2 -#> coords.x1 coords.x2 -#> -#> 1 105.16667 3.000000 -#> 2 116.80000 -1.466667 -#> 3 -77.18333 -12.016667 -#> 4 -75.55000 10.316667 -#> 5 -69.31667 19.200000 -#> 6 121.73333 5.883333 -#> 7 101.50000 1.683333 -#> 8 -65.43333 18.150000 -#> 9 101.48333 1.700000 -#> 10 112.50000 16.183333 -#> # ... with 463 more rows +asam <- read_asam() + +asam +## # A tibble: 7,843 x 9 +## reference date latitude longitude navArea subreg hostility victim description +## +## 1 2019-73 2019-09-30 1.04 104. XI 71 Five Armed ro… Bulk Car… , SINGAPORE STRAITS. DECK CREW ON RO… +## 2 2019-72 2019-09-28 5.33 120. XI 92 Two High-spee… Bulk Car… AROUND 12NM NW OF TAWI-TAWI ISLAND, … +## 3 2019-75 2019-09-23 6.28 3.23 II 57 On September 23rd a duty watchman on… +## 4 2019-74 2019-09-23 5.46 119. XI 72 Seven people … two fish… TWO FISHING BOATS SAILED TOWARDS TAM… +## 5 2019-76 2019-09-16 9.42 -13.7 II 51 Four armed ro… Tanker On September 16th four robbers armed… +## 6 2019-71 2019-07-21 2.92 105. XI 71 PIRATES BULK CAR… INDONESIA: On 21 July, seven pirates… +## 7 2019-70 2019-07-21 8.47 -13.5 II 51 ROBBERS CONTAINE… SIERRA LEONE: On 21 July, five robbe… +## 8 2019-68 2019-07-16 1.17 104. XI 71 ROBBERS TUG INDONESIA: On 16 July, robbers board… +## 9 2019-69 2019-07-13 9.59 -79.5 IV 26 PIRATES PLEASURE… PANAMA: On 13 July, a monohull with … +## 10 2019-67 2019-07-13 2.97 4.67 II 57 PIRATES CARGO SH… NIGERIA: On 13 July, pirates boarded… +## # … with 7,833 more rows + +filter(asam, grepl("pirate", hostility, ignore.case=TRUE), lubridate::year(date) == lubridate::year(Sys.Date())) +## # A tibble: 31 x 9 +## reference date latitude longitude navArea subreg hostility victim description +## +## 1 2019-71 2019-07-21 2.92 105. XI 71 PIRATES BULK CARR… INDONESIA: On 21 July, seven pirates arm… +## 2 2019-69 2019-07-13 9.59 -79.5 IV 26 PIRATES PLEASURE … PANAMA: On 13 July, a monohull with two … +## 3 2019-67 2019-07-13 2.97 4.67 II 57 PIRATES CARGO SHIP NIGERIA: On 13 July, pirates boarded the… +## 4 2019-65 2019-07-01 12.9 43.2 IX 62 PIRATES MERCHANT … RED SEA: On 1 July, a merchant vessel un… +## 5 2019-57 2019-06-03 4.23 7.1 II 57 PIRATES SPEEDBOATS NIGERIA: On 3 June, five Port Harcourt-b… +## 6 2019-56 2019-05-31 0.0500 -51.0 V 24 PIRATES BULK CARR… BRAZIL: On 31 May, six persons armed wit… +## 7 2019-46 2019-05-12 6.00 1.27 II 57 PIRATES CHEMICAL … TOGO: On 12 May, armed persons boarded a… +## 8 2019-53 2019-05-05 3. 7.83 II 57 PIRATES SEMI-SUB … EQUATORIAL GUINEA: On 5 May, the semi-su… +## 9 2019-52 2019-05-05 3.07 7.98 II 57 PIRATES TUG BOAT EQUATORIAL GUINEA: On 5 May, pirates hij… +## 10 2019-40 2019-04-24 -0.483 48.6 VIII 61 Pirates Multiple … INDIAN OCEAN: On 21 April, fishing vesse… +## # … with 21 more rows ``` -*and plot them* - -``` r -subregions_map <- fortify(subregions) -#> Regions defined for each Polygons -world <- map_data("world") -#> -#> Attaching package: 'maps' -#> The following object is masked from 'package:purrr': -#> -#> map - -gg <- ggplot() -gg <- gg + geom_cartogram(data=world, map=world, - aes(x=long, y=lat, map_id=region), - color="black", fill="#e7e7e7", size=0.15) -gg <- gg + geom_cartogram(data=subregions_map, map=subregions_map, - aes(x=long, y=lat, map_id=id), - color="white", fill="white", size=0.15, alpha=0) -gg <- gg + geom_point(data=pirates, color="black", fill="yellow", - aes(x=coords.x1, y=coords.x2), shape=21) -gg <- gg + xlim(-170, 170) -gg <- gg + ylim(-58, 75) -gg <- gg + coord_proj("+proj=wintri") -gg <- gg + theme_map() -gg <- gg + theme(panel.background=element_rect(fill="steelblue")) -gg -``` +## asam Metrics - +| Lang | \# Files | (%) | LoC | (%) | Blank lines | (%) | \# Lines | (%) | +| :--- | -------: | ---: | --: | --: | ----------: | ---: | -------: | ---: | +| R | 5 | 0.83 | 26 | 0.6 | 7 | 0.21 | 52 | 0.58 | +| Rmd | 1 | 0.17 | 17 | 0.4 | 26 | 0.79 | 37 | 0.42 | -### Code of Conduct +## Code of Conduct -Please note that this project is released with a [Contributor Code of Conduct](CONDUCT.md). By participating in this project you agree to abide by its terms. +Please note that this project is released with a Contributor Code of +Conduct. By participating in this project you agree to abide by its +terms. diff --git a/data/asam_sf.rda b/data/asam_sf.rda deleted file mode 100644 index 6fe545f..0000000 Binary files a/data/asam_sf.rda and /dev/null differ diff --git a/data/asam_shp.rda b/data/asam_shp.rda deleted file mode 100644 index 1302fb5..0000000 Binary files a/data/asam_shp.rda and /dev/null differ diff --git a/man/asam.Rd b/man/asam.Rd index 481e47f..e08984b 100644 --- a/man/asam.Rd +++ b/man/asam.Rd @@ -4,21 +4,22 @@ \name{asam} \alias{asam} \alias{asam-package} -\title{Access, download, update and work with Anti-shipping Activity Messages (ASAM) -database files} +\title{Read and work with Anti-shipping Activity Messages (ASAM) database files} \description{ Anti-shipping Activity Messages ('ASAM') include the locations and descriptive accounts of specific hostile acts against ships and mariners. The reports may be useful for recognition, prevention and avoidance of -potential hostile activity. A snapshot of the official 'ASAM' database is -included along with utilities to update the local database and the -official polygons defining the 'ASAM' global regions and subregions. +potential hostile activity. Tools are provided to download the official 'ASAM' +database along with a geojson version of the official polygons defining the +'ASAM' global regions and subregions. Data is from \url{https://msi.nga.mil/Piracy} } -\details{ +\seealso{ +Useful links: \itemize{ -\item URL: \url{http://gitlab.com/hrbrmstr/asam} -\item BugReports: \url{https://gitlab.com/hrbrmstr/asam/issues} + \item \url{http://gitlab.com/hrbrmstr/asam} + \item Report bugs at \url{https://gitlab.com/hrbrmstr/asam/issues} } + } \author{ Bob Rudis (bob@rud.is) diff --git a/man/asam_refresh.Rd b/man/asam_refresh.Rd deleted file mode 100644 index 79eccb8..0000000 --- a/man/asam_refresh.Rd +++ /dev/null @@ -1,26 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/refresh.r -\name{asam_refresh} -\alias{asam_refresh} -\title{Refresh ASAM database - -The \code{asam} pacakge comes with a snapshot of the official ASAM -database. This database is updated daily by the National Geospatial-Intelligence -Agency (NGIA) and this function provides a simple means to refresh it.} -\usage{ -asam_refresh() -} -\value{ -(invisible) \code{TRUE} or \code{FALSE} depending on the success of - the retrieval. -} -\description{ -\code{asam_refresh} will fetch the latest (the files are udated daily) - ASAM shapefile database and overwrite the one installed with the package - (or previously updated). -} -\examples{ -\dontrun{ -asam_refresh() -} -} diff --git a/man/asam_sf.Rd b/man/asam_sf.Rd deleted file mode 100644 index 83bdda6..0000000 --- a/man/asam_sf.Rd +++ /dev/null @@ -1,45 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data.r -\docType{data} -\name{asam_sf} -\alias{asam_sf} -\title{ASAM (Anti-shipping Activity Messages) Data (simple features)} -\format{A simple feature collection with 8,003 features and 12 fields} -\usage{ -data(asam_sf) -} -\description{ -This dataset contains data from the National Geospatial - Intelligence Acency's Anti-shipping Activity Messages (ASAM) - database. This include the locations and descriptive accounts - of specific hostile acts against ships and mariners. The reports - may be useful for recognition, prevention and avoidance of - potential hostile activity. - -\itemize{ - \item \code{Reference}: ASAM Reference Number - \item \code{DateOfOcc}: Date of incident occurrence (a \code{Date} object) - \item \code{SubReg}: Geographical Subregion. See - \url{http://fas.org/irp/world/para/docs/geol_geo.htm} for a map of - the boundaries for these locations or the \code{\link{asam_subregions}} - function in this package. - \item \code{Aggressor}: Who was the aggressor - \item \code{Descript}: Description of the anti-shipping activity - \item \code{Desc1}: Description of the anti-shipping activity - \item \code{Desc2}: Description of the anti-shipping activity - \item \code{Desc3}: Description of the anti-shipping activity - \item \code{Desc4}: Description of the anti-shipping activity - \item \code{Desc5}: Description of the anti-shipping activity - \item \code{Desc6}: Description of the anti-shipping activity -} -} -\note{ -Last updated 2018-09-23 -} -\references{ -\href{http://msi.nga.mil/NGAPortal/MSI.portal?_nfpb=true&_pageLabel=msi_portal_page_65}{ASAM home} -} -\seealso{ -\code{\link{asam_refresh}} for updating the dataset, -} -\keyword{datasets} diff --git a/man/asam_shp.Rd b/man/asam_shp.Rd deleted file mode 100644 index 5dc8069..0000000 --- a/man/asam_shp.Rd +++ /dev/null @@ -1,45 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data.r -\docType{data} -\name{asam_shp} -\alias{asam_shp} -\title{ASAM (Anti-shipping Activity Messages) Data (shapefile)} -\format{A \code{SpatialPointsDataFrame} with 12 variables and 8,003 observations} -\usage{ -data(asam_shp) -} -\description{ -This dataset contains data from the National Geospatial - Intelligence Acency's Anti-shipping Activity Messages (ASAM) - database. This include the locations and descriptive accounts - of specific hostile acts against ships and mariners. The reports - may be useful for recognition, prevention and avoidance of - potential hostile activity. - -\itemize{ - \item \code{Reference}: ASAM Reference Number - \item \code{DateOfOcc}: Date of incident occurrence (a \code{Date} object) - \item \code{SubReg}: Geographical Subregion. See - \url{http://fas.org/irp/world/para/docs/geol_geo.htm} for a map of - the boundaries for these locations or the \code{\link{asam_subregions}} - function in this package. - \item \code{Aggressor}: Who was the aggressor - \item \code{Descript}: Description of the anti-shipping activity - \item \code{Desc1}: Description of the anti-shipping activity - \item \code{Desc2}: Description of the anti-shipping activity - \item \code{Desc3}: Description of the anti-shipping activity - \item \code{Desc4}: Description of the anti-shipping activity - \item \code{Desc5}: Description of the anti-shipping activity - \item \code{Desc6}: Description of the anti-shipping activity -} -} -\note{ -Last updated 2018-09-23 -} -\references{ -\href{http://msi.nga.mil/NGAPortal/MSI.portal?_nfpb=true&_pageLabel=msi_portal_page_65}{ASAM home} -} -\seealso{ -\code{\link{asam_refresh}} for updating the dataset, -} -\keyword{datasets} diff --git a/man/asam_subregions.Rd b/man/asam_subregions.Rd index 0226d72..355547d 100644 --- a/man/asam_subregions.Rd +++ b/man/asam_subregions.Rd @@ -4,13 +4,7 @@ \alias{asam_subregions} \title{Retrieve ASAM subregions polygons} \usage{ -asam_subregions(sp = TRUE) -} -\arguments{ -\item{sp}{if \code{TRUE} then return a \code{Spatial} object otherwise return a simple feature collection} -} -\value{ -\code{SpatialPolygonsDataFrame} +asam_subregions() } \description{ Returns the official ASAM Subregions polygons as a \code{SpatialPolygonsDataFrame} @@ -32,6 +26,5 @@ chart numbers refer to the geographic subregion. \examples{ \dontrun{ plot(asam_subregions()) -plot(asam_subregions(FALSE)) } } diff --git a/man/figures/README-subregions-1.png b/man/figures/README-subregions-1.png new file mode 100644 index 0000000..7c5b66c Binary files /dev/null and b/man/figures/README-subregions-1.png differ diff --git a/man/read_asam.Rd b/man/read_asam.Rd new file mode 100644 index 0000000..d823c84 --- /dev/null +++ b/man/read_asam.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/read.r +\name{read_asam} +\alias{read_asam} +\title{Read ASAM database + +The ASAM database is updated daily by the National Geospatial-Intelligence +Agency (NGIA) and this function provides a simple means to download it.} +\usage{ +read_asam(quiet = FALSE) +} +\arguments{ +\item{quiet}{if `TRUE` no messages} +} +\description{ +Read ASAM database + +The ASAM database is updated daily by the National Geospatial-Intelligence +Agency (NGIA) and this function provides a simple means to download it. +} +\examples{ +\dontrun{ +read_asam() +} +}