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 1bbaf30 commit d9b33d8
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 145 deletions.
20 changes: 1 addition & 19 deletions inst/include/geojsonsf/geojsonsf.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <Rcpp.h>

// [[Rcpp::depends(rapidjsonr)]]
// [[Rcpp::depends(sfheaders)]]

namespace geojsonsf {
const int EPSG = 4326;
Expand All @@ -12,25 +13,6 @@ namespace geojsonsf {
inline void attach_class( Rcpp::StringVector& geojson ) {
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 "";
// }
}

#define UNKNOWN 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,4 @@ namespace geometrycollection {
} // namespace geometrycollection
} // namespace geojsonsf


// for backwards compability until spatialwidget v0.2 is on CRAN
template< typename Writer >
inline void make_gc_type(Writer& writer, Rcpp::List& sfg,
std::string& geom_type, Rcpp::CharacterVector& cls){
Rcpp::stop("");
};

#endif
12 changes: 7 additions & 5 deletions inst/include/geojsonsf/sf/sf/construct.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
namespace geojsonsf {
namespace sf {

inline Rcpp::List construct_sf( Rcpp::List& lst, std::unordered_set< std::string >& property_keys,
std::unordered_map< std::string, std::string>& property_types,
Document& doc_properties,
int& sfg_objects,
int& row_index ) {
inline Rcpp::List construct_sf(
Rcpp::List& lst, std::unordered_set< std::string >& property_keys,
std::unordered_map< std::string, std::string>& property_types,
Document& doc_properties,
int& sfg_objects,
int& row_index
) {

int n_cols = property_keys.size();
if ( sfg_objects > 0 ) {
Expand Down
5 changes: 4 additions & 1 deletion inst/include/geojsonsf/sf/sfc/geojson_sfc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ namespace sfc {
int sfg_counter = 0;

geojsonsf::sfc::utils::fetch_geometries( sf, sfc_output, sfg_counter );
sfheaders::sfc::attach_sfc_attributes( sfc_output, geom_attr, geometry_types, bbox, z_range, m_range, geojsonsf::EPSG, geojsonsf::PROJ4STRING, nempty );
sfheaders::sfc::attach_sfc_attributes(
sfc_output, geom_attr, geometry_types, bbox, z_range, m_range,
geojsonsf::EPSG, geojsonsf::PROJ4STRING, nempty
);

return sfc_output;
}
Expand Down
102 changes: 5 additions & 97 deletions inst/include/geojsonsf/sf/sfc/utils/sfc_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,101 +12,6 @@ namespace geojsonsf {
namespace sfc {
namespace utils {

// inline Rcpp::NumericVector start_bbox() {
// Rcpp::NumericVector bbox(4); // xmin, ymin, xmax, ymax
// bbox(0) = bbox(1) = bbox(2) = bbox(3) = NA_REAL;
// return bbox;
// }

// inline Rcpp::StringVector start_sfc_classes(size_t collectionCount) {
// Rcpp::StringVector sfc_classes(collectionCount);
// return sfc_classes;
// }

// inline void calculate_bbox(Rcpp::NumericVector& bbox, Rcpp::NumericVector& point) {
// //xmin, ymin, xmax, ymax
// bbox[0] = std::min(point[0], bbox[0]);
// bbox[2] = std::max(point[0], bbox[2]);
//
// bbox[1] = std::min(point[1], bbox[1]);
// bbox[3] = std::max(point[1], bbox[3]);
// }


inline std::string attach_class(
Rcpp::List& sfc,
std::string geom_type,
std::unordered_set< std::string >& geometry_types
) {

std::string geometry_class;

// handle no features
// '{"type":"FeatureCollection","features":[]}'
if (geometry_types.size() == 0 ) {
return "GEOMETRY";
}

if (geom_type == "GEOMETRYCOLLECTION") {
geometry_class = "GEOMETRYCOLLECTION";
} else {

if (geometry_types.size() > 1) {
geometry_class = "GEOMETRY";

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 = sfheaders::getSfClass(sfci);
sfc_classes[i] = cls[1];
}

// attribute::classes
sfc.attr("classes") = sfc_classes;

} else {
std::string type = *geometry_types.begin();
transform(type.begin(), type.end(), type.begin(), toupper);
geometry_class = type;
}
}
return geometry_class;
}

// inline void attach_sfc_attributes(
// Rcpp::List& sfc,
// std::string& type,
// Rcpp::NumericVector& bbox,
// std::unordered_set< std::string >& geometry_types,
// int& nempty
// ) {
//
// std::string geometry_class = attach_class(sfc, type, geometry_types);
// sfc.attr("class") = Rcpp::CharacterVector::create("sfc_" + geometry_class, "sfc");
//
// double prec = 0;
//
// // attribute::crs
// Rcpp::List crs = Rcpp::List::create(
// Rcpp::Named("epsg") = geojsonsf::EPSG,
// Rcpp::Named("proj4string") = geojsonsf::PROJ4STRING
// );
//
// crs.attr("class") = Rcpp::CharacterVector::create("crs");
// sfc.attr("crs") = crs;
//
// // attribute::precision
// sfc.attr("precision") = prec;
//
// // attribute::n_empty
// sfc.attr("n_empty") = nempty;
//
// // attribute::bbox
// bbox.attr("class") = Rcpp::CharacterVector::create("bbox");
// bbox.attr("names") = Rcpp::CharacterVector::create("xmin", "ymin", "xmax", "ymax");
// sfc.attr("bbox") = bbox;
// }

inline Rcpp::List create_null_sfc() {
Rcpp::List empty_sfc(0);

Expand All @@ -116,8 +21,11 @@ namespace utils {
Rcpp::NumericVector m_range = sfheaders::zm::start_m_range();
int n_empty = 0;
std::unordered_set< std::string > geometry_types{"GEOMETRY"};
//attach_sfc_attributes(empty_sfc, type, bbox, z_range, m_range, geometry_types, n_empty);
sfheaders::sfc::attach_sfc_attributes( empty_sfc, type, geometry_types, bbox, z_range, m_range, geojsonsf::EPSG, geojsonsf::PROJ4STRING, n_empty );

sfheaders::sfc::attach_sfc_attributes(
empty_sfc, type, geometry_types, bbox, z_range, m_range,
geojsonsf::EPSG, geojsonsf::PROJ4STRING, n_empty
);
return empty_sfc;
}

Expand Down
6 changes: 0 additions & 6 deletions inst/include/geojsonsf/sf/sfg/geojson_sfg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ using namespace rapidjson;
namespace geojsonsf {
namespace sfg {



// inline Rcpp::CharacterVector sfg_attributes( std::string& dimension, std::string& geom_type ) {
// return Rcpp::CharacterVector::create( dimension, geom_type, "sfg" );
// }

inline double get_lon(const Value& coord_array) {
geojsonsf::validate::validate_point(coord_array[0]);
return coord_array[0].GetDouble();
Expand Down
9 changes: 0 additions & 9 deletions inst/include/geojsonsf/writers/writers.hpp

This file was deleted.

0 comments on commit d9b33d8

Please sign in to comment.