Skip to content

Commit

Permalink
version 0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jalazawa authored and cran-robot committed Nov 17, 2017
0 parents commit 46682bc
Show file tree
Hide file tree
Showing 12 changed files with 556 additions and 0 deletions.
27 changes: 27 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Package: spMaps
Type: Package
Title: Europe SpatialPolygonsDataFrame Builder
Version: 0.1
Date: 2017-11-15
Authors@R: c(
person("Jalal-Edine", "ZAWAM", email = "jalal-edine.zawam@rte-france.com", role = c("aut", "cre")),
person("Benoit", "Thieurmel", email = "benoit.thieurmel@datastorm.fr", role = "aut"),
person("RTE", role = "cph")
)
Maintainer: Jalal-Edine ZAWAM <jalal-edine.zawam@rte-france.com>
Description: Build custom Europe SpatialPolygonsDataFrame, if you don't know what is a SpatialPolygonsDataFrame see SpatialPolygons() in 'sp', by example for mapLayout() in 'antaresViz'. Antares is a powerful software developed by RTE to simulate and study electric power systems (more information about 'Antares' here: <https://antares.rte-france.com>).
URL: https://github.com/rte-antares-rpackage/antaresMaps
BugReports: https://github.com/rte-antares-rpackage/antaresMaps/issues
License: GPL (>= 2) | file LICENSE
LazyData: TRUE
Encoding: UTF-8
Depends: R (>= 2.10), sp
RoxygenNote: 6.0.1
Suggests: testthat, covr
NeedsCompilation: no
Packaged: 2017-11-16 07:47:02 UTC; jalazawa
Author: Jalal-Edine ZAWAM [aut, cre],
Benoit Thieurmel [aut],
RTE [cph]
Repository: CRAN
Date/Publication: 2017-11-17 12:38:17 UTC
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
COPYRIGHT HOLDER: RTE R�seau de transport d'�lectricit�
11 changes: 11 additions & 0 deletions MD5
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
b79134305d97d52407acfc154e9fd3b2 *DESCRIPTION
ed36de57b24b2922c78b0e50e20809a9 *LICENSE
ce49b038f581b9ec6e206e20cf90557d *NAMESPACE
dcaa1256d4b8e5285f459dc474152e10 *R/sysdata.rda
1c507631eba2c255220b19696c9cb282 *R/utils.R
7816407adc31f3b2887fe5305ffcf886 *README.md
2387ca3e1161621e8b175b076404f06d *inst/dataset/build_save_data.R
5bdf4fb8b9f09675569e9ab5e32fc936 *man/spMaps.Rd
a0930d037706bc88c15d2df7a521761d *tests/testthat.R
a26e0b57e38e2a32c2e202e3be70253c *tests/testthat/test-dataset.R
3fbe9a50e3e2dc5693186da2a8b3d68e *tests/testthat/test-getAntaresMap.R
8 changes: 8 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Generated by roxygen2: do not edit by hand

export(getEuropeCountries)
export(getEuropeReferenceTable)
export(getEuropeStates)
export(getSpMaps)
import(sp)
importFrom(utils,data)
Binary file added R/sysdata.rda
Binary file not shown.
143 changes: 143 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
#' @rdname spMaps
#' @export
#' @importFrom utils data
#' @import sp
#'
getEuropeReferenceTable <- function(){
europe_countries_ref$name <- as.character(europe_countries_ref$name)
europe_countries_ref$code <- as.character(europe_countries_ref$code)
europe_countries_ref
}

#' @rdname spMaps
#' @export
#'
getEuropeCountries <- function(){
europe_countries_10m
}

#' @rdname spMaps
#' @export
#'
getEuropeStates <- function(){
europe_states_provinces_10m
}

#' Get custom Europe map (\code{SpatialPolygonsDataFrame})
#'
#' This function builds a custom Europe map and return a \code{SpatialPolygonsDataFrame}.
#' The output can be use by example in \link[antaresViz]{mapLayout} with the \code{map} argument.
#'
#' @param countries \code{character}. Vector of wanted countries, without details / states.
#' Must referred to \code{code} column of the reference table \code{getEuropeReferenceTable}.
#' "all" (default) keep all countries
#'
#' @param states \code{character}. Vector of wanted countries, with details / states.
#' Must referred to \code{code} column of the reference table \code{getEuropeReferenceTable}.
#' "all" keep all countries. NULL as default.
#'
#' @return \code{SpatialPolygonsDataFrame}
#'
#' @examples
#'
#' # default map : Europe without states
#' europe_cty <- getSpMaps()
#' plot(europe_cty)
#'
#' # subset on some countries
#' ref_table <- getEuropeReferenceTable()
#'
#' italy_spain_fra <- getSpMaps(countries = c("FRA", "ITA", "ESP"))
#' plot(italy_spain_fra)
#'
#' \dontrun{
#' italy_spain_fra_states <- getSpMaps(countries = NULL, states = c("FRA", "ITA", "ESP"))
#' plot(italy_spain_fra_states)
#'
#' # combine countries and states
#' combine_map <- getSpMaps(countries = c("ITA", "ESP"), states = "FRA")
#' plot(combine_map)
#'
#' # build your custom map : you can use directly data
#' # to subset the area you really want
#' europe_states <- getEuropeStates()
#' europe_countries <- getEuropeCountries()
#'
#' # for example, have a look to GBR states map
#' summary(europe_states)
#' gbr_states_districts <- europe_states[
#' europe_states$sr_adm0_a3 %in% "GBR" &
#' europe_states$type %in% "Administrative County",]
#' plot(gbr_states_districts)
#'
#' # combine with another map : you just have to have the same columns...
#' # getSpMaps only return "name" column
#' custom_states <- rbind(
#' getSpMaps(countries = NULL, states = "FRA"),
#' gbr_states_districts[, "name", drop = FALSE])
#'
#' plot(custom_states)
#'
#' }
#'
#' @export
#'
#'
#' @name spMaps
#'
getSpMaps <- function(countries = "all", states = NULL){

# controls
if(is.null(countries) & is.null(states)){
message("No countries and no states selected")
return(NULL)
}

# reference table
ref_table <- getEuropeReferenceTable()

# don't show countries if in states
if("all" %in% countries & "all" %in% states){
countries <- NULL
} else if("all" %in% countries & !is.null(states)){
countries <- ref_table$code
countries <- setdiff(countries, states)
} else if(!is.null(countries) & !is.null(states)){
countries <- setdiff(countries, states)
}
if(length(countries) == 0) countries <- NULL

# countries
if(!is.null(countries)){
stopifnot(all(countries %in% c("all", ref_table$code)))
if(!"all" %in% countries){
countries_data <- europe_countries_10m[europe_countries_10m$adm0_a3 %in% countries, ]
} else {
countries_data <- europe_countries_10m
}
} else {
countries_data <- NULL
}

# states
if(!is.null(states)){
stopifnot(all(states %in% c("all", ref_table$code)))
if(!"all" %in% states){
states_data <- europe_states_provinces_10m[europe_states_provinces_10m$sr_adm0_a3 %in% states, ]
} else {
states_data <- europe_states_provinces_10m
}
} else {
states_data <- NULL
}

if(!is.null(countries_data) & is.null(states_data)){
return(countries_data[, c("name"), drop = FALSE])
} else if(is.null(countries_data) & !is.null(states_data)){
return(states_data[, c("name"), drop = FALSE])
} else {
return(rbind(countries_data[, c("name"), drop = FALSE],
states_data[, c("name"), drop = FALSE]))
}
}

23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[![Build status](https://ci.appveyor.com/api/projects/status/rnf5iejmgyu00j1i?svg=true)](https://ci.appveyor.com/project/rte-antares-rpackage/antaresMaps)
[![Build Status](https://travis-ci.org/rte-antares-rpackage/antaresMaps.svg?branch=master)](https://travis-ci.org/rte-antares-rpackage/antaresMaps)
[![codecov](https://codecov.io/gh/rte-antares-rpackage/antaresMaps/branch/master/graph/badge.svg)](https://codecov.io/gh/rte-antares-rpackage/antaresMaps)

# The 'antaresMaps' R package

The `antaresMaps` package provides functions allow to build custom maps to using `antaresViz` (`mapLayout`).

## Installation


To install the current version:

```r
install_github("rte-antares-rpackage/antaresMaps", ref = "master")
```

To display the help of the package and see all the functions it provides, type:


```r
?antaresMaps
```

0 comments on commit 46682bc

Please sign in to comment.