Skip to content

Commit

Permalink
Merge pull request #55 from SymbolixAU/df
Browse files Browse the repository at this point in the history
test and fix for #51
  • Loading branch information
SymbolixAU authored Nov 13, 2018
2 parents ff5d35c + e182d23 commit 0b82d23
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/geojson_sfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,21 @@ void get_integer_points( const Value& point_array, int& n, Rcpp::IntegerVector i
void get_numeric_points( const Value& point_array, int& n, Rcpp::NumericVector nv,
Rcpp::NumericVector& bbox ) {
int i;
if (point_array.Size() == 0 ) {
Rcpp::stop("mis-specified geometry");
}
// if (point_array.Size() < 0 ) {
// Rcpp::stop("mis-specified geometry");
// }

// if ( n < 0 || point_array.Size() == 0 ) {
// Rcpp::stop("mis-specified geometry");
// }

// Rcpp::Rcout << "n: " << n << std::endl;
// Rcpp::Rcout << "points_size: " << point_array.Size() << std::endl;
// const Value& v = point_array[0];
// Rcpp::Rcout << "v.type: " << v.GetType() << std::endl;

for ( i = 0; i < n; i++ ) {
validate_point(point_array[i]);
validate_point(point_array[i]);
nv[i] = point_array[i].GetDouble();
}
calculate_bbox(bbox, nv);
Expand Down Expand Up @@ -140,9 +150,16 @@ void get_line_string( const Value& line_array, Rcpp::NumericVector& bbox, Rcpp::
for( row = 0; row < n; row++ ) {
const Value& coord_array = line_array[ row ];
int n_points = coord_array.Size();

if( n_points <= 1 ) {
Rcpp::stop("mis-specified geometry");
}

if( n_points > max_cols ) {
max_cols = n_points;
}
//Rcpp::Rcout << "n_points: " << n_points << std::endl;

Rcpp::NumericVector nv( 4 ); // initialise with ZM , we remove later
get_numeric_points( coord_array, n_points, nv, bbox );
nm( row, Rcpp::_ ) = nv;
Expand Down
6 changes: 6 additions & 0 deletions src/geojson_validate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ void validate_points(const Value& v) {

void validate_point(const Value& v) {
// TODO(move to header):
// Rcpp::Rcout << "v.size: " << v.Size() << std::endl;
// Rcpp::Rcout << "v.type: " << v.GetType() << std::endl;
// if ( v.Size() < 2 ) {
// Rcpp::stop("mis-specified geometry");
// }

static const char* ARRAY_TYPES[] =
{ "Null", "False", "True", "Object", "Array", "String", "Number" };
if( strncmp(ARRAY_TYPES[v.GetType()], "Num", 3) != 0) {
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-geojson_sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,15 @@ test_that("ints vs numerics read correctly", {

})

test_that("the geoms I test in mapdeck work", {

expect_silent( geojsonsf::geojson_sf('{"type":"Point","coordinates":[0,0]}') )
expect_silent( geojsonsf::geojson_sf('{"type":"MultiPoint","coordinates":[[0,0],[1,1]]}') )
expect_silent( geojsonsf::geojson_sf('{"type":"LineString","coordinates":[[0,0],[1,1]]}') )
expect_silent( geojsonsf::geojson_sf('{"type":"MultiLineString","coordinates":[[[0,0],[1,1]],[[0,0]]]}') )
expect_silent( geojsonsf::geojson_sf('{"type":"Polygon","coordinates":[[[0,0],[0,1],[1,1],[1,0],[0,0]]]}') )
expect_silent( geojsonsf::geojson_sf('{"type":"MultiPolygon","coordinates":[[[[0,0],[0,1],[1,1],[1,0],[0,0]],[[2,2],[2,3],[3,3],[3,2],[2,2]]]]}') )
expect_silent( geojsonsf::geojson_sf('{"type":"MultiPolygon","coordinates":[[[[0,0],[0,1],[1,1],[1,0],[0,0]],[[0,0],[0,-1],[-1,-1],[1,0],[0,0]]]]}') )

})

0 comments on commit 0b82d23

Please sign in to comment.