Skip to content

Commit

Permalink
empty points go to 0,0 - is this correct #32
Browse files Browse the repository at this point in the history
  • Loading branch information
SymbolixAU committed Aug 30, 2018
1 parent 8e91992 commit a64bf39
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 15 deletions.
63 changes: 62 additions & 1 deletion R/scratch.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,87 @@
# ept <- sf::st_sfc(sf::st_point())
# pt <- sf::st_sfc(sf::st_point(c(1,1)))
#
# sfept <- sf::st_sf(geometry = ept)
# sfpt <- sf::st_sf(geometry = pt)
#
# emp <- sf::st_sfc(sf::st_multipoint())
# mp <- sf::st_sfc(sf::st_multipoint(matrix(1:4, ncol = 2)))
#
# sfemp <- sf::st_sf(geometry = emp)
# sfmp <- sf::st_sf(geometry = mp )
#
# el <- sf::st_sfc(sf::st_linestring())
# l <- sf::st_sfc(sf::st_linestring(matrix(1:4, ncol = 2)))
#
# sfel <- sf::st_sf(geometry = el )
# sfl <- sf::st_sf(geometry = l )
#
# eml <- sf::st_sfc(sf::st_multilinestring())
# ml <- sf::st_sfc(sf::st_multilinestring(x = list(matrix(1:4, ncol = 2))))
#
# sfeml <- sf::st_sf(geometry = eml )
# sfml <- sf::st_sf(geometry = ml )
#
# epl <- sf::st_sfc(sf::st_polygon())
# pl <- sf::st_sfc(sf::st_multipolygon(x = list(sf::st_polygon(list(x = matrix(c(0,0,1,0,1,1,0,1,0,0), ncol = 2, byrow = T))))))
# pl <- sf::st_sfc(sf::st_polygon(list(x = matrix(c(0,0,1,0,1,1,0,1,0,0), ncol = 2, byrow = T))))
#
# sfepl <- sf::st_sf(geometry = epl)
# sfpl <- sf::st_sf(geometry = pl)
#
# empl <- sf::st_sfc(sf::st_multipolygon())
# mpl <- sf::st_sfc(sf::st_multipolygon(x = list(sf::st_polygon(list(x = matrix(c(0,0,1,0,1,1,0,1,0,0), ncol = 2, byrow = T))))))
#
# sfempl <- sf::st_sf(geometry = empl)
# sfmpl <- sf::st_sf(geometry = mpl)
#
#
#
# encode(ept)
# encode(pt)
#
# encode(sfept)
# encode(sfpt)
#
# encode(emp)
# encode(mp)
#
# encode( sfemp )
# encode( sfmp )
#
# encode(el)
# encode(l)
#
# encode( sfel )
# encode( sfl )
#
# encode(eml)
# encode(ml)
#
# encode( sfeml )
# encode( sfml )
#
# encode(epl)
# encode(pl)
#
# encode( sfepl )
# encode( sfpl )
#
# encode(empl)
# encode(mpl)
#
# encode( sfempl )
# encode( sfmpl )
#
#
# library(googleway)
# set_key(read.dcf("~/Documents/.googleAPI", fields = "GOOGLE_MAP_KEY"))
#
# google_map() %>%
# add_markers(sfemp)
#
# google_map() %>%
# add_polylines(data = sfel)
#
# google_map() %>%
# add_polylines(data = sfeml)
#
21 changes: 14 additions & 7 deletions R/sfencoded.R
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,24 @@ printSfEncodedPrefix <- function(e, encType) {

if(encType == "sfencoded") {
e <- vapply(e, function(z) {
paste0(
attr(z, "sfc")[2], ": ",
substr(z[1], 1, pmin(nchar(z[1]), 20)),
"..."
m <- pmin(nchar(z[1]), 20)
a <- attr(z, "sfc")[2]
ifelse(is.na(m), paste0(a, ": EMPTY"),
paste0(
a, ": ",
substr(z[1], 1, m)
, ifelse(m >= 20, "...", "")
)
)
}, "" )
} else {
e <- vapply(e, function(z) {
paste0(
substr(z[1], 1, pmin(nchar(z[1]), 20)),
"..."
m <- pmin(nchar(z[1]), 20)
ifelse(is.na(m), "EMPTY",
paste0(
substr(z[1], 1, m),
ifelse(m >= 20, "...", "")
)
)
}, "" )
}
Expand Down
16 changes: 9 additions & 7 deletions src/encode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,14 @@ void write_data(std::ostringstream& os, std::ostringstream& oszm, Rcpp::Characte
Rcpp::List rcpp_encodeSfGeometry(Rcpp::List sfc, bool strip){

Rcpp::CharacterVector cls_attr = sfc.attr("class");

int db = 0;


Rcpp::CharacterVector sfg_dim;
int dim_divisor;

Rcpp::List output(sfc.size());
Rcpp::List output_zm(sfc.size());
int lastItem;
Rcpp::List thisSfc;

// TODO(empty geometries should not enter this list and return something?)

Expand All @@ -317,11 +316,14 @@ Rcpp::List rcpp_encodeSfGeometry(Rcpp::List sfc, bool strip){
Rcpp::checkUserInterrupt();

sfg_dim = getSfClass(sfc[i]);

make_dim_divisor(sfg_dim[0], &dim_divisor);
thisSfc = sfc[i];

if (thisSfc.size() > 0 ) {

write_data(os, oszm, sfg_dim, dim_divisor, sfc[i], cls_attr[0], 0);

make_dim_divisor(sfg_dim[0], &dim_divisor);

write_data(os, oszm, sfg_dim, dim_divisor, sfc[i], cls_attr[0], 0);
}

std::string str = os.str();
// std::string zmstr = oszm.str();
Expand Down

0 comments on commit a64bf39

Please sign in to comment.