Skip to content

Commit

Permalink
more sfheaders for #68
Browse files Browse the repository at this point in the history
  • Loading branch information
SymbolixAU committed Sep 11, 2019
1 parent 7c60e01 commit 1bbaf30
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 145 deletions.
9 changes: 5 additions & 4 deletions inst/include/geojsonsf/geojson/api/df_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 );
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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

Expand Down
19 changes: 11 additions & 8 deletions inst/include/geojsonsf/geojson/write_geometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
36 changes: 18 additions & 18 deletions inst/include/geojsonsf/geojsonsf.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ namespace geojsonsf {
geojson.attr("class") = Rcpp::CharacterVector::create("geojson","json");
}

template <int RTYPE>
inline Rcpp::CharacterVector sfClass(Rcpp::Vector<RTYPE> v) {
return v.attr("class");
}

inline Rcpp::CharacterVector getSfClass(SEXP sf) {

switch( TYPEOF(sf) ) {
case REALSXP:
return sfClass<REALSXP>(sf);
case VECSXP:
return sfClass<VECSXP>(sf);
case INTSXP:
return sfClass<INTSXP>(sf);
default: Rcpp::stop("unknown sf type");
}
return "";
}
// template <int RTYPE>
// inline Rcpp::CharacterVector sfClass(Rcpp::Vector<RTYPE> v) {
// return v.attr("class");
// }
//
// inline Rcpp::CharacterVector getSfClass(SEXP sf) {
//
// switch( TYPEOF(sf) ) {
// case REALSXP:
// return sfClass<REALSXP>(sf);
// case VECSXP:
// return sfClass<VECSXP>(sf);
// case INTSXP:
// return sfClass<INTSXP>(sf);
// default: Rcpp::stop("unknown sf type");
// }
// return "";
// }
}

#define UNKNOWN 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#define GEOJSONSF_GEOMETRYCOLLECTION_H

#include <Rcpp.h>
#include "geojsonsf/utils/utils.hpp"

#include "sfheaders/utils/utils.hpp"

namespace geojsonsf {
namespace geometrycollection {
Expand All @@ -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);
}
Expand All @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion inst/include/geojsonsf/sf/sfc/utils/sfc_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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];
}

Expand Down
2 changes: 0 additions & 2 deletions inst/include/geojsonsf/sf/sfg/geojson_sfg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
64 changes: 0 additions & 64 deletions inst/include/geojsonsf/utils/utils.hpp

This file was deleted.

45 changes: 0 additions & 45 deletions inst/include/geojsonsf/utils/where/where.hpp

This file was deleted.

0 comments on commit 1bbaf30

Please sign in to comment.