Skip to content

Commit 3f9ae45

Browse files
committed
#172, remove JS stuff, using wicket now
1 parent 5c4f717 commit 3f9ae45

14 files changed

+42
-2463
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ script: ./travis-tool.sh run_tests
55

66
before_script:
77
- sudo apt-get --yes --force-yes update -qq
8-
- sudo apt-get install -y libproj-dev libv8-dev libproj-dev libgeos++-dev
8+
- sudo apt-get install -y libproj-dev libproj-dev libgeos++-dev
99
- curl -OL http://raw.github.com/craigcitro/r-travis/master/scripts/travis-tool.sh
1010
- chmod 755 ./travis-tool.sh
1111
- ./travis-tool.sh bootstrap

DESCRIPTION

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ Imports:
2929
lubridate (>= 1.5.0),
3030
httr (>= 1.1.0),
3131
whisker (>= 0.3-2),
32-
V8 (>= 1.1),
3332
jsonlite (>= 1.1),
3433
data.table (>= 1.9.6),
3534
tibble (>= 1.2),

NAMESPACE

-3
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,7 @@ export(occ_names_options)
8686
export(occ_options)
8787
export(spocc_capwords)
8888
export(wkt2bbox)
89-
export(wkt_read)
9089
export(wkt_vis)
91-
export(wkt_write)
92-
importFrom(V8,new_context)
9390
importFrom(data.table,rbindlist)
9491
importFrom(data.table,setDF)
9592
importFrom(httr,GET)

R/handle_sp.R

+3-16
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,6 @@
3232
# handle_sp(sppoly_df)
3333
# handle_sp(sppoly_df, group = FALSE)[[1]]
3434

35-
handle_sp <- function(spobj, group = TRUE) wicket::sp_convert(spobj, group = group)
36-
# wkt <- make_wkt(spobj)
37-
# stopifnot(is.numeric(length(wkt)))
38-
# stopifnot(length(wkt) > 0)
39-
# return( wkt )
40-
# }
41-
42-
# make_wkt <- function(x){
43-
# coords <- lapply(x@polygons, function(z) {
44-
# z@Polygons[[1]]@coords
45-
# })
46-
# lapply(coords, function(z) {
47-
# geojson <- jsonlite::toJSON(list(type = "Polygon", coordinates = list(z)), auto_unbox = TRUE)
48-
# wkt_write(geojson)
49-
# })
50-
# }
35+
handle_sp <- function(spobj, group = TRUE) {
36+
wicket::sp_convert(spobj, group = group)
37+
}

R/on_load.R

-10
This file was deleted.

R/read_wkt.R

-26
This file was deleted.

R/wkt_bbox.R

-12
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,14 @@
2424
#' wkt <- "POLYGON((-125 38.4,-125 40.9,-121.8 40.9,-121.8 38.4,-125 38.4))"
2525
#' wkt2bbox(wkt)
2626
#' }
27-
2827
bbox2wkt <- function(minx=NA, miny=NA, maxx=NA, maxy=NA, bbox=NULL) {
2928
if (is.null(bbox)) bbox <- list(c(minx, miny, maxx, maxy))
3029
wicket::bounding_wkt(values = bbox)
31-
# stopifnot(length(bbox) == 4) #check for 4 digits
32-
# stopifnot(!any(is.na(bbox))) #check for NAs
33-
# stopifnot(is.numeric(as.numeric(bbox))) #check for numeric-ness
34-
# paste('POLYGON((',
35-
# sprintf('%s %s',bbox[1],bbox[2]), ',', sprintf(' %s %s',bbox[3],bbox[2]), ',',
36-
# sprintf(' %s %s',bbox[3],bbox[4]), ',', sprintf(' %s %s',bbox[1],bbox[4]), ',',
37-
# sprintf(' %s %s',bbox[1],bbox[2]),
38-
# '))', sep = "")
3930
}
4031

4132
#' @param wkt A Well Known Text object.
4233
#' @export
4334
#' @rdname bbox2wkt
4435
wkt2bbox <- function(wkt){
45-
# stopifnot(!is.null(wkt))
46-
# tmp <- wkt_read(wkt)$bbox
47-
# as.vector(tmp)
4836
wicket::wkt_bounding(wkt)
4937
}

R/wkt_vis.r

+38-27
Original file line numberDiff line numberDiff line change
@@ -34,46 +34,57 @@
3434

3535
wkt_vis <- function(x, zoom = 6, maptype = "terrain", browse = TRUE) {
3636
long = lat = group = NULL
37+
3738
stopifnot(!is.null(x))
3839
stopifnot(is.character(x))
39-
40-
out <- wkt_read(gsub("\n|\n\\s+", "", strtrim(x)))
41-
42-
if (inherits(out$coordinates[,,1], "matrix")) {
43-
longs <- data.frame(out$coordinates[,,1])
44-
lats <- data.frame(out$coordinates[,,2])
45-
} else {
46-
longs <- t(data.frame(out$coordinates[,,1]))
47-
lats <- t(data.frame(out$coordinates[,,2]) )
48-
}
49-
tocentroid <- list()
50-
dfs <- list()
51-
for (i in 1:NROW(longs)) {
52-
tocentroid[[i]] <- tmp <- data.frame(long = as.numeric(longs[i,]), lat = as.numeric(lats[i,]))
53-
dfs[[i]] <- apply(tmp, 1, function(x) as.list(x[c('long','lat')]))
54-
}
55-
centroid <- get_centroid(do.call("rbind", tocentroid))
40+
x <- gsub("\n|\n\\s+", "", strtrim(x))
41+
out <- wicket::wkt_coords(x)
42+
centroid <- wicket::get_centroid(x)
43+
dfs <- unname(lapply(split(out, out$ring), function(z) {
44+
unname(
45+
apply(z, 1, function(x) {
46+
as.list(stats::setNames(x[c('lng','lat')], c('long', 'lat')))
47+
})
48+
)
49+
}))
5650

5751
whiskout <- list()
5852
for (i in seq_along(dfs)) {
5953
dats <- dfs[[i]]
6054
whiskout[[i]] <- whisker.render(features)
6155
}
6256
rend <- paste0(map_header, paste(whiskout, sep = "", collapse = ","), map_end)
63-
64-
foot <- sprintf(footer, centroid[2], centroid[1], zoom)
57+
foot <- sprintf(footer, centroid$lat, centroid$lng, zoom)
6558
res <- paste(rend, foot)
6659
tmpfile <- tempfile(pattern = 'spocc', fileext = ".html")
6760
write(res, file = tmpfile)
6861
if (browse) browseURL(tmpfile) else tmpfile
6962
}
7063

71-
get_centroid <- function(x) {
72-
x <- unname(as.matrix(x))
73-
geojson <- jsonlite::toJSON(list(type = "Polygon", coordinates = list(x)), auto_unbox = TRUE)
74-
cent$eval(sprintf("var out = centroid(%s);", geojson))
75-
cent$get("out.geometry.coordinates")
76-
}
64+
65+
# out <- wkt_read(gsub("\n|\n\\s+", "", strtrim(x)))
66+
# if (inherits(out$coordinates[,,1], "matrix")) {
67+
# longs <- data.frame(out$coordinates[,,1])
68+
# lats <- data.frame(out$coordinates[,,2])
69+
# } else {
70+
# longs <- t(data.frame(out$coordinates[,,1]))
71+
# lats <- t(data.frame(out$coordinates[,,2]) )
72+
# }
73+
# tocentroid <- list()
74+
# dfs <- list()
75+
# for (i in 1:NROW(longs)) {
76+
# tocentroid[[i]] <- tmp <- data.frame(long = as.numeric(longs[i,]),
77+
# lat = as.numeric(lats[i,]))
78+
# dfs[[i]] <- apply(tmp, 1, function(x) as.list(x[c('long','lat')]))
79+
# }
80+
# centroid <- get_centroid(do.call("rbind", tocentroid))
81+
82+
# get_centroid <- function(x) {
83+
# x <- unname(as.matrix(x))
84+
# geojson <- jsonlite::toJSON(list(type = "Polygon", coordinates = list(x)), auto_unbox = TRUE)
85+
# cent$eval(sprintf("var out = centroid(%s);", geojson))
86+
# cent$get("out.geometry.coordinates")
87+
# }
7788

7889
map_header <- '
7990
<!DOCTYPE html>
@@ -82,8 +93,8 @@ map_header <- '
8293
<meta charset=utf-8 />
8394
<title>spocc WKT Viewer</title>
8495
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
85-
<script src="https://api.tiles.mapbox.com/mapbox.js/v2.2.2/mapbox.js"></script>
86-
<link href="https://api.tiles.mapbox.com/mapbox.js/v2.2.2/mapbox.css" rel="stylesheet" />
96+
<script src="https://api.tiles.mapbox.com/mapbox.js/v3.0.1/mapbox.js"></script>
97+
<link href="https://api.tiles.mapbox.com/mapbox.js/v3.0.1/mapbox.css" rel="stylesheet" />
8798
<style>
8899
body { margin:0; padding:0; }
89100
#map { position:absolute; top:0; bottom:0; width:100%; }

inst/js/LICENSE-terraformer

-7
This file was deleted.

inst/js/LICENSE-turf-centroid.R

-21
This file was deleted.

inst/js/README-terraformer.md

-4
This file was deleted.

0 commit comments

Comments
 (0)