Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
update vignette and readme, some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed Oct 17, 2017
1 parent 0534502 commit f576606
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 98 deletions.
4 changes: 0 additions & 4 deletions R/as_wkt.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
#' res <- mr_geojson(key = "Morocco:dam")
#' mr_as_wkt(res, fmt = 5)
#'
#' nms <- mr_names("MarineRegions:eez")
#' res <- mr_geojson(key = grep("MarineRegions", nms$geoname, value = TRUE)[10])
#' mr_as_wkt(res, fmt = 5)
#'
#' # shp files
#' ## path to wkt
#' mr_as_wkt(mr_shp(key = "Morocco:dam", read = FALSE))
Expand Down
2 changes: 1 addition & 1 deletion R/mr_features_get.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ mime_map <- list(
`application/json` = 'application/json',
`application/vnd.google-earth.kml xml` = 'application/vnd.google-earth.kml+xml',
`application/vnd.google-earth.kml+xml` = 'application/vnd.google-earth.kml+xml',
`csv` = 'text/csv',
`csv` = 'text/csv;charset=UTF-8',
`gml3` = 'application/xml',
`gml32` = 'text/xml; subtype=gml/3.2',
`json` = "application/json;charset=UTF-8",
Expand Down
16 changes: 5 additions & 11 deletions R/region_names_search.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' @param ... Parameters passed on to \code{\link{agrep}}
#'
#' @return \code{NULL} if no matches found, or a data.frame, or tibble, of class
#' tbl_df (basically, a compact data.frame), with slots:
#' \code{tbl_df}, with slots:
#' \itemize{
#' \item name (character) - name of the region, which is a combination of the
#' name_first and name_second, e.g., Morocco:elevation_10m
Expand All @@ -29,12 +29,10 @@
#' mr_names_search(x = "iho", q = "Black")
#' mr_names_search(x = "iho", q = "Sea")
#'
#' # more examples, with and without passing in mr_names() output
#' mr_names_search(res, q = "IHO")
#' mr_names_search("Heritage")
#' mr_names_search(res, q = "Heritage")
#' mr_names_search("ecoregions")
#' mr_names_search(res, q = "ecoregions")
#' # more examples
#' mr_names_search("iho", "Sea")
#' (res <- mr_names("MarineRegions:iho"))
#' mr_names_search(res, q = "Sea")
#' }
mr_names_search <- function(x, q = NULL, ...) {
UseMethod('mr_names_search')
Expand All @@ -50,14 +48,11 @@ mr_names_search.character <- function(x, q = NULL, ...) {
stopifnot(tolower(x) %in% c('eez', 'eez_boundaries', 'iho', 'fao', 'lme'))
mrx <- paste0("MarineRegions:", tolower(x))
xx <- mr_names(mrx)
# q <- x
# x <- mr_names()
do_regns(xx, q, mrx, ...)
}

# helper
do_regns <- function(x, q, mrx = NULL, ...) {
#nmsps <- sort(unique(x$title))
name_field <- switch(
mrx,
`MarineRegions:eez` = "geoname",
Expand All @@ -71,7 +66,6 @@ do_regns <- function(x, q, mrx = NULL, ...) {
if (length(tmp) == 0) {
NULL
} else {
# x[x$title %in% tmp, ]
x[x[[name_field]] %in% tmp, ]
}
}
8 changes: 0 additions & 8 deletions R/region_shp.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,6 @@
#' filter = "Samoan Exclusive Economic Zone"
#' )
#' sp::plot(res)
#'
#'
#' # use curl options
#' library(httr)
#' res <- mr_shp(
#' key = "MarineRegions:eez",
#' config = verbose()
#' )
#' }
mr_shp <- function(key = NULL, name = NULL, maxFeatures = 50,
overwrite = TRUE, read = TRUE, filter = NULL, ...) {
Expand Down
2 changes: 1 addition & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ nameorkey <- function(name, key) {
xx <- c('MarineRegions:eez','MarineRegions:eez_boundaries',
'MarineRegions:iho','MarineRegions:fao', 'MarineRegions:lme')
nms <- dtdf(lapply(xx, mr_names))
nms[nms$geoname == name, ]$name
nms[nms$geoname == name, ]$geoname
} else {
key
}
Expand Down
5 changes: 3 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ leaflet() %>%
setView(-3.9, 35, zoom = 10)
```

![map](https://d17oy1vhnax1f7.cloudfront.net/items/023A1m1m413n20060T0M/Screen%20Shot%202016-12-07%20at%204.13.56%20PM.png)
![map](tools/img/leaf1.png)

## Shape

Get region
Expand All @@ -84,7 +85,7 @@ leaflet() %>%
addPolygons(data = res2)
```

![map2](https://d17oy1vhnax1f7.cloudfront.net/items/3Z1s1r45043Y3m2j0d0N/Screen%20Shot%202016-12-07%20at%204.14.53%20PM.png)
![map2](tools/img/leaf2.png)

## Convert to WKT

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ leaflet() %>%
setView(-3.9, 35, zoom = 10)
```

![map](https://d17oy1vhnax1f7.cloudfront.net/items/023A1m1m413n20060T0M/Screen%20Shot%202016-12-07%20at%204.13.56%20PM.png)
![map](tools/img/leaf1.png)

## Shape

Get region
Expand All @@ -93,7 +94,7 @@ leaflet() %>%
addPolygons(data = res2)
```

![map2](https://d17oy1vhnax1f7.cloudfront.net/items/3Z1s1r45043Y3m2j0d0N/Screen%20Shot%202016-12-07%20at%204.14.53%20PM.png)
![map2](tools/img/leaf2.png)

## Convert to WKT

Expand Down
51 changes: 26 additions & 25 deletions inst/vign/mregions.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,37 +108,38 @@ Either pass output of `mr_names()`

```r
mr_names_search(rnames, "IHO")
#> # A tibble: 7 × 6
#> layer name_first name_second id name mrgid
#> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 MarineRegions:iho MarineRegions iho iho.34 Gulf of Mexico 4288
#> 2 MarineRegions:iho MarineRegions iho iho.37 Rio de La Plata 4325
#> 3 MarineRegions:iho MarineRegions iho iho.82 Ionian Sea 3351
#> 4 MarineRegions:iho MarineRegions iho iho.65 Sea of Okhotsk 4309
#> 5 MarineRegions:iho MarineRegions iho iho.69 Gulf of California 4314
#> 6 MarineRegions:iho MarineRegions iho iho.95 Timor Sea 4344
#> 7 MarineRegions:iho MarineRegions iho iho.62 Seto Naikai or Inland Sea 4306
#> # A tibble: 7 x 6
#> layer name_first name_second id
#> <chr> <chr> <chr> <chr>
#> 1 MarineRegions:iho MarineRegions iho iho.1
#> 2 MarineRegions:iho MarineRegions iho iho.7
#> 3 MarineRegions:iho MarineRegions iho iho.18
#> 4 MarineRegions:iho MarineRegions iho iho.40
#> 5 MarineRegions:iho MarineRegions iho iho.53
#> 6 MarineRegions:iho MarineRegions iho iho.76
#> 7 MarineRegions:iho MarineRegions iho iho.94
#> # ... with 2 more variables: name <chr>, mrgid <chr>
```

or don't (but then `mr_names_search()` call takes longer)


```r
mr_names_search("iho", q = "Sea")
#> # A tibble: 74 × 6
#> layer name_first name_second id name mrgid
#> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 MarineRegions:iho MarineRegions iho iho.1 Inner Seas off the West Coast of Scotland 4283
#> 2 MarineRegions:iho MarineRegions iho iho.2 Mediterranean Sea - Western Basin 4279
#> 3 MarineRegions:iho MarineRegions iho iho.3 Mediterranean Sea - Eastern Basin 4280
#> 4 MarineRegions:iho MarineRegions iho iho.4 Sea of Marmara 3369
#> 5 MarineRegions:iho MarineRegions iho iho.5 Black Sea 3319
#> 6 MarineRegions:iho MarineRegions iho iho.6 Sea of Azov 3320
#> 7 MarineRegions:iho MarineRegions iho iho.7 Irish Sea and St. George's Channel 2357
#> 8 MarineRegions:iho MarineRegions iho iho.10 Bay of Biscay 2359
#> 9 MarineRegions:iho MarineRegions iho iho.11 Celtic Sea 2351
#> 10 MarineRegions:iho MarineRegions iho iho.14 North Sea 2350
#> # ... with 64 more rows
#> # A tibble: 73 x 6
#> layer name_first name_second id
#> <chr> <chr> <chr> <chr>
#> 1 MarineRegions:iho MarineRegions iho iho.3
#> 2 MarineRegions:iho MarineRegions iho iho.4
#> 3 MarineRegions:iho MarineRegions iho iho.6
#> 4 MarineRegions:iho MarineRegions iho iho.7
#> 5 MarineRegions:iho MarineRegions iho iho.8
#> 6 MarineRegions:iho MarineRegions iho iho.10
#> 7 MarineRegions:iho MarineRegions iho iho.15
#> 8 MarineRegions:iho MarineRegions iho iho.16
#> 9 MarineRegions:iho MarineRegions iho iho.17
#> 10 MarineRegions:iho MarineRegions iho iho.27
#> # ... with 63 more rows, and 2 more variables: name <chr>, mrgid <chr>
```

## Get a region - geojson
Expand All @@ -149,7 +150,7 @@ res3 <- mr_geojson(key = "Morocco:dam")
class(res3)
#> [1] "mr_geojson"
names(res3)
#> [1] "type" "totalFeatures" "features" "crs" "bbox"
#> [1] "type" "totalFeatures" "features" "crs"
```

## Get a region - shp
Expand Down
4 changes: 0 additions & 4 deletions man/mr_as_wkt.Rd

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

12 changes: 5 additions & 7 deletions man/mr_names_search.Rd

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

8 changes: 0 additions & 8 deletions man/mr_shp.Rd

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

Binary file added tools/img/leaf1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tools/img/leaf2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 26 additions & 25 deletions vignettes/mregions.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -108,37 +108,38 @@ Either pass output of `mr_names()`

```r
mr_names_search(rnames, "IHO")
#> # A tibble: 7 × 6
#> layer name_first name_second id name mrgid
#> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 MarineRegions:iho MarineRegions iho iho.34 Gulf of Mexico 4288
#> 2 MarineRegions:iho MarineRegions iho iho.37 Rio de La Plata 4325
#> 3 MarineRegions:iho MarineRegions iho iho.82 Ionian Sea 3351
#> 4 MarineRegions:iho MarineRegions iho iho.65 Sea of Okhotsk 4309
#> 5 MarineRegions:iho MarineRegions iho iho.69 Gulf of California 4314
#> 6 MarineRegions:iho MarineRegions iho iho.95 Timor Sea 4344
#> 7 MarineRegions:iho MarineRegions iho iho.62 Seto Naikai or Inland Sea 4306
#> # A tibble: 7 x 6
#> layer name_first name_second id
#> <chr> <chr> <chr> <chr>
#> 1 MarineRegions:iho MarineRegions iho iho.1
#> 2 MarineRegions:iho MarineRegions iho iho.7
#> 3 MarineRegions:iho MarineRegions iho iho.18
#> 4 MarineRegions:iho MarineRegions iho iho.40
#> 5 MarineRegions:iho MarineRegions iho iho.53
#> 6 MarineRegions:iho MarineRegions iho iho.76
#> 7 MarineRegions:iho MarineRegions iho iho.94
#> # ... with 2 more variables: name <chr>, mrgid <chr>
```

or don't (but then `mr_names_search()` call takes longer)


```r
mr_names_search("iho", q = "Sea")
#> # A tibble: 74 × 6
#> layer name_first name_second id name mrgid
#> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 MarineRegions:iho MarineRegions iho iho.1 Inner Seas off the West Coast of Scotland 4283
#> 2 MarineRegions:iho MarineRegions iho iho.2 Mediterranean Sea - Western Basin 4279
#> 3 MarineRegions:iho MarineRegions iho iho.3 Mediterranean Sea - Eastern Basin 4280
#> 4 MarineRegions:iho MarineRegions iho iho.4 Sea of Marmara 3369
#> 5 MarineRegions:iho MarineRegions iho iho.5 Black Sea 3319
#> 6 MarineRegions:iho MarineRegions iho iho.6 Sea of Azov 3320
#> 7 MarineRegions:iho MarineRegions iho iho.7 Irish Sea and St. George's Channel 2357
#> 8 MarineRegions:iho MarineRegions iho iho.10 Bay of Biscay 2359
#> 9 MarineRegions:iho MarineRegions iho iho.11 Celtic Sea 2351
#> 10 MarineRegions:iho MarineRegions iho iho.14 North Sea 2350
#> # ... with 64 more rows
#> # A tibble: 73 x 6
#> layer name_first name_second id
#> <chr> <chr> <chr> <chr>
#> 1 MarineRegions:iho MarineRegions iho iho.3
#> 2 MarineRegions:iho MarineRegions iho iho.4
#> 3 MarineRegions:iho MarineRegions iho iho.6
#> 4 MarineRegions:iho MarineRegions iho iho.7
#> 5 MarineRegions:iho MarineRegions iho iho.8
#> 6 MarineRegions:iho MarineRegions iho iho.10
#> 7 MarineRegions:iho MarineRegions iho iho.15
#> 8 MarineRegions:iho MarineRegions iho iho.16
#> 9 MarineRegions:iho MarineRegions iho iho.17
#> 10 MarineRegions:iho MarineRegions iho iho.27
#> # ... with 63 more rows, and 2 more variables: name <chr>, mrgid <chr>
```

## Get a region - geojson
Expand All @@ -149,7 +150,7 @@ res3 <- mr_geojson(key = "Morocco:dam")
class(res3)
#> [1] "mr_geojson"
names(res3)
#> [1] "type" "totalFeatures" "features" "crs" "bbox"
#> [1] "type" "totalFeatures" "features" "crs"
```

## Get a region - shp
Expand Down

0 comments on commit f576606

Please sign in to comment.