-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
SymbolixAU
committed
May 25, 2018
1 parent
33248f6
commit 8b1f67c
Showing
4 changed files
with
110 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
}) | ||
|