Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroen committed Oct 8, 2019
1 parent 3bd82e9 commit 007e4a8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion R/mapbox.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ mvt_sf_point <- function(mat){
}

mvt_sf_linestring <- function(mat){
if(length(unique(mat[,3])) == 1){
if(all_equal(mat[,3])){
sf::st_linestring(mat[,1:2])
} else {
sf::st_multilinestring(split_matrix_groups(mat))
Expand All @@ -106,9 +106,14 @@ mvt_sf_linestring <- function(mat){

#FIXME: calculate winding order to detect MULTIPOLYGONS
mvt_sf_polygon <- function(mat){
# if(!all_equal(mat[,3])) browser()
sf::st_polygon(split_matrix_groups(mat))
}

all_equal <- function(x){
length(unique(x)) == 1L
}

split_matrix_groups <- function(mat){
groups <- unname(split(mat[,1:2], mat[,3]))
lapply(groups, matrix, ncol = 2)
Expand Down

0 comments on commit 007e4a8

Please sign in to comment.