From 475bd8bf407182b00a7ef97a1419ba519b1bad5e Mon Sep 17 00:00:00 2001 From: tospig Date: Tue, 12 Nov 2019 19:15:04 +1100 Subject: [PATCH] stuff for #40 --- R/spatial_widget.R | 2 +- inst/include/spatialwidget/spatialwidget.hpp | 62 ++++++++++++-------- src/RcppExports.cpp | 2 +- src/widget_point.cpp | 2 +- 4 files changed, 39 insertions(+), 29 deletions(-) diff --git a/R/spatial_widget.R b/R/spatial_widget.R index e093fc6..d53ce7f 100644 --- a/R/spatial_widget.R +++ b/R/spatial_widget.R @@ -194,7 +194,7 @@ widget_point_binary <- function( l[["data_type"]] <- NULL if( tp == "sf" ) { - js_data <- rcpp_widget_point_binary( data, l, c("geometry"), json_legend, digits ) + js_data <- rcpp_widget_point_df_binary( data, l, c("geometry"), json_legend, digits ) } else if (tp == "df" ) { if( is.null( lon ) || is.null( lat ) ) { stop("lon and lat are requried for data.frames") diff --git a/inst/include/spatialwidget/spatialwidget.hpp b/inst/include/spatialwidget/spatialwidget.hpp index f0305d7..6b8ba45 100644 --- a/inst/include/spatialwidget/spatialwidget.hpp +++ b/inst/include/spatialwidget/spatialwidget.hpp @@ -340,7 +340,7 @@ namespace api { * argument is a named list, list(myGeometry = c("lon","lat")), where 'myGeometry' * will be returned inside the 'geometry' object of the GeoJSON */ -inline Rcpp::NumericVector create_binary( +inline Rcpp::List create_binary( Rcpp::DataFrame& data, Rcpp::List& params, Rcpp::List& lst_defaults, @@ -378,7 +378,15 @@ inline Rcpp::NumericVector create_binary( // (oh, taht's right) // - all the mapdeck get* functions shoudl be numeric, thoughh + return lst["data"]; + + // TODO + // construct vectors of positions, colours, and everything else + Rcpp::DataFrame df = Rcpp::as< Rcpp::DataFrame >( lst["data"] ); + + return df; + // // Rcpp::List lst_geometries = df["geometry"]; // @@ -386,33 +394,35 @@ inline Rcpp::NumericVector create_binary( // Rcpp::NumericVector lats = lst_geometries[1]; // - Rcpp::StringVector df_names = df.names(); - Rcpp::Rcout << df_names << std::endl; - - Rcpp::NumericVector lons = df["lon"]; - Rcpp::NumericVector lats = df["lat"]; - //return lons; - - - R_xlen_t n_1 = lons.size(); - R_xlen_t n_2 = lats.size(); - - R_xlen_t n = n_1 + n_2; - - Rcpp::NumericVector binary_res( n ); - - R_xlen_t i; - for( i = 0; i < n_1; i++ ) { - binary_res[i] = lons[i]; - } + // Rcpp::StringVector df_names = df.names(); + // Rcpp::Rcout << df_names << std::endl; + // + // Rcpp::NumericVector lons = df["lon"]; + // Rcpp::NumericVector lats = df["lat"]; + // //return lons; + // + // + // R_xlen_t n_1 = lons.size(); + // R_xlen_t n_2 = lats.size(); + // + // R_xlen_t n = n_1 + n_2; + // + // Rcpp::NumericVector binary_res( n ); + // + // R_xlen_t i; + // for( i = 0; i < n_1; i++ ) { + // binary_res[i] = lons[i]; + // } + // + // int idx = 0; + // for( i = n_1; i < n; i++ ) { + // binary_res[i] = lats[ idx ]; + // idx++; + // } + // + // return binary_res; - int idx = 0; - for( i = n_1; i < n; i++ ) { - binary_res[i] = lats[ idx ]; - idx++; - } - return binary_res; // // Rcpp::StringVector js_data = spatialwidget::geojson::to_geojson_atomise( df, geometry_columns, digits ); // diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 050c034..09774c4 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -342,7 +342,7 @@ BEGIN_RCPP END_RCPP } // rcpp_widget_point_df_binary -Rcpp::NumericVector rcpp_widget_point_df_binary(Rcpp::DataFrame data, Rcpp::List params, Rcpp::List geometries, bool jsonify_legend, int digits); +Rcpp::List rcpp_widget_point_df_binary(Rcpp::DataFrame data, Rcpp::List params, Rcpp::List geometries, bool jsonify_legend, int digits); RcppExport SEXP _spatialwidget_rcpp_widget_point_df_binary(SEXP dataSEXP, SEXP paramsSEXP, SEXP geometriesSEXP, SEXP jsonify_legendSEXP, SEXP digitsSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; diff --git a/src/widget_point.cpp b/src/widget_point.cpp index 3b2c0bf..7e7c8f2 100644 --- a/src/widget_point.cpp +++ b/src/widget_point.cpp @@ -65,7 +65,7 @@ Rcpp::List rcpp_widget_point_df( // [[Rcpp::export]] -Rcpp::NumericVector rcpp_widget_point_df_binary( +Rcpp::List rcpp_widget_point_df_binary( Rcpp::DataFrame data, Rcpp::List params, Rcpp::List geometries,