Skip to content

Commit

Permalink
some fixes and template arguments for #38
Browse files Browse the repository at this point in the history
  • Loading branch information
SymbolixAU authored and SymbolixAU committed Apr 3, 2020
1 parent 486c1c2 commit ea8b661
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 34 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Depends: R (>= 3.3.0)
Imports:
Rcpp (>= 0.12.13)
LinkingTo:
Rcpp,
BH,
Rcpp (>= 1.0.4.6),
BH (>= 1.72.0-3),
sfheaders
RoxygenNote: 6.1.0
Suggests:
Expand Down
39 changes: 22 additions & 17 deletions inst/include/googlepolylines/encode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <Rcpp.h>
#include "googlepolylines/googlepolylines.h"

#include "sfheaders/df/sfg.hpp"
//#include "sfheaders/df/sfg.hpp"
#include "sfheaders/sfg/sfg_attributes.hpp"

namespace googlepolylines {
Expand Down Expand Up @@ -37,9 +37,10 @@ namespace encode {
encode_number(os, ui);
}

template < int RTYPE >
inline void encode(
Rcpp::NumericVector& lons,
Rcpp::NumericVector& lats,
Rcpp::Vector< RTYPE >& lons,
Rcpp::Vector< RTYPE >& lats,
std::ostringstream& os
) {
int plat = 0;
Expand All @@ -63,31 +64,33 @@ namespace encode {
}
}

template< int RTYPE >
inline std::string encode(
Rcpp::NumericVector& lons,
Rcpp::NumericVector& lats
Rcpp::Vector< RTYPE >& lons,
Rcpp::Vector< RTYPE >& lats
) {
std::ostringstream os;
encode( lons, lats, os );
// Rcpp::Rcout << "os" << os.str() << std::endl;
return os.str();
}

template< int RTYPE >
inline std::string encode(
Rcpp::NumericMatrix& mat
Rcpp::Matrix< RTYPE >& mat
) {
if( mat.ncol() < 2 ) {
Rcpp::stop("googlepolylines - expecting at least 2 columns in a matrix");
}

Rcpp::NumericVector lons = mat( Rcpp::_, 0 );
Rcpp::NumericVector lats = mat( Rcpp::_, 1 );
Rcpp::Vector< RTYPE > lons = mat( Rcpp::_, 0 );
Rcpp::Vector< RTYPE > lats = mat( Rcpp::_, 1 );
return encode( lons, lats );
}

// encode sfg objects
template< int RTYPE >
inline Rcpp::StringVector encode_point(
Rcpp::NumericVector& sfg
Rcpp::Vector< RTYPE >& sfg
) {

//Rcpp::DataFrame df = sfheaders::df::sfg_to_df(sfg);
Expand All @@ -96,17 +99,18 @@ namespace encode {
if( sfg.length() < 2 ) {
Rcpp::stop("googlepolylines - not enough values in a point");
}
Rcpp::NumericVector lons(1);
Rcpp::NumericVector lats(1);
Rcpp::Vector< RTYPE > lons(1);
Rcpp::Vector< RTYPE > lats(1);
lons[0] = sfg[0];
lats[0] = sfg[1];
Rcpp::StringVector res(1);
res[0] = encode( lons, lats );
return res;
}

template< int RTYPE >
inline Rcpp::StringVector encode_multipoint(
Rcpp::NumericMatrix& sfg
Rcpp::Matrix< RTYPE >& sfg
) {

if( sfg.ncol() < 2 ) {
Expand All @@ -124,17 +128,18 @@ namespace encode {
for( i = 0; i < n; ++i ) {
double lon = sfg( i, 0 );
double lat = sfg( i, 1 );
Rcpp::NumericVector lons(1);
Rcpp::NumericVector lats(1);
Rcpp::Vector< RTYPE > lons(1);
Rcpp::Vector< RTYPE > lats(1);
lons[0] = lon;
lats[0] = lat;
res[i] = encode( lons, lats );
}
return res;
}

template< int RTYPE >
inline Rcpp::StringVector encode_linestring(
Rcpp::NumericMatrix& sfg
Rcpp::Matrix< RTYPE >& sfg
) {

R_xlen_t n = sfg.nrow();
Expand Down Expand Up @@ -221,7 +226,7 @@ namespace encode {
for( i = 0; i < n; ++i ) {

SEXP sfg = sfc[ i ];
cls = sfheaders::df::getSfgClass( sfg );
cls = sfheaders::sfg::getSfgClass( sfg );
geometry = cls[1];

Rcpp::StringVector sv;
Expand Down
12 changes: 6 additions & 6 deletions src/googlePolylines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@ Rcpp::List rcpp_decode_polyline_list(
// a 2-column data.frame?
// probably

size_t n = encodedList.size();
R_xlen_t n = encodedList.size();
Rcpp::List output(n);
Rcpp::CharacterVector sfg_dim;
std::vector<double> pointsLat;
std::vector<double> pointsLon;
std::vector<std::string> col_headers;

for (size_t i = 0; i < n; i++) {
R_xlen_t i;
for( i = 0; i < n; ++i ) {

Rcpp::StringVector polylines = encodedList[i];

sfg_dim = polylines.attr( attribute );
col_headers = get_col_headers(sfg_dim[0]);

size_t pn = polylines.size();
R_xlen_t pn = polylines.size();
Rcpp::List polyline_output(pn);

for (size_t j = 0; j < pn; j++ ) {
for (R_xlen_t j = 0; j < pn; j++ ) {

// If polylines[j] is NA, assign a data frame of NA values
if( Rcpp::StringVector::is_na( polylines[j] ) ) {
Expand Down Expand Up @@ -177,7 +177,7 @@ std::string encode_polyline(){

std::ostringstream os;

for(unsigned int i = 0; i < global_vars::lats.size(); i++){
for(R_xlen_t i = 0; i < global_vars::lats.size(); i++){

late5 = global_vars::lats[i] * 1e5;
lone5 = global_vars::lons[i] * 1e5;
Expand Down
19 changes: 10 additions & 9 deletions src/wkt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,15 @@ void coordSeparateWKT(std::ostringstream& os) {
// [[Rcpp::export]]
Rcpp::StringVector rcpp_polyline_to_wkt(Rcpp::List sfencoded) {

unsigned int nrow = sfencoded.size();
R_xlen_t nrow = sfencoded.size();
Rcpp::StringVector res(nrow);
std::string stdspl;
Rcpp::CharacterVector cls;
Rcpp::StringVector pl;
Rcpp::String spl;

for (size_t i = 0; i < nrow; i++ ){
R_xlen_t i;

for ( i = 0; i < nrow; i++ ){

std::ostringstream os;
stdspl.clear();
Expand All @@ -128,9 +129,9 @@ Rcpp::StringVector rcpp_polyline_to_wkt(Rcpp::List sfencoded) {
}

beginWKT(os, cls);
unsigned int n = pl.size();
R_xlen_t n = pl.size();

for(size_t j = 0; j < n; j ++ ) {
for(R_xlen_t j = 0; j < n; j ++ ) {

spl = pl[j];

Expand Down Expand Up @@ -211,7 +212,7 @@ void ReplaceStringInPlace(std::string& subject, const std::string& search,
* Finds the 'GEOMETRY' text
*/
std::string geomFromWKT(std::string& pl) {
size_t s = pl.find_first_of("(");
R_xlen_t s = pl.find_first_of("(");
std::string geom = pl.substr(0, s);
boost::trim(geom);
// pl.replace(0, s, "");
Expand Down Expand Up @@ -312,16 +313,16 @@ void encode_wkt_multi_polygon(MultiPolygon const& mpl, std::ostringstream& os) {
// [[Rcpp::export]]
Rcpp::List rcpp_wkt_to_polyline(Rcpp::StringVector wkt) {

size_t n = wkt.length();
R_xlen_t n = wkt.length();
Rcpp::String r_wkt;
std::string str_wkt;
std::string geomType;
std::vector<std::string> cls;
Rcpp::CharacterVector sv;

Rcpp::List resultPolylines(n);
int lastItem;
unsigned int i;
R_xlen_t lastItem;
R_xlen_t i;

for (i = 0; i < n; i++ ) {

Expand Down

0 comments on commit ea8b661

Please sign in to comment.