Skip to content

Commit

Permalink
Merge pull request #24 from SymbolixAU/null2
Browse files Browse the repository at this point in the history
closes #11 and closes #23
  • Loading branch information
SymbolixAU authored May 1, 2018
2 parents 65c566d + 84373ea commit a265a7d
Show file tree
Hide file tree
Showing 17 changed files with 213 additions and 349 deletions.
8 changes: 4 additions & 4 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

rcpp_geojson_to_sfc <- function(geojson, flatten_geometries) {
.Call(`_geojsonsf_rcpp_geojson_to_sfc`, geojson, flatten_geometries)
rcpp_geojson_to_sfc <- function(geojson, expand_geometries) {
.Call(`_geojsonsf_rcpp_geojson_to_sfc`, geojson, expand_geometries)
}

rcpp_geojson_to_sf <- function(geojson, flatten_geometries) {
.Call(`_geojsonsf_rcpp_geojson_to_sf`, geojson, flatten_geometries)
rcpp_geojson_to_sf <- function(geojson, expand_geometries) {
.Call(`_geojsonsf_rcpp_geojson_to_sf`, geojson, expand_geometries)
}

rcpp_geojson_to_wkt <- function(geojson) {
Expand Down
38 changes: 19 additions & 19 deletions R/geojson_sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
#' Extracts geometries from GeoJSON and returns an `sfc` object
#'
#' @param geojson string or vector of GeoJSON, or a URL or file pointing to a geojson file
#' @param flatten_geometries logical indicating whether to unnest GEOMETRYCOLLECTION rows. see details
#' @param expand_geometries logical indicating whether to unnest GEOMETRYCOLLECTION rows. see details
#'
#' @details
#' specifying \code{flatten_geometries = TRUE} will expand individual \code{GEOMETRYCOLLECTION}
#' specifying \code{expand_geometries = TRUE} will expand individual \code{GEOMETRYCOLLECTION}
#' geometries to their own row in the resulting `sf` object. If the geometries are part
#' of a \code{Feature} (i.e., with properties), the properties will be repeated on each row.
#'
#' The \code{GEOMETRYCOLLECTION} information is not kept when using \code{flatten_geometries = TRUE}. Therefore,
#' The \code{GEOMETRYCOLLECTION} information is not kept when using \code{expand_geometries = TRUE}. Therefore,
#' it is not possible to reconstruct the \code{GEOMETRYCOLLECTION} after unnesting it.
#'
#' @examples
Expand All @@ -29,28 +29,28 @@
#' }
#'
#' @export
geojson_sfc <- function(geojson, flatten_geometries = FALSE) UseMethod("geojson_sfc")
geojson_sfc <- function(geojson, expand_geometries = FALSE) UseMethod("geojson_sfc")


#' @export
geojson_sfc.character <- function(geojson, flatten_geometries = FALSE) {
geojson_sfc.character <- function(geojson, expand_geometries = FALSE) {

if(length(geojson) > 1) {
return(rcpp_geojson_to_sfc(geojson, flatten_geometries))
return(rcpp_geojson_to_sfc(geojson, expand_geometries))
}
if (is_url(geojson)) {
return(geojson_sfc(curl::curl(geojson), flatten_geometries))
return(geojson_sfc(curl::curl(geojson), expand_geometries))
} else if (file.exists(geojson) ) {
return(rcpp_read_sfc_file(normalizePath(geojson), flatten_geometries))
return(rcpp_read_sfc_file(normalizePath(geojson), expand_geometries))
}
return(rcpp_geojson_to_sfc(geojson, flatten_geometries))
return(rcpp_geojson_to_sfc(geojson, expand_geometries))
}

#' @export
geojson_sfc.connection <- function(geojson, flatten_geometries = FALSE) geojson_sfc(read_url(geojson), flatten_geometries)
geojson_sfc.connection <- function(geojson, expand_geometries = FALSE) geojson_sfc(read_url(geojson), expand_geometries)

#' @export
geojson_sfc.default <- function(geojson, flatten_geometries = FALSE) rcpp_geojson_to_sfc(geojson, flatten_geometries)
geojson_sfc.default <- function(geojson, expand_geometries = FALSE) rcpp_geojson_to_sfc(geojson, expand_geometries)

#' Geojson to sf
#'
Expand All @@ -74,28 +74,28 @@ geojson_sfc.default <- function(geojson, flatten_geometries = FALSE) rcpp_geojso
#'
#' @inherit geojson_sfc params details
#' @export
geojson_sf <- function(geojson, flatten_geometries = FALSE) UseMethod("geojson_sf")
geojson_sf <- function(geojson, expand_geometries = FALSE) UseMethod("geojson_sf")


#' @export
geojson_sf.character <- function(geojson, flatten_geometries = FALSE) {
geojson_sf.character <- function(geojson, expand_geometries = FALSE) {

if(length(geojson) > 1) {
return(rcpp_geojson_to_sf(geojson, flatten_geometries))
return(rcpp_geojson_to_sf(geojson, expand_geometries))
}
if (is_url(geojson)) {
return(geojson_sf(curl::curl(geojson), flatten_geometries))
return(geojson_sf(curl::curl(geojson), expand_geometries))
} else if (file.exists(geojson) ) {
return(rcpp_read_sf_file(normalizePath(geojson), flatten_geometries))
return(rcpp_read_sf_file(normalizePath(geojson), expand_geometries))
}
return(rcpp_geojson_to_sf(geojson, flatten_geometries))
return(rcpp_geojson_to_sf(geojson, expand_geometries))
}

#' @export
geojson_sf.connection <- function(geojson, flatten_geometries = F) geojson_sf(read_url(geojson), flatten_geometries)
geojson_sf.connection <- function(geojson, expand_geometries = F) geojson_sf(read_url(geojson), expand_geometries)

#' @export
geojson_sf.default <- function(geojson, flatten_geometries = F) rcpp_geojson_to_sf(geojson, flatten_geometries)
geojson_sf.default <- function(geojson, expand_geometries = F) rcpp_geojson_to_sf(geojson, expand_geometries)


## TODO:
Expand Down
1 change: 0 additions & 1 deletion R/scratch.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@

# ## - there needs to handle the case where the `sf` object will have any geometry type.


18 changes: 9 additions & 9 deletions inst/include/geojson_to_sf.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Rcpp::List parse_geometry_collection_object(const Value& val,
Rcpp::NumericVector& bbox,
std::set< std::string >& geometry_types,
int& sfg_objects,
bool& flatten_geometries);
bool& expand_geometries);

Rcpp::List parse_feature_object(const Value& feature,
Rcpp::NumericVector& bbox,
Expand All @@ -27,7 +27,7 @@ Rcpp::List parse_feature_object(const Value& feature,
std::set< std::string >& property_keys,
Document& doc_properties,
std::map< std::string, std::string>& property_types,
bool& flatten_geometries,
bool& expand_geometries,
int& nempty);

Rcpp::List parse_feature_collection_object(const Value& fc,
Expand All @@ -37,7 +37,7 @@ Rcpp::List parse_feature_collection_object(const Value& fc,
std::set< std::string >& property_keys,
Document& doc_properties,
std::map< std::string, std::string>& property_types,
bool& flatten_geometries);
bool& expand_geometries);

void parse_geojson(const Value& v,
Rcpp::List& sfc,
Expand All @@ -49,7 +49,7 @@ void parse_geojson(const Value& v,
std::set< std::string >& property_keys,
Document& doc_properties,
std::map< std::string, std::string>& property_types,
bool& flatten_geometries);
bool& expand_geometries);

void parse_geojson_array(Document& d,
Rcpp::List& sfc,
Expand All @@ -61,7 +61,7 @@ void parse_geojson_array(Document& d,
std::set< std::string >& property_keys,
Document& doc_properties,
std::map< std::string, std::string>& property_types,
bool& flatten_geometries);
bool& expand_geometries);

void parse_geojson_object(Document& d,
Rcpp::List& sfc,
Expand All @@ -72,15 +72,15 @@ void parse_geojson_object(Document& d,
std::set< std::string >& property_keys,
Document& doc_properties,
std::map< std::string, std::string>& property_types,
bool& flatten_geometries);
bool& expand_geometries);

Rcpp::List geojson_to_sf(const char* geojson, Rcpp::NumericVector& bbox,
std::set< std::string >& geometry_types,
int& sfg_objects,
std::set< std::string >& property_keys,
Document& doc_properties,
std::map< std::string, std::string>& property_types,
bool& flatten_geometries);
bool& expand_geometries);

void setup_property_vectors(std::map< std::string, std::string>& property_types,
Rcpp::List& properties, int& sfg_objects);
Expand All @@ -96,8 +96,8 @@ Rcpp::List construct_sf(Rcpp::List& lst, std::set< std::string >& property_keys,
int& sfg_objects,
int& row_index);

Rcpp::List generic_geojson_to_sf(Rcpp::StringVector geojson, bool& flatten_geometries);
Rcpp::List generic_geojson_to_sf(Rcpp::StringVector geojson, bool& expand_geometries);

Rcpp::List create_sfc(Rcpp::StringVector geojson, bool& flatten_geometries);
Rcpp::List create_sfc(Rcpp::StringVector geojson, bool& expand_geometries);

#endif
8 changes: 4 additions & 4 deletions man/geojson_sf.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/geojson_sfc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@
using namespace Rcpp;

// rcpp_geojson_to_sfc
Rcpp::List rcpp_geojson_to_sfc(Rcpp::StringVector geojson, bool& flatten_geometries);
RcppExport SEXP _geojsonsf_rcpp_geojson_to_sfc(SEXP geojsonSEXP, SEXP flatten_geometriesSEXP) {
Rcpp::List rcpp_geojson_to_sfc(Rcpp::StringVector geojson, bool& expand_geometries);
RcppExport SEXP _geojsonsf_rcpp_geojson_to_sfc(SEXP geojsonSEXP, SEXP expand_geometriesSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< Rcpp::StringVector >::type geojson(geojsonSEXP);
Rcpp::traits::input_parameter< bool& >::type flatten_geometries(flatten_geometriesSEXP);
rcpp_result_gen = Rcpp::wrap(rcpp_geojson_to_sfc(geojson, flatten_geometries));
Rcpp::traits::input_parameter< bool& >::type expand_geometries(expand_geometriesSEXP);
rcpp_result_gen = Rcpp::wrap(rcpp_geojson_to_sfc(geojson, expand_geometries));
return rcpp_result_gen;
END_RCPP
}
// rcpp_geojson_to_sf
Rcpp::List rcpp_geojson_to_sf(Rcpp::StringVector geojson, bool flatten_geometries);
RcppExport SEXP _geojsonsf_rcpp_geojson_to_sf(SEXP geojsonSEXP, SEXP flatten_geometriesSEXP) {
Rcpp::List rcpp_geojson_to_sf(Rcpp::StringVector geojson, bool expand_geometries);
RcppExport SEXP _geojsonsf_rcpp_geojson_to_sf(SEXP geojsonSEXP, SEXP expand_geometriesSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< Rcpp::StringVector >::type geojson(geojsonSEXP);
Rcpp::traits::input_parameter< bool >::type flatten_geometries(flatten_geometriesSEXP);
rcpp_result_gen = Rcpp::wrap(rcpp_geojson_to_sf(geojson, flatten_geometries));
Rcpp::traits::input_parameter< bool >::type expand_geometries(expand_geometriesSEXP);
rcpp_result_gen = Rcpp::wrap(rcpp_geojson_to_sf(geojson, expand_geometries));
return rcpp_result_gen;
END_RCPP
}
Expand Down
Loading

0 comments on commit a265a7d

Please sign in to comment.