Skip to content

Commit

Permalink
cran readY'
Browse files Browse the repository at this point in the history
  • Loading branch information
SymbolixAU committed May 25, 2018
1 parent 33248f6 commit 8b1f67c
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 148 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: googleway
Type: Package
Title: Accesses Google Maps APIs to Retrieve Data and Plot Maps
Version: 2.6.1004
Date: 2018-04-29
Version: 2.7.0
Date: 2018-05-25
Authors@R: c(
person("David", "Cooley", ,"[email protected]", role = c("aut", "cre")),
person("Paulo", "Barcelos", role = "ctb", comment = "Author of c++ decode_pl"),
Expand Down
14 changes: 2 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,14 @@ Provides a mechanism to access various [Google Maps APIs](https://developers.goo

![Google Maps](./vignettes/img/polygon_legend.png)

## v2.6
## v2.7

see [News](https://github.com/SymbolixAU/googleway/blob/master/NEWS.md) for a full list of changes and additions

For specific examples, see the blog posts for

* [sf objects](https://www.symbolix.com.au/blog-main/2018)
* [Colours](https://www.symbolix.com.au/blog-main/sgh8lg7gwfe7kw98df7jh6897dmbge)
* [Legends](https://www.symbolix.com.au/blog-main/rg72j9l8tm85dpz7278ms76ys48gp6)
* [Result Accessors](https://www.symbolix.com.au/blog-main/fhcs36y9h8zftenfhwpsredbeyf3zf)
* [Drag & Drop GeoJSON](https://www.symbolix.com.au/blog-main/b9z2z337hzzfc4hws8gf8lk358473z)
* [API Keys](https://www.symbolix.com.au/blog-main/2018-1)
* [Load Interval](https://www.symbolix.com.au/blog-main/5376khrw92a7cwz7ah4cewbaltjtsn)


See the [**vignette**](https://github.com/SymbolixAU/googleway/blob/master/vignettes/googleway-vignette.Rmd) for instructions and examples.

## v2.7.0 (development)
## v2.7.0001+ (dev)



Expand Down
8 changes: 4 additions & 4 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@

## Release summary

* Updates v2.4.0 to v2.6.0
# Removed all source / C++ code
* Updates v2.6.0 to v2.7.0
* Removed dependencies on undeclared packages from unit tests, as per CRAN request - email "CRAN packages maintained by you" from Kurt Hornik, 2018-05-18


## Test Environments

* local OS X 15.6.0 (High Sierra) install, R 3.4.4
* ubuntu 12.04.5 (on travis-ci), R 3.3.0
* local OS X 15.6.0 (High Sierra) install, R 3.5.0
* travis-ci (ubuntu 14.04.5, R Under development r74781)
* win-builder (devel and release)


Expand Down
232 changes: 102 additions & 130 deletions tests/testthat/test-google_map_layer_sf.R
Original file line number Diff line number Diff line change
@@ -1,130 +1,102 @@
# context("sf")
#
#
# test_that("sf objects encoded", {
#
# df <- data.frame(
# myId = c(1,1,1,1,1,1,1,1,2,2,2,2)
# , lineId = c(1,1,1,1,2,2,2,2,1,1,1,2)
# , lon = c(-80.190, -66.118, -64.757, -80.190, -70.579, -67.514, -66.668, -70.579, -70, -49, -51, -70)
# , lat = c(26.774, 18.466, 32.321, 26.774, 28.745, 29.570, 27.339, 28.745, 22, 23, 22, 22)
# )
#
# p1 <- as.matrix(df[4:1, c("lon", "lat")])
# p2 <- as.matrix(df[8:5, c("lon", "lat")])
# p3 <- as.matrix(df[9:12, c("lon", "lat")])
#
# sfAttrs <- function(sf, geom) {
# attr(sf, "class") <- c("XY", geom, "sfg")
# sf <- list(sf)
# attr(sf, "class") <- c("sfc_POINT", "sfc")
# attr(sf, "precision") <- 0
# bbox <- c(xmin = 0, ymin = 0, xmax = 0, ymax = 0)
# attr(sf, "bbox") <- bbox
# attr(sf, "precision") <- 0
# attr(sf, "n_empty") <- 0
# return(sf)
# }
#
# constructSf <- function(sf) {
# sf <- data.frame(geometry = sf)
# attr(sf, "class") <- c("sf", "data.frame")
# attr(sf, "sf_column") <- "geometry"
# attr(sf, "agr") <- factor()
# return(sf)
# }
#
# pt <- matrix(c(df[1, "lon"], df[1, "lat"]), nrow = 1)
# mp <- as.matrix(df[1:2, c("lon", "lat")])
# ln <- p3
#
# dfpt <- data.frame(geometry = as.list(pt))
# attr(dfpt, "class") <- c("sf", "data.frame")
#
# data.frame(list(mp))
# data.frame(list(ln))
# data.frame(geometry = list(mp, ln))
#
# pt <- sfAttrs(pt, "POINT")
# pt <- constructSf(pt)
#
# mp <- sfAttrs(mp, "MULTIPOINT")
# #mp <- constructSf(mp)
# ln <- sfAttrs(ln, "LINESTRING")
# #ln <- constructSf(ln)
# ml <- list(p1, p2)
# ml <- sfAttrs(ml, "MULTILINESTRING")
# #ml <- constructSf(ml)
# po <- list(p1, p2)
# po <- sfAttrs(po, "POLYGON")
# #po <- constructSf(po)
# mpl <- list( list(p1, p2), list(p3) )
# mpl <- sfAttrs(mpl, "MULTIPOLYGON")
# #mpl <- constructSf(mpl)
#
# rbind(pt, mp)
#
# #
# sf <- rbind(
# sf::st_sf(geometry = point),
# sf::st_sf(geometry = multipolygon),
# sf::st_sf(geometry = multilinestring),
# sf::st_sf(geometry = linestring),
# sf::st_sf(geometry = point),
# sf::st_sf(geometry = multipoint)
# )
#
# expect_true(inherits(googleway:::normalise_sf(sf), "sfencoded"))
#
# enc <- googlePolylines::encode(sf)
# expect_true(googleway:::findEncodedColumn(enc, NULL) == "geometry")
# expect_true(googleway:::findEncodedColumn(enc, "geometry") == "geometry")
#
# df <- data.frame(polyline = "abc")
# expect_true(googleway:::findEncodedColumn(df, 'polyline') == "polyline")
#
# })
#
# test_that("correct sf rows are returned", {
#
# df <- data.frame(myId = c(1,1,1,1,1,1,1,1,2,2,2,2),
# lineId = c(1,1,1,1,2,2,2,2,1,1,1,2),
# lon = c(-80.190, -66.118, -64.757, -80.190, -70.579, -67.514, -66.668, -70.579, -70, -49, -51, -70),
# lat = c(26.774, 18.466, 32.321, 26.774, 28.745, 29.570, 27.339, 28.745, 22, 23, 22, 22))
#
# p1 <- as.matrix(df[4:1, c("lon", "lat")])
# p2 <- as.matrix(df[8:5, c("lon", "lat")])
# p3 <- as.matrix(df[9:12, c("lon", "lat")])
#
# point <- sf::st_sfc(sf::st_point(x = c(df[1,"lon"], df[1,"lat"])))
# multipoint <- sf::st_sfc(sf::st_multipoint(x = as.matrix(df[1:2, c("lon", "lat")])))
# polygon <- sf::st_sfc(sf::st_polygon(x = list(p1, p2)))
# linestring <- sf::st_sfc(sf::st_linestring(p3))
# multilinestring <- sf::st_sfc(sf::st_multilinestring(list(p1, p2)))
# multipolygon <- sf::st_sfc(sf::st_multipolygon(x = list(list(p1, p2), list(p3))))
#
# sf <- rbind(
# sf::st_sf(geometry = polygon),
# sf::st_sf(geometry = multipolygon),
# sf::st_sf(geometry = multilinestring),
# sf::st_sf(geometry = linestring),
# sf::st_sf(geometry = point),
# sf::st_sf(geometry = multipoint)
# )
#
# expect_true(nrow(googleway:::normaliseSfData(sf, "POLYGON")) == 2)
# expect_true(nrow(googleway:::normaliseSfData(sf, "LINE")) == 2)
# expect_true(nrow(googleway:::normaliseSfData(sf, "POINT")) == 2)
#
# enc <- googlePolylines::encode(sf)
#
# expect_identical(enc, googleway:::normalise_sf(sf))
# expect_identical(enc, googleway:::normalise_sf(enc))
# expect_error(googleway:::normalise_sf(""), "Expecting an sf or sfencoded object to add_sf")
#
# expect_true(nrow(googleway:::normaliseSfData(enc, "POLYGON")) == 2)
# expect_true(nrow(googleway:::normaliseSfData(enc, "LINE")) == 2)
# expect_true(nrow(googleway:::normaliseSfData(enc, "POINT")) == 2)
#
# })
#
context("sf")


test_that("sf objects encoded", {

sf <- structure(list(geometry = structure(list(structure(list(structure(c(-80.19,
-64.757, -66.118, -80.19, 26.774, 32.321, 18.466, 26.774), .Dim = c(4L,
2L), .Dimnames = list(c("4", "3", "2", "1"), c("lon", "lat"))),
structure(c(-70.579, -66.668, -67.514, -70.579, 28.745, 27.339,
29.57, 28.745), .Dim = c(4L, 2L), .Dimnames = list(c("8",
"7", "6", "5"), c("lon", "lat")))), class = c("XY", "POLYGON",
"sfg")), structure(list(list(structure(c(-80.19, -64.757, -66.118,
-80.19, 26.774, 32.321, 18.466, 26.774), .Dim = c(4L, 2L), .Dimnames = list(
c("4", "3", "2", "1"), c("lon", "lat"))), structure(c(-70.579,
-66.668, -67.514, -70.579, 28.745, 27.339, 29.57, 28.745), .Dim = c(4L,
2L), .Dimnames = list(c("8", "7", "6", "5"), c("lon", "lat")))),
list(structure(c(-70, -49, -51, -70, 22, 23, 22, 22), .Dim = c(4L,
2L), .Dimnames = list(c("9", "10", "11", "12"), c("lon",
"lat"))))), class = c("XY", "MULTIPOLYGON", "sfg")), structure(list(
structure(c(-80.19, -64.757, -66.118, -80.19, 26.774, 32.321,
18.466, 26.774), .Dim = c(4L, 2L), .Dimnames = list(c("4",
"3", "2", "1"), c("lon", "lat"))), structure(c(-70.579, -66.668,
-67.514, -70.579, 28.745, 27.339, 29.57, 28.745), .Dim = c(4L,
2L), .Dimnames = list(c("8", "7", "6", "5"), c("lon", "lat"
)))), class = c("XY", "MULTILINESTRING", "sfg")), structure(c(-70,
-49, -51, -70, 22, 23, 22, 22), .Dim = c(4L, 2L), .Dimnames = list(
c("9", "10", "11", "12"), c("lon", "lat")), class = c("XY",
"LINESTRING", "sfg")), structure(c(-80.19, 26.774), class = c("XY",
"POINT", "sfg")), structure(c(-80.19, -66.118, 26.774, 18.466
), .Dim = c(2L, 2L), .Dimnames = list(c("1", "2"), c("lon", "lat"
)), class = c("XY", "MULTIPOINT", "sfg"))), class = c("sfc_GEOMETRY",
"sfc"), precision = 0, bbox = structure(c(xmin = -80.19, ymin = 18.466,
xmax = -49, ymax = 32.321), class = "bbox"), crs = structure(list(
epsg = NA_integer_, proj4string = NA_character_), class = "crs"), n_empty = 0L, classes = c("POLYGON",
"MULTIPOLYGON", "MULTILINESTRING", "LINESTRING", "POINT", "MULTIPOINT"
))), row.names = c(NA, 6L), sf_column = "geometry", agr = structure(integer(0), class = "factor", .Label = c("constant",
"aggregate", "identity"), .Names = character(0)), class = c("sf",
"data.frame"))

expect_true(inherits(googleway:::normalise_sf(sf), "sfencoded"))

enc <- googlePolylines::encode(sf)
expect_true(googleway:::findEncodedColumn(enc, NULL) == "geometry")
expect_true(googleway:::findEncodedColumn(enc, "geometry") == "geometry")

df <- data.frame(polyline = "abc")
expect_true(googleway:::findEncodedColumn(df, 'polyline') == "polyline")

})

test_that("correct sf rows are returned", {

sf <- structure(list(geometry = structure(list(structure(list(structure(c(-80.19,
-64.757, -66.118, -80.19, 26.774, 32.321, 18.466, 26.774), .Dim = c(4L,
2L), .Dimnames = list(c("4", "3", "2", "1"), c("lon", "lat"))),
structure(c(-70.579, -66.668, -67.514, -70.579, 28.745, 27.339,
29.57, 28.745), .Dim = c(4L, 2L), .Dimnames = list(c("8",
"7", "6", "5"), c("lon", "lat")))), class = c("XY", "POLYGON",
"sfg")), structure(list(list(structure(c(-80.19, -64.757, -66.118,
-80.19, 26.774, 32.321, 18.466, 26.774), .Dim = c(4L, 2L), .Dimnames = list(
c("4", "3", "2", "1"), c("lon", "lat"))), structure(c(-70.579,
-66.668, -67.514, -70.579, 28.745, 27.339, 29.57, 28.745), .Dim = c(4L,
2L), .Dimnames = list(c("8", "7", "6", "5"), c("lon", "lat")))),
list(structure(c(-70, -49, -51, -70, 22, 23, 22, 22), .Dim = c(4L,
2L), .Dimnames = list(c("9", "10", "11", "12"), c("lon",
"lat"))))), class = c("XY", "MULTIPOLYGON", "sfg")), structure(list(
structure(c(-80.19, -64.757, -66.118, -80.19, 26.774, 32.321,
18.466, 26.774), .Dim = c(4L, 2L), .Dimnames = list(c("4",
"3", "2", "1"), c("lon", "lat"))), structure(c(-70.579, -66.668,
-67.514, -70.579, 28.745, 27.339, 29.57, 28.745), .Dim = c(4L,
2L), .Dimnames = list(c("8", "7", "6", "5"), c("lon", "lat"
)))), class = c("XY", "MULTILINESTRING", "sfg")), structure(c(-70,
-49, -51, -70, 22, 23, 22, 22), .Dim = c(4L, 2L), .Dimnames = list(
c("9", "10", "11", "12"), c("lon", "lat")), class = c("XY",
"LINESTRING", "sfg")), structure(c(-80.19, 26.774), class = c("XY",
"POINT", "sfg")), structure(c(-80.19, -66.118, 26.774, 18.466
), .Dim = c(2L, 2L), .Dimnames = list(c("1", "2"), c("lon", "lat"
)), class = c("XY", "MULTIPOINT", "sfg"))), class = c("sfc_GEOMETRY",
"sfc"), precision = 0, bbox = structure(c(xmin = -80.19, ymin = 18.466,
xmax = -49, ymax = 32.321), class = "bbox"), crs = structure(list(
epsg = NA_integer_, proj4string = NA_character_), class = "crs"), n_empty = 0L, classes = c("POLYGON",
"MULTIPOLYGON", "MULTILINESTRING", "LINESTRING", "POINT", "MULTIPOINT"
))), row.names = c(NA, 6L), sf_column = "geometry", agr = structure(integer(0), class = "factor", .Label = c("constant",
"aggregate", "identity"), .Names = character(0)), class = c("sf",
"data.frame"))

expect_true(nrow(googleway:::normaliseSfData(sf, "POLYGON")) == 2)
expect_true(nrow(googleway:::normaliseSfData(sf, "LINE")) == 2)
expect_true(nrow(googleway:::normaliseSfData(sf, "POINT")) == 2)

enc <- googlePolylines::encode(sf)

expect_identical(enc, googleway:::normalise_sf(sf))
expect_identical(enc, googleway:::normalise_sf(enc))
expect_error(googleway:::normalise_sf(""), "Expecting an sf or sfencoded object to add_sf")

expect_true(nrow(googleway:::normaliseSfData(enc, "POLYGON")) == 2)
expect_true(nrow(googleway:::normaliseSfData(enc, "LINE")) == 2)
expect_true(nrow(googleway:::normaliseSfData(enc, "POINT")) == 2)

})

0 comments on commit 8b1f67c

Please sign in to comment.