diff --git a/inst/include/geojsonsf/geojson/api/df_api.hpp b/inst/include/geojsonsf/geojson/api/df_api.hpp index 60fcc08..5e6bb64 100644 --- a/inst/include/geojsonsf/geojson/api/df_api.hpp +++ b/inst/include/geojsonsf/geojson/api/df_api.hpp @@ -5,10 +5,10 @@ #include "jsonify/to_json/writers/simple.hpp" #include "geojsonsf/geojsonsf.h" -#include "geojsonsf/utils/where/where.hpp" #include "geojsonsf/geojson/write_geometry.hpp" #include "sfheaders/sfg/sfg_dimension.hpp" +#include "sfheaders/utils/vectors/vectors.hpp" namespace geojsonsf { namespace api { @@ -17,7 +17,8 @@ namespace api { Rcpp::DataFrame& df, Rcpp::StringVector& geometry_columns, int& digits, - bool& factors_as_string ) { + bool& factors_as_string + ) { rapidjson::StringBuffer sb; rapidjson::Writer < rapidjson::StringBuffer > writer( sb ); @@ -47,7 +48,7 @@ namespace api { for ( i = 0; i < df.length(); i++ ) { Rcpp::String this_column = column_names[i]; - int idx = geojsonsf::utils::where::where_is( this_column, geometry_columns ); + int idx = sfheaders::utils::where_is( this_column, geometry_columns ); if ( idx == -1 ) { // i.e. it's not in the vector property_names[property_counter] = column_names[i]; @@ -131,7 +132,7 @@ namespace api { for ( i = 0; i < df.length(); i++) { Rcpp::String this_column = column_names[i]; - int idx = geojsonsf::utils::where::where_is( this_column, geometry_columns ); + int idx = sfheaders::utils::where_is( this_column, geometry_columns ); if ( idx == -1 ) { // i.e. it's not in the vector diff --git a/inst/include/geojsonsf/geojson/write_geometry.hpp b/inst/include/geojsonsf/geojson/write_geometry.hpp index fd48ac1..2eb7a2a 100644 --- a/inst/include/geojsonsf/geojson/write_geometry.hpp +++ b/inst/include/geojsonsf/geojson/write_geometry.hpp @@ -4,7 +4,10 @@ #include "geojsonsf/geojsonsf.h" #include "geojsonsf/geojson/writers/writers.hpp" #include "geojsonsf/write_geojson.hpp" -#include "geojsonsf/utils/utils.hpp" + +#include "sfheaders/sfheaders.hpp" +#include "sfheaders/utils/utils.hpp" +#include "sfheaders/utils/sexp/sexp.hpp" namespace geojsonsf { namespace write_geometry { @@ -27,13 +30,13 @@ namespace write_geometry { std::string geom_type; geom_type = cls[1]; - int sfglength = geojsonsf::utils::get_sexp_length( sfg ); + int sfglength = sfheaders::utils::get_sexp_length( sfg ); if (sfglength == 0) { writer.Null(); } else { - bool isnull = geojsonsf::utils::is_null_geometry( sfg, geom_type ); + bool isnull = sfheaders::utils::is_null_geometry( sfg, geom_type ); if ( isnull ) { writer.Null(); } else { @@ -56,20 +59,20 @@ namespace write_geometry { SEXP sfg = sfc[ sfg_index ]; std::string geom_type; - Rcpp::CharacterVector cls = geojsonsf::getSfClass(sfg); + Rcpp::CharacterVector cls = sfheaders::getSfClass(sfg); cls_check( cls ); geom_type = cls[1]; // need to keep track of GEOMETRYCOLLECTIONs so we can correctly close them bool isGeometryCollection = (geom_type == "GEOMETRYCOLLECTION") ? true : false; - int sfglength = geojsonsf::utils::get_sexp_length( sfg ); + int sfglength = sfheaders::utils::get_sexp_length( sfg ); if (sfglength == 0) { writer.Null(); } else { - bool isnull = geojsonsf::utils::is_null_geometry( sfg, geom_type ); + bool isnull = sfheaders::utils::is_null_geometry( sfg, geom_type ); if ( isnull ) { writer.Null(); } else { @@ -106,13 +109,13 @@ namespace write_geometry { // need to keep track of GEOMETRYCOLLECTIONs so we can correctly close them bool isGeometryCollection = (geom_type == "GEOMETRYCOLLECTION") ? true : false; - int sfglength = geojsonsf::utils::get_sexp_length( sfg ); + int sfglength = sfheaders::utils::get_sexp_length( sfg ); if (sfglength == 0) { writer.Null(); } else { - bool isnull = geojsonsf::utils::is_null_geometry( sfg, geom_type ); + bool isnull = sfheaders::utils::is_null_geometry( sfg, geom_type ); if ( isnull ) { writer.Null(); } else { diff --git a/inst/include/geojsonsf/geojsonsf.h b/inst/include/geojsonsf/geojsonsf.h index f366788..f205617 100644 --- a/inst/include/geojsonsf/geojsonsf.h +++ b/inst/include/geojsonsf/geojsonsf.h @@ -13,24 +13,24 @@ namespace geojsonsf { geojson.attr("class") = Rcpp::CharacterVector::create("geojson","json"); } - template - inline Rcpp::CharacterVector sfClass(Rcpp::Vector v) { - return v.attr("class"); - } - - inline Rcpp::CharacterVector getSfClass(SEXP sf) { - - switch( TYPEOF(sf) ) { - case REALSXP: - return sfClass(sf); - case VECSXP: - return sfClass(sf); - case INTSXP: - return sfClass(sf); - default: Rcpp::stop("unknown sf type"); - } - return ""; - } + // template + // inline Rcpp::CharacterVector sfClass(Rcpp::Vector v) { + // return v.attr("class"); + // } + // + // inline Rcpp::CharacterVector getSfClass(SEXP sf) { + // + // switch( TYPEOF(sf) ) { + // case REALSXP: + // return sfClass(sf); + // case VECSXP: + // return sfClass(sf); + // case INTSXP: + // return sfClass(sf); + // default: Rcpp::stop("unknown sf type"); + // } + // return ""; + // } } #define UNKNOWN 0 diff --git a/inst/include/geojsonsf/geometrycollection/geometrycollection.hpp b/inst/include/geojsonsf/geometrycollection/geometrycollection.hpp index db29865..388da77 100644 --- a/inst/include/geojsonsf/geometrycollection/geometrycollection.hpp +++ b/inst/include/geojsonsf/geometrycollection/geometrycollection.hpp @@ -2,8 +2,8 @@ #define GEOJSONSF_GEOMETRYCOLLECTION_H #include -#include "geojsonsf/utils/utils.hpp" +#include "sfheaders/utils/utils.hpp" namespace geojsonsf { namespace geometrycollection { @@ -22,7 +22,7 @@ namespace geometrycollection { gc_geom_type = cls[1]; SEXP tst = *it; - isnull = geojsonsf::utils::is_null_geometry( tst, gc_geom_type ); + isnull = sfheaders::utils::is_null_geometry( tst, gc_geom_type ); } else { gc_type(tmp, gc_geom_type, isnull, cls); } @@ -36,7 +36,7 @@ namespace geometrycollection { gc_geom_type = cls[1]; SEXP tst = *it; - isnull = geojsonsf::utils::is_null_geometry( tst, gc_geom_type ); + isnull = sfheaders::utils::is_null_geometry( tst, gc_geom_type ); } break; } diff --git a/inst/include/geojsonsf/sf/sfc/utils/sfc_utils.hpp b/inst/include/geojsonsf/sf/sfc/utils/sfc_utils.hpp index d5ea52d..53c0950 100644 --- a/inst/include/geojsonsf/sf/sfc/utils/sfc_utils.hpp +++ b/inst/include/geojsonsf/sf/sfc/utils/sfc_utils.hpp @@ -3,6 +3,7 @@ #include "geojsonsf/geojsonsf.h" +#include "sfheaders/sfheaders.hpp" #include "sfheaders/sfc/sfc_attributes.hpp" #include "sfheaders/sfc/bbox.hpp" #include "sfheaders/sfc/zm_range.hpp" @@ -56,7 +57,7 @@ namespace utils { Rcpp::StringVector sfc_classes = sfheaders::sfc::start_sfc_classes( sfc.size() ); for (int i = 0; i < sfc.size(); i++) { SEXP sfci = sfc[i]; - Rcpp::CharacterVector cls = geojsonsf::getSfClass(sfci); + Rcpp::CharacterVector cls = sfheaders::getSfClass(sfci); sfc_classes[i] = cls[1]; } diff --git a/inst/include/geojsonsf/sf/sfg/geojson_sfg.hpp b/inst/include/geojsonsf/sf/sfg/geojson_sfg.hpp index d79f7fa..0739d0d 100644 --- a/inst/include/geojsonsf/sf/sfg/geojson_sfg.hpp +++ b/inst/include/geojsonsf/sf/sfg/geojson_sfg.hpp @@ -6,8 +6,6 @@ #include "rapidjson/document.h" #include "geojsonsf/sf/sfc/geojson_sfc.hpp" #include "geojsonsf/geojson/geojson_validate.hpp" -#include "geojsonsf/utils/utils.hpp" -#include "geojsonsf/utils/where/where.hpp" #include "sfheaders/sfc/bbox.hpp" #include "sfheaders/sfc/zm_range.hpp" diff --git a/inst/include/geojsonsf/utils/utils.hpp b/inst/include/geojsonsf/utils/utils.hpp deleted file mode 100644 index 3d799ce..0000000 --- a/inst/include/geojsonsf/utils/utils.hpp +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef GEOJSONSF_UTILS_H -#define GEOJSONSF_UTILS_H - -#include - -namespace geojsonsf { -namespace utils { - - template - inline int sexp_length(Rcpp::Vector v) { - return v.length(); - } - - inline int get_sexp_length( SEXP s ) { - switch( TYPEOF(s) ) { - case REALSXP: - return sexp_length< REALSXP >( s ); - case VECSXP: - return sexp_length< VECSXP >( s ); - case INTSXP: - return sexp_length< INTSXP >( s ); - default: Rcpp::stop("unknown sf type"); - } - return 0; - } - - inline bool is_null_geometry( SEXP& sfg, std::string& geom_type ) { - int n = get_sexp_length( sfg ); - if( geom_type == "POINT" ) { - Rcpp::NumericVector nv = Rcpp::as< Rcpp::NumericVector >( sfg ); - if (ISNAN( nv[0] ) ) { - return true; - } - } else if ( n == 0 ) { - return true; - } - return false; - } - - // inline std::string make_dimension( int n ) { - // switch( n ) { - // case 2: { - // return "XY"; - // break; - // } - // case 3: { - // return "XYZ"; - // break; - // } - // case 4: { - // return "XYZM"; - // break; - // } - // default: { - // Rcpp::stop("unknown dimension attribute"); - // } - // } - // return "XY"; // never reached - // } - -} // namespace utils -} // namespace geojsonsf - -#endif diff --git a/inst/include/geojsonsf/utils/where/where.hpp b/inst/include/geojsonsf/utils/where/where.hpp deleted file mode 100644 index bb2f0ac..0000000 --- a/inst/include/geojsonsf/utils/where/where.hpp +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef GEOJSONSF_UTILS_WHERE_H -#define GEOJSONSF_UTILS_WHERE_H - -#include - -namespace geojsonsf { -namespace utils { -namespace where { - - /* - * find_parameter_index_in_vector - * Finds the location (index) of a string in the list of parameters (as given by the R function call) - */ - inline int where_is( - Rcpp::String to_find, - Rcpp::StringVector& sv ) { - int n = sv.size(); - int i; - for( i = 0; i < n; i++ ) { - if ( to_find == sv[i] ) { - return i; - } - } - return -1; - } - - inline Rcpp::IntegerVector where_is( - Rcpp::StringVector& param_value, - Rcpp::StringVector& data_names) { - - int n = param_value.size(); - int i; - Rcpp::IntegerVector res( n ); - for ( i = 0; i < n; i++ ) { - Rcpp::String to_find = param_value[i]; - res[i] = where_is( to_find, data_names ); - } - return res; - } - -} // namespace where -} // namespace utils -} // namespace spatialwidget - -#endif