diff --git a/src/geojson_sfg.cpp b/src/geojson_sfg.cpp index 27399c0..dcb13e7 100644 --- a/src/geojson_sfg.cpp +++ b/src/geojson_sfg.cpp @@ -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); @@ -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; diff --git a/src/geojson_validate.cpp b/src/geojson_validate.cpp index 65ff6e2..3d67d3e 100644 --- a/src/geojson_validate.cpp +++ b/src/geojson_validate.cpp @@ -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) { diff --git a/tests/testthat/test-geojson_sf.R b/tests/testthat/test-geojson_sf.R index 704afd8..3af024f 100644 --- a/tests/testthat/test-geojson_sf.R +++ b/tests/testthat/test-geojson_sf.R @@ -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]]]]}') ) + +}) +