Skip to content

Commit

Permalink
stuff for #40
Browse files Browse the repository at this point in the history
  • Loading branch information
dcooley committed Nov 12, 2019
1 parent 58e46e2 commit 475bd8b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 29 deletions.
2 changes: 1 addition & 1 deletion R/spatial_widget.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
62 changes: 36 additions & 26 deletions inst/include/spatialwidget/spatialwidget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -378,41 +378,51 @@ 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"];
//
// Rcpp::NumericVector lons = lst_geometries[0];
// 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 );
//
Expand Down
2 changes: 1 addition & 1 deletion src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/widget_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 475bd8b

Please sign in to comment.