dcooley / sfheaders

Compare a2be9d9 ... +5 ... 741d2c7

Coverage Reach
inst/include/sfheaders/sfc/linestring/sfc_linestring.hpp inst/include/sfheaders/sfc/linestring/sfc_linestrings.hpp inst/include/sfheaders/sfc/multipoint/sfc_multipoint.hpp inst/include/sfheaders/sfc/multipoint/sfc_multipoints.hpp inst/include/sfheaders/sfc/polygon/sfc_polygon.hpp inst/include/sfheaders/sfc/polygon/sfc_polygons.hpp inst/include/sfheaders/sfc/multipolygon/sfc_multipolygon.hpp inst/include/sfheaders/sfc/multipolygon/sfc_multipolygons.hpp inst/include/sfheaders/sfc/bbox.hpp inst/include/sfheaders/sfc/multilinestring/sfc_multilinestring.hpp inst/include/sfheaders/sfc/multilinestring/sfc_multilinestrings.hpp inst/include/sfheaders/sfc/point/sfc_point.hpp inst/include/sfheaders/sfc/point/sfc_points.hpp inst/include/sfheaders/sfc/m_range.hpp inst/include/sfheaders/sfc/z_range.hpp inst/include/sfheaders/sfc/sfc_attributes.hpp inst/include/sfheaders/sfc/sfc_types.hpp inst/include/sfheaders/sfc/zm_range.hpp inst/include/sfheaders/sfg/polygon/sfg_polygon.hpp inst/include/sfheaders/sfg/polygon/close_polygon.hpp inst/include/sfheaders/sfg/polygon/sfg_polygons.hpp inst/include/sfheaders/sfg/multilinestring/sfg_multilinestring.hpp inst/include/sfheaders/sfg/multilinestring/sfg_multilinestrings.hpp inst/include/sfheaders/sfg/multipolygon/sfg_multipolygon.hpp inst/include/sfheaders/sfg/multipolygon/sfg_multipolygons.hpp inst/include/sfheaders/sfg/multipoint/sfg_multipoint.hpp inst/include/sfheaders/sfg/multipoint/sfg_multipoints.hpp inst/include/sfheaders/sfg/linestring/sfg_linestring.hpp inst/include/sfheaders/sfg/linestring/sfg_linestrings.hpp inst/include/sfheaders/sfg/point/sfg_point.hpp inst/include/sfheaders/sfg/point/sfg_points.hpp inst/include/sfheaders/sfg/sfg_types.hpp inst/include/sfheaders/sfg/sfg_dimension.hpp inst/include/sfheaders/sfg/sfg_attributes.hpp inst/include/sfheaders/sf/multipolygon/sf_multipolygon.hpp inst/include/sfheaders/sf/polygon/sf_polygon.hpp inst/include/sfheaders/sf/multilinestring/sf_multilinestring.hpp inst/include/sfheaders/sf/sf_utils.hpp inst/include/sfheaders/sf/multipoint/sf_multipoint.hpp inst/include/sfheaders/sf/linestring/sf_linestring.hpp inst/include/sfheaders/sf/point/sf_point.hpp inst/include/sfheaders/sf/sf.hpp inst/include/sfheaders/utils/columns/columns.hpp inst/include/sfheaders/utils/lists/list.hpp inst/include/sfheaders/utils/vectors/vectors.hpp inst/include/sfheaders/utils/lines/lines.hpp inst/include/sfheaders/utils/unique/unique_ids.hpp inst/include/sfheaders/utils/unique/unique_sort.hpp inst/include/sfheaders/utils/utils.hpp inst/include/sfheaders/utils/subset/subset.hpp inst/include/sfheaders/df/sfg.hpp inst/include/sfheaders/df/sfc.hpp inst/include/sfheaders/df/sf.hpp inst/include/sfheaders/df/utils.hpp inst/include/sfheaders/cast/sfg.hpp inst/include/sfheaders/cast/sfc.hpp inst/include/sfheaders/cast/sf.hpp R/sf.R R/sf_helpers.R R/utils.R R/sfc.R R/sfg.R R/df.R R/cast.R src/to_sfc.cpp src/to_sfg.cpp src/lists.cpp src/utils.cpp src/to_sf.cpp src/bbox.cpp src/cast.cpp src/to_df.cpp src/shapes.cpp src/sfg_dimension.cpp

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.


@@ -26,6 +26,77 @@
Loading
26 26
namespace sfheaders {
27 27
namespace df {
28 28
29 +
  inline void dim_error() { // #nocov
30 +
    Rcpp::stop("sfheaders - unknown geometry dimension");    // #nocov
31 +
  }
32 +
33 +
  inline Rcpp::IntegerVector get_sfg_cols( R_xlen_t& n_col, int geometry, std::string& dim ) {
34 +
35 +
    switch( geometry ) {
36 +
    case sfheaders::sfg::SFG_POINT: {}
37 +
    case sfheaders::sfg::SFG_MULTIPOINT: {}
38 +
    case sfheaders::sfg::SFG_LINESTRING: {
39 +
      if( dim == "XY" ) {
40 +
      return Rcpp::IntegerVector({ X_COLUMN, Y_COLUMN });
41 +
    } else if( dim == "XYZM" ) {
42 +
      return Rcpp::IntegerVector({ X_COLUMN, Y_COLUMN, Z_COLUMN, M_COLUMN });
43 +
    } else if ( dim == "XYZ" ) {
44 +
      return Rcpp::IntegerVector({ X_COLUMN, Y_COLUMN, Z_COLUMN });
45 +
    } else if ( dim == "XYM" ) {
46 +
      return Rcpp::IntegerVector({ X_COLUMN, Y_COLUMN, M_COLUMN });
47 +
    } else {
48 +
      dim_error();  // #nocov
49 +
    }
50 +
    }
51 +
    case sfheaders::sfg::SFG_MULTILINESTRING: {}
52 +
    case sfheaders::sfg::SFG_POLYGON: {
53 +
      if( dim == "XY" ) {
54 +
      return Rcpp::IntegerVector({ LINESTRING_COLUMN, X_COLUMN, Y_COLUMN });
55 +
    } else if( dim == "XYZM" ) {
56 +
      return Rcpp::IntegerVector({ LINESTRING_COLUMN, X_COLUMN, Y_COLUMN, Z_COLUMN, M_COLUMN });
57 +
    } else if ( dim == "XYZ" ) {
58 +
      return Rcpp::IntegerVector({ LINESTRING_COLUMN, X_COLUMN, Y_COLUMN, Z_COLUMN });
59 +
    } else if ( dim == "XYM" ) {
60 +
      return Rcpp::IntegerVector({ LINESTRING_COLUMN, X_COLUMN, Y_COLUMN, M_COLUMN });
61 +
    } else {
62 +
      dim_error();  // #nocov
63 +
    }
64 +
    }
65 +
    case sfheaders::sfg::SFG_MULTIPOLYGON: {
66 +
      if( dim == "XY" ) {
67 +
      return Rcpp::IntegerVector({ POLYGON_COLUMN, LINESTRING_COLUMN, X_COLUMN, Y_COLUMN });
68 +
    } else if( dim == "XYZM" ) {
69 +
      return Rcpp::IntegerVector({ POLYGON_COLUMN, LINESTRING_COLUMN, X_COLUMN, Y_COLUMN, Z_COLUMN, M_COLUMN });
70 +
    } else if ( dim == "XYZ" ) {
71 +
      return Rcpp::IntegerVector({ POLYGON_COLUMN, LINESTRING_COLUMN, X_COLUMN, Y_COLUMN, Z_COLUMN });
72 +
    } else if ( dim == "XYM" ) {
73 +
      return Rcpp::IntegerVector({ POLYGON_COLUMN, LINESTRING_COLUMN, X_COLUMN, Y_COLUMN, M_COLUMN });
74 +
    } else {
75 +
      dim_error(); // #nocov
76 +
    }
77 +
    }
78 +
    case sfheaders::sfg::SFG_GEOMETRYCOLLECTION: {
79 +
      if( dim == "XY" ) {
80 +
      return Rcpp::IntegerVector({ MULTIPOLYGON_COLUMN, POLYGON_COLUMN, LINESTRING_COLUMN, X_COLUMN, Y_COLUMN });
81 +
    } else if( dim == "XYZM" ) {
82 +
      return Rcpp::IntegerVector({ MULTIPOLYGON_COLUMN, POLYGON_COLUMN, LINESTRING_COLUMN, X_COLUMN, Y_COLUMN, Z_COLUMN, M_COLUMN });
83 +
    } else if ( dim == "XYZ" ) {
84 +
      return Rcpp::IntegerVector({ MULTIPOLYGON_COLUMN, POLYGON_COLUMN, LINESTRING_COLUMN, X_COLUMN, Y_COLUMN, Z_COLUMN });
85 +
    } else if ( dim == "XYM" ) {  // #nocov
86 +
      return Rcpp::IntegerVector({ MULTIPOLYGON_COLUMN, POLYGON_COLUMN, LINESTRING_COLUMN, X_COLUMN, Y_COLUMN, M_COLUMN });  // #nocov
87 +
    } else {
88 +
      dim_error(); // #nocov
89 +
    }
90 +
91 +
    }
92 +
    default: {
93 +
      Rcpp::stop("sfheaders - unknown geometry type");  // #nocov
94 +
    }
95 +
    }
96 +
97 +
    return Rcpp::IntegerVector(); // #nocov never reached
98 +
  }
99 +
29 100
  const Rcpp::CharacterVector column_names = {
30 101
    "sfc_id", "sfg_id", "geometrycollection_id", "multipolygon_id", "polygon_id", "multilinestring_id",
31 102
    "linestring_id", "multipoint_id", "point_id", "x","y","z","m"
@@ -67,6 +138,8 @@
Loading
67 138
    } else if ( geometry == "MULTIPOLYGON" ) {
68 139
      columns[ LINESTRING_COLUMN ] = true;
69 140
      columns[ POLYGON_COLUMN ] = true;
141 +
    // } else if ( geometry == "GEOMETRYCOLLECTION" ) {
142 +
    //   columns[ GEOMETRYCOLLECTION_COLUMN ] = true;
70 143
    }
71 144
    return column_names[ columns ];
72 145
  }
@@ -373,7 +446,126 @@
Loading
373 446
    return res;
374 447
  }
375 448
376 -
  inline Rcpp::List sfg_to_df( SEXP& sfg ) {
449 +
  inline Rcpp::List sfg_geometrycollection_coordinates( Rcpp::List& sfg, R_xlen_t& sfg_rows ) {
450 +
451 +
    R_xlen_t n_sfgs = sfg.size();
452 +
    R_xlen_t i;
453 +
    Rcpp::List res( n_sfgs );
454 +
455 +
    R_xlen_t total_rows = 0;
456 +
457 +
    // need to fill res(),
458 +
    // then collapse it...
459 +
    // but it will be filled like an 'sfc' - a collection of geometries.
460 +
    // ...
461 +
    // to collapse_list, each list element must have the same number of columns
462 +
    // so do I initialise all of them?
463 +
464 +
    for( i = 0; i < n_sfgs; ++i ) {
465 +
466 +
      SEXP s = sfg[ i ];
467 +
      Rcpp::CharacterVector cls = sfheaders::utils::getSfgClass( s );
468 +
      std::string geometry;
469 +
      geometry = cls[1];
470 +
      int sfg_type = sfheaders::sfg::get_sfg_type( geometry );
471 +
472 +
      Rcpp::Rcout << "geometry: " << geometry << ", " << sfg_type << std::endl;
473 +
474 +
      switch( sfg_type ) {
475 +
      case sfheaders::sfg::SFG_POINT: {
476 +
        Rcpp::NumericVector vec = Rcpp::as< Rcpp::NumericVector >( s );
477 +
        res[i] = sfheaders::df::sfg_point_coordinates( vec, sfg_rows );
478 +
        break;
479 +
      }
480 +
      case sfheaders::sfg::SFG_MULTIPOINT: {
481 +
        Rcpp::NumericMatrix mat = Rcpp::as< Rcpp::NumericMatrix >( s );
482 +
        Rcpp::Rcout << mat << std::endl;
483 +
        res[i] = sfheaders::df::sfg_multipoint_coordinates( mat, sfg_rows );
484 +
        break;
485 +
      }
486 +
      case sfheaders::sfg::SFG_LINESTRING: {
487 +
        Rcpp::NumericMatrix mat = Rcpp::as< Rcpp::NumericMatrix >( s );
488 +
        Rcpp::Rcout << mat << std::endl;
489 +
        res[i] = sfheaders::df::sfg_linestring_coordinates( mat, sfg_rows );
490 +
        break;
491 +
      }
492 +
      case sfheaders::sfg::SFG_MULTILINESTRING: {
493 +
        Rcpp::List lst = Rcpp::as< Rcpp::List >( s );
494 +
        res[i] = sfheaders::df::sfg_multilinestring_coordinates( lst, sfg_rows );
495 +
        break;
496 +
      }
497 +
      case sfheaders::sfg::SFG_POLYGON: {
498 +
        Rcpp::List lst = Rcpp::as< Rcpp::List >( s );
499 +
        res[i] = sfheaders::df::sfg_polygon_coordinates( lst, sfg_rows );
500 +
        break;
501 +
      }
502 +
      case sfheaders::sfg::SFG_MULTIPOLYGON: {
503 +
        Rcpp::List lst = Rcpp::as< Rcpp::List >( s );
504 +
        res[i] = sfheaders::df::sfg_multipolygon_coordinates( lst, sfg_rows );
505 +
        break;
506 +
      }
507 +
      case sfheaders::sfg::SFG_GEOMETRYCOLLECTION: {
508 +
        Rcpp::List lst = Rcpp::as< Rcpp::List >( s );
509 +
        res[i] = sfheaders::df::sfg_geometrycollection_coordinates( lst, sfg_rows );
510 +
        Rcpp::Rcout << "getting gc coords - sfg_rows: " << sfg_rows << std::endl;
511 +
        //res = collapse_list( res, sfg_rows );
512 +
        break;
513 +
      }
514 +
      default: {
515 +
        Rcpp::stop("sfheaders - unknown sfg type inside goemetrycollection");  // #nocov
516 +
      }
517 +
      }
518 +
    }
519 +
520 +
    Rcpp::Rcout << "sfg_rows: " << sfg_rows << std::endl;
521 +
522 +
    // res = collapse_list( res, sfg_rows );
523 +
524 +
    return res;
525 +
526 +
    Rcpp::stop("sfheaders - geometrycollection not implemented");
527 +
    return Rcpp::List();
528 +
  }
529 +
530 +
  inline Rcpp::List get_sfg_coordinates( SEXP& sfg, R_xlen_t& sfc_rows, int SFG_TYPE ) {
531 +
532 +
    switch( SFG_TYPE ) {
533 +
    case sfheaders::sfg::SFG_POINT: {
534 +
      Rcpp::NumericVector vec = Rcpp::as< Rcpp::NumericVector >( sfg );
535 +
      return sfheaders::df::sfg_point_coordinates( vec, sfc_rows );
536 +
    }
537 +
    case sfheaders::sfg::SFG_MULTIPOINT: {
538 +
      Rcpp::NumericMatrix mat = Rcpp::as< Rcpp::NumericMatrix >( sfg );
539 +
      return sfheaders::df::sfg_multipoint_coordinates( mat, sfc_rows );
540 +
    }
541 +
    case sfheaders::sfg::SFG_LINESTRING: {
542 +
      Rcpp::NumericMatrix mat = Rcpp::as< Rcpp::NumericMatrix >( sfg );
543 +
      return sfheaders::df::sfg_linestring_coordinates( mat, sfc_rows );
544 +
    }
545 +
    case sfheaders::sfg::SFG_MULTILINESTRING: {
546 +
      Rcpp::List lst = Rcpp::as< Rcpp::List >( sfg );
547 +
      return sfheaders::df::sfg_multilinestring_coordinates( lst, sfc_rows );
548 +
    }
549 +
    case sfheaders::sfg::SFG_POLYGON: {
550 +
      Rcpp::List lst = Rcpp::as< Rcpp::List >( sfg );
551 +
      return sfheaders::df::sfg_polygon_coordinates( lst, sfc_rows );
552 +
    }
553 +
    case sfheaders::sfg::SFG_MULTIPOLYGON: {
554 +
      Rcpp::List lst = Rcpp::as< Rcpp::List >( sfg );
555 +
      return sfheaders::df::sfg_multipolygon_coordinates( lst, sfc_rows );
556 +
    }
557 +
    case sfheaders::sfg::SFG_GEOMETRYCOLLECTION: {
558 +
      Rcpp::List lst = Rcpp::as< Rcpp::List >( sfg );
559 +
      return sfheaders::df::sfg_geometrycollection_coordinates( lst, sfc_rows );
560 +
    }
561 +
    default: {
562 +
      Rcpp::stop("sfheaders - unknown sfg type");  // #nocov
563 +
    }
564 +
    }
565 +
    return Rcpp::List::create(); // #nocov never reaches
566 +
  }
567 +
568 +
  inline Rcpp::List sfg_to_df( SEXP& sfg, R_xlen_t& sfg_rows ) {
377 569
378 570
    Rcpp::List res;
379 571
@@ -387,7 +579,7 @@
Loading
387 579
    //dim = cls[0];
388 580
    geometry = cls[1];
389 581
390 -
    R_xlen_t sfg_rows = 0;
582 +
    //R_xlen_t sfg_rows = 0;
391 583
392 584
    if( geometry == "POINT" ) {
393 585
      Rcpp::NumericVector nv = Rcpp::as< Rcpp::NumericVector >( sfg );
@@ -413,23 +605,34 @@
Loading
413 605
      Rcpp::List lst = Rcpp::as< Rcpp::List >( sfg );
414 606
      res = sfg_multipolygon_coordinates( lst, sfg_rows );
415 607
608 +
    } else if (geometry == "GEOMETRYCOLLECTION" ) {
609 +
      Rcpp::List lst = Rcpp::as< Rcpp::List >( sfg );
610 +
      R_xlen_t n = lst.size();
611 +
      R_xlen_t i;
612 +
      //R_xlen_t total_rows;
613 +
      R_xlen_t inner_rows = 0;
614 +
      Rcpp::List inner_res( n );
615 +
      for( i = 0; i < n; ++i ) {
616 +
        Rcpp::Rcout << "loopy" << std::endl;
617 +
        SEXP sfgi = lst[ i ];
618 +
        inner_res[ i ] =  sfg_to_df( sfgi, inner_rows );
619 +
        Rcpp::Rcout << "inner_rows: " << inner_rows << std::endl;
620 +
        //total_rows = total_rows + inner_rows;
621 +
        //Rcpp::Rcout << "total_rows: " << total_rows << std::endl;
622 +
        sfg_rows = sfg_rows + inner_rows;
623 +
      }
624 +
      Rcpp::Rcout << "total_sfg_rows: " << sfg_rows << std::endl;
625 +
      //res = collapse_list( inner_res, sfg_rows );
626 +
      //res = sfg_geometrycollection_coordinates( lst, sfg_rows );
627 +
      return inner_res;
628 +
416 629
    } else {
417 630
      Rcpp::stop("sfheaders - unknown geometry type"); // #nocov
418 631
    }
419 632
420 633
    Rcpp::CharacterVector df_names = make_names( cls );
421 -
422 -
    res.attr("class") = Rcpp::CharacterVector("data.frame");
423 -
424 -
    if( sfg_rows > 0 ) {
425 -
      Rcpp::IntegerVector rownames = Rcpp::seq( 1, sfg_rows );
426 -
      res.attr("row.names") = rownames;
427 -
    } else {
428 -
      res.attr("row.names") = Rcpp::IntegerVector(0); // #nocov
429 -
    }
430 -
431 -
    res.attr("names") = df_names;
432 -
    return res;
634 +
    Rcpp::Rcout << "cls: " << cls << ", df_names: " << df_names << std::endl;
635 +
    return sfheaders::utils::make_dataframe(res, sfg_rows, df_names );
433 636
  }
434 637
435 638
} // df

@@ -3,7 +3,8 @@
Loading
3 3
4 4
// [[Rcpp::export]]
5 5
SEXP rcpp_sfg_to_df( SEXP sfg ) {
6 -
  return sfheaders::df::sfg_to_df( sfg );
6 +
  R_xlen_t sfg_rows = 0;
7 +
  return sfheaders::df::sfg_to_df( sfg, sfg_rows );
7 8
}
8 9
9 10
// [[Rcpp::export]]

@@ -48,64 +48,6 @@
Loading
48 48
    return res;
49 49
  }
50 50
51 -
  inline void dim_error() { // #nocov
52 -
    Rcpp::stop("sfheaders - unknown geometry dimension");    // #nocov
53 -
  }
54 -
55 -
  inline Rcpp::IntegerVector get_sfg_cols( R_xlen_t& n_col, int geometry, std::string& dim ) {
56 -
57 -
    switch( geometry ) {
58 -
    case sfheaders::sfg::SFG_POINT: {}
59 -
    case sfheaders::sfg::SFG_MULTIPOINT: {}
60 -
    case sfheaders::sfg::SFG_LINESTRING: {
61 -
      if( dim == "XY" ) {
62 -
      return Rcpp::IntegerVector({ X_COLUMN, Y_COLUMN });
63 -
    } else if( dim == "XYZM" ) {
64 -
      return Rcpp::IntegerVector({ X_COLUMN, Y_COLUMN, Z_COLUMN, M_COLUMN });
65 -
    } else if ( dim == "XYZ" ) {
66 -
      return Rcpp::IntegerVector({ X_COLUMN, Y_COLUMN, Z_COLUMN });
67 -
    } else if ( dim == "XYM" ) {
68 -
      return Rcpp::IntegerVector({ X_COLUMN, Y_COLUMN, M_COLUMN });
69 -
    } else {
70 -
      dim_error();  // #nocov
71 -
    }
72 -
    }
73 -
    case sfheaders::sfg::SFG_MULTILINESTRING: {}
74 -
    case sfheaders::sfg::SFG_POLYGON: {
75 -
      if( dim == "XY" ) {
76 -
      return Rcpp::IntegerVector({ LINESTRING_COLUMN, X_COLUMN, Y_COLUMN });
77 -
    } else if( dim == "XYZM" ) {
78 -
      return Rcpp::IntegerVector({ LINESTRING_COLUMN, X_COLUMN, Y_COLUMN, Z_COLUMN, M_COLUMN });
79 -
    } else if ( dim == "XYZ" ) {
80 -
      return Rcpp::IntegerVector({ LINESTRING_COLUMN, X_COLUMN, Y_COLUMN, Z_COLUMN });
81 -
    } else if ( dim == "XYM" ) {
82 -
      return Rcpp::IntegerVector({ LINESTRING_COLUMN, X_COLUMN, Y_COLUMN, M_COLUMN });
83 -
    } else {
84 -
      dim_error();  // #nocov
85 -
    }
86 -
    }
87 -
    case sfheaders::sfg::SFG_MULTIPOLYGON: {
88 -
      if( dim == "XY" ) {
89 -
      return Rcpp::IntegerVector({ POLYGON_COLUMN, LINESTRING_COLUMN, X_COLUMN, Y_COLUMN });
90 -
    } else if( dim == "XYZM" ) {
91 -
      return Rcpp::IntegerVector({ POLYGON_COLUMN, LINESTRING_COLUMN, X_COLUMN, Y_COLUMN, Z_COLUMN, M_COLUMN });
92 -
    } else if ( dim == "XYZ" ) {
93 -
      return Rcpp::IntegerVector({ POLYGON_COLUMN, LINESTRING_COLUMN, X_COLUMN, Y_COLUMN, Z_COLUMN });
94 -
    } else if ( dim == "XYM" ) {
95 -
      return Rcpp::IntegerVector({ POLYGON_COLUMN, LINESTRING_COLUMN, X_COLUMN, Y_COLUMN, M_COLUMN });
96 -
    } else {
97 -
      dim_error(); // #nocov
98 -
    }
99 -
100 -
    }
101 -
    default: {
102 -
      Rcpp::stop("sfheaders - unknown geometry type");  // #nocov
103 -
    }
104 -
    }
105 -
106 -
    return Rcpp::IntegerVector(); // #nocov never reached
107 -
  }
108 -
109 51
  inline void sfg_n_coordinates(
110 52
      SEXP& sfg,
111 53
      R_xlen_t& sfg_count
@@ -172,62 +114,6 @@
Loading
172 114
    return res;
173 115
  }
174 116
175 -
  // sfcs are a list of sfgs.
176 -
  // they can be mixed, or individual.
177 -
  // if indiidual, loop over each one and extract the sfgs, list by list, then collapse the lists??
178 -
179 -
  inline Rcpp::List get_sfg_coordinates( SEXP& sfg, R_xlen_t& sfc_rows, int SFG_TYPE ) {
180 -
181 -
    switch( SFG_TYPE ) {
182 -
    case sfheaders::sfg::SFG_POINT: {
183 -
      Rcpp::NumericVector vec = Rcpp::as< Rcpp::NumericVector >( sfg );
184 -
      return sfheaders::df::sfg_point_coordinates( vec, sfc_rows );
185 -
    }
186 -
    case sfheaders::sfg::SFG_MULTIPOINT: {
187 -
      Rcpp::NumericMatrix mat = Rcpp::as< Rcpp::NumericMatrix >( sfg );
188 -
      return sfheaders::df::sfg_multipoint_coordinates( mat, sfc_rows );
189 -
    }
190 -
    case sfheaders::sfg::SFG_LINESTRING: {
191 -
      Rcpp::NumericMatrix mat = Rcpp::as< Rcpp::NumericMatrix >( sfg );
192 -
      return sfheaders::df::sfg_linestring_coordinates( mat, sfc_rows );
193 -
    }
194 -
    case sfheaders::sfg::SFG_MULTILINESTRING: {
195 -
      Rcpp::List lst = Rcpp::as< Rcpp::List >( sfg );
196 -
      return sfheaders::df::sfg_multilinestring_coordinates( lst, sfc_rows );
197 -
    }
198 -
    case sfheaders::sfg::SFG_POLYGON: {
199 -
      Rcpp::List lst = Rcpp::as< Rcpp::List >( sfg );
200 -
      return sfheaders::df::sfg_polygon_coordinates( lst, sfc_rows );
201 -
    }
202 -
    case sfheaders::sfg::SFG_MULTIPOLYGON: {
203 -
      Rcpp::List lst = Rcpp::as< Rcpp::List >( sfg );
204 -
      return sfheaders::df::sfg_multipolygon_coordinates( lst, sfc_rows );
205 -
    }
206 -
    default: {
207 -
      Rcpp::stop("sfheaders - unknown sfg type");  // #nocov
208 -
    }
209 -
    }
210 -
    return Rcpp::List::create(); // #nocov never reaches
211 -
  }
212 -
213 -
  inline int get_sfg_type( std::string& sfg ) {
214 -
    if( sfg == "POINT" ) {
215 -
      return sfheaders::sfg::SFG_POINT;
216 -
    } else if ( sfg == "MULTIPOINT" ) {
217 -
      return sfheaders::sfg::SFG_MULTIPOINT;
218 -
    } else if ( sfg == "LINESTRING" ) {
219 -
      return sfheaders::sfg::SFG_LINESTRING;
220 -
    } else if ( sfg == "MULTILINESTRING" ) {
221 -
      return sfheaders::sfg::SFG_MULTILINESTRING;
222 -
    } else if ( sfg == "POLYGON" ) {
223 -
      return sfheaders::sfg::SFG_POLYGON;
224 -
    } else if ( sfg == "MULTIPOLYGON" ) {
225 -
      return sfheaders::sfg::SFG_MULTIPOLYGON;
226 -
    } else {
227 -
      Rcpp::stop("sfheaders - unknown sfg type");  // #nocov
228 -
    }
229 -
  }
230 -
231 117
  inline int get_sfg_column_index( std::string& sfg ) {
232 118
    if( sfg == "POINT" ) {
233 119
      return POINT_COLUMN;
@@ -241,13 +127,22 @@
Loading
241 127
      return POLYGON_COLUMN;
242 128
    } else if ( sfg == "MULTIPOLYGON" ) {
243 129
      return MULTIPOLYGON_COLUMN;
130 +
    } else if ( sfg == "GEOMETRYCOLLECTION" ) {
131 +
      return GEOMETRYCOLLECTION_COLUMN;
244 132
    } else {
245 133
      Rcpp::stop("sfheaders - unknown sfg type");  // #nocov
246 134
    }
247 135
  }
248 136
249 -
250 -
  // used for any mixed geomtry, or non-POINT, because the total number of rows is varaible
137 +
  /*
138 +
   * get sfc geometry coordinates
139 +
   *
140 +
   * loops into every sfg inside the sfc and fills in the result list
141 +
   * (from \code{setup_result}) for the correct columns, and
142 +
   * at the appropriate row index
143 +
   *
144 +
   * used for any mixed geomtry, or non-POINT, because the total number of rows is varaible
145 +
   */
251 146
  inline Rcpp::List get_sfc_geometry_coordinates(
252 147
      Rcpp::List& sfc,
253 148
      R_xlen_t& total_coordinates
@@ -278,10 +173,14 @@
Loading
278 173
279 174
    for( i = 0; i < n_sfg; ++i ) {
280 175
176 +
      Rcpp::Rcout << "i: " << i << std::endl;
177 +
281 178
      SEXP sfci = sfc[ i ];
282 179
283 180
      cls = sfheaders::utils::getSfgClass( sfci );
284 181
182 +
      Rcpp::Rcout << "cls: " << cls << std::endl;
183 +
285 184
      dim = cls[0];
286 185
287 186
      if ( dim == "XYZM" ) {
@@ -297,17 +196,32 @@
Loading
297 196
      // Rcpp::Rcout << "columns: " << columns << std::endl;
298 197
299 198
      sfg_class = cls[1];
300 -
      sfg_type = get_sfg_type( sfg_class );
199 +
      sfg_type = sfheaders::sfg::get_sfg_type( sfg_class );
301 200
      sfg_column_idx = get_sfg_column_index( sfg_class );
302 201
      columns[ sfg_column_idx ] = true;
303 202
304 -
      Rcpp::List sfg = get_sfg_coordinates( sfci, sfc_rows, sfg_type );
203 +
      Rcpp::List sfg = sfheaders::df::get_sfg_coordinates( sfci, sfc_rows, sfg_type );
305 204
205 +
      // for any other 'sfg', this size is the length of the list
206 +
      // because it goes through the various 'matrix_to_list' / 'vector_to_list'
207 +
      // functions
208 +
      // so a GEOMETRYCOLLECTION needs to be collapsed to this list
209 +
      // (and)
306 210
      n_col = sfg.size();
307 211
308 -
      Rcpp::IntegerVector sfg_cols = get_sfg_cols( n_col, sfg_type, dim );
309 -
      column_index_check( sfg_cols, n_col );
212 +
      Rcpp::IntegerVector sfg_cols = sfheaders::df::get_sfg_cols( n_col, sfg_type, dim );
213 +
214 +
      Rcpp::Rcout << "sfg_cols: " << sfg_cols << std::endl;
215 +
      Rcpp::Rcout << "n_col: " << n_col << std::endl;
216 +
217 +
      //return sfg;
218 +
219 +
      //column_index_check( sfg_cols, n_col );
220 +
221 +
      Rcpp::Rcout << "index checked" << std::endl;
310 222
223 +
      // for GEOMETRYCOLLECTIONS this needs to loop over each geometry?
224 +
      // or should the 'sfg' be collapsed before it gets here??
311 225
      for( j = 0; j < n_col; ++j ) {
312 226
313 227
        Rcpp::NumericVector new_values_vector = sfg[ j ];

@@ -14,11 +14,11 @@
Loading
14 14
namespace sfheaders {
15 15
namespace cast {
16 16
17 -
  inline void column_index_check( Rcpp::IntegerVector& sfg_cols, R_xlen_t& n_col ) {
18 -
    if( sfg_cols.length() != n_col ) {
19 -
      Rcpp::stop("sfheaders - column indexing error - please report this issue, along with an example, at github.com/dcooley/sfheaders");  // #nocov
20 -
    }
21 -
  }
17 +
  // inline void column_index_check( Rcpp::IntegerVector& sfg_cols, R_xlen_t& n_col ) {
18 +
  //   if( sfg_cols.length() != n_col ) {
19 +
  //     Rcpp::stop("sfheaders - column indexing error - please report this issue, along with an example, at github.com/dcooley/sfheaders");  // #nocov
20 +
  //   }
21 +
  // }
22 22
23 23
  // inline Rcpp::List vec_to_vec( Rcpp::NumericVector& sfg, R_xlen_t& sfg_rows, double& id ) {
24 24
  //   return sfheaders::df::vector_to_list( sfg, sfg_rows, id );

@@ -9,12 +9,13 @@
Loading
9 9
namespace sfheaders {
10 10
namespace sfg {
11 11
12 -
  const int SFG_POINT           = 1;
13 -
  const int SFG_MULTIPOINT      = 2;
14 -
  const int SFG_LINESTRING      = 3;
15 -
  const int SFG_MULTILINESTRING = 4;
16 -
  const int SFG_POLYGON         = 5;
17 -
  const int SFG_MULTIPOLYGON    = 6;
12 +
  const int SFG_POINT              = 1;
13 +
  const int SFG_MULTIPOINT         = 2;
14 +
  const int SFG_LINESTRING         = 3;
15 +
  const int SFG_MULTILINESTRING    = 4;
16 +
  const int SFG_POLYGON            = 5;
17 +
  const int SFG_MULTIPOLYGON       = 6;
18 +
  const int SFG_GEOMETRYCOLLECTION = 7;
18 19
19 20
  const int VECTOR              = 1;
20 21
  const int MATRIX              = 2;
@@ -36,6 +37,26 @@
Loading
36 37
    return ""; // never reaches
37 38
  }
38 39
40 +
  inline int get_sfg_type( std::string& sfg ) {
41 +
    if( sfg == "POINT" ) {
42 +
      return sfheaders::sfg::SFG_POINT;
43 +
    } else if ( sfg == "MULTIPOINT" ) {
44 +
      return sfheaders::sfg::SFG_MULTIPOINT;
45 +
    } else if ( sfg == "LINESTRING" ) {
46 +
      return sfheaders::sfg::SFG_LINESTRING;
47 +
    } else if ( sfg == "MULTILINESTRING" ) {
48 +
      return sfheaders::sfg::SFG_MULTILINESTRING;
49 +
    } else if ( sfg == "POLYGON" ) {
50 +
      return sfheaders::sfg::SFG_POLYGON;
51 +
    } else if ( sfg == "MULTIPOLYGON" ) {
52 +
      return sfheaders::sfg::SFG_MULTIPOLYGON;
53 +
    } else if ( sfg == "GEOMETRYCOLLECTION" ) {
54 +
      return sfheaders::sfg::SFG_GEOMETRYCOLLECTION;
55 +
    } else {
56 +
      Rcpp::stop("sfheaders - unknown sfg type");  // #nocov
57 +
    }
58 +
  }
59 +
39 60
  inline void make_sfg(
40 61
    Rcpp::IntegerVector& iv,
41 62
    int sfg_type,

Learn more Showing 4 files with coverage changes found.

Changes in inst/include/sfheaders/utils/lists/list.hpp
-3
+3
Loading file...
Changes in inst/include/sfheaders/df/sf.hpp
-5
Loading file...
Changes in R/sf_helpers.R
-1
Loading file...
Changes in inst/include/sfheaders/df/sfc.hpp
-2
Loading file...
Files Coverage
R -0.02% 95.67%
inst/include/sfheaders -1.25% 98.04%
src 0.02% 96.76%
Project Totals (74 files) 97.90%
Loading