dcooley / sfheaders

@@ -373,6 +373,79 @@
Loading
373 373
    return res;
374 374
  }
375 375
376 +
  inline Rcpp::List sfg_geometrycollection_coordinates( Rcpp::List& sfg, R_xlen_t& sfg_rows ) {
377 +
378 +
    R_xlen_t n_sfgs = sfg.size();
379 +
    R_xlen_t i;
380 +
    Rcpp::List res( n_sfgs );
381 +
382 +
    // need to fill res(),
383 +
    // then collapse it...
384 +
    // but it will be filled like an 'sfc' - a collection of geometries.
385 +
    // ...
386 +
    // to collapse_list, each list element must have the same number of columns
387 +
    // so do I initialise all of them?
388 +
389 +
    for( i = 0; i < n_sfgs; ++i ) {
390 +
391 +
      SEXP s = sfg[ i ];
392 +
      Rcpp::CharacterVector cls = sfheaders::utils::getSfgClass( s );
393 +
      std::string geometry;
394 +
      geometry = cls[1];
395 +
      int sfg_type = sfheaders::sfg::get_sfg_type( geometry );
396 +
397 +
      Rcpp::Rcout << "geometry: " << geometry << ", " << sfg_type << std::endl;
398 +
399 +
      switch( sfg_type ) {
400 +
      case sfheaders::sfg::SFG_POINT: {
401 +
        Rcpp::NumericVector vec = Rcpp::as< Rcpp::NumericVector >( s );
402 +
        res[i] = sfheaders::df::sfg_point_coordinates( vec, sfg_rows );
403 +
        break;
404 +
      }
405 +
      case sfheaders::sfg::SFG_MULTIPOINT: {
406 +
        Rcpp::NumericMatrix mat = Rcpp::as< Rcpp::NumericMatrix >( s );
407 +
        Rcpp::Rcout << mat << std::endl;
408 +
        res[i] = sfheaders::df::sfg_multipoint_coordinates( mat, sfg_rows );
409 +
        break;
410 +
      }
411 +
      case sfheaders::sfg::SFG_LINESTRING: {
412 +
        Rcpp::NumericMatrix mat = Rcpp::as< Rcpp::NumericMatrix >( s );
413 +
        Rcpp::Rcout << mat << std::endl;
414 +
        res[i] = sfheaders::df::sfg_linestring_coordinates( mat, sfg_rows );
415 +
        break;
416 +
      }
417 +
      case sfheaders::sfg::SFG_MULTILINESTRING: {
418 +
        Rcpp::List lst = Rcpp::as< Rcpp::List >( s );
419 +
        res[i] = sfheaders::df::sfg_multilinestring_coordinates( lst, sfg_rows );
420 +
        break;
421 +
      }
422 +
      case sfheaders::sfg::SFG_POLYGON: {
423 +
        Rcpp::List lst = Rcpp::as< Rcpp::List >( s );
424 +
        res[i] = sfheaders::df::sfg_polygon_coordinates( lst, sfg_rows );
425 +
        break;
426 +
      }
427 +
      case sfheaders::sfg::SFG_MULTIPOLYGON: {
428 +
        Rcpp::List lst = Rcpp::as< Rcpp::List >( s );
429 +
        res[i] = sfheaders::df::sfg_multipolygon_coordinates( lst, sfg_rows );
430 +
        break;
431 +
      }
432 +
      case sfheaders::sfg::SFG_GEOMETRYCOLLECTION: {
433 +
        Rcpp::List lst = Rcpp::as< Rcpp::List >( s );
434 +
        res[i] = sfheaders::df::sfg_geometrycollection_coordinates( lst, sfg_rows );
435 +
        break;
436 +
      }
437 +
      default: {
438 +
        Rcpp::stop("sfheaders - unknown sfg type inside goemetrycollection");  // #nocov
439 +
      }
440 +
      }
441 +
    }
442 +
443 +
    return res;
444 +
445 +
    Rcpp::stop("sfheaders - geometrycollection not implemented");
446 +
    return Rcpp::List();
447 +
  }
448 +
376 449
  inline Rcpp::List sfg_to_df( SEXP& sfg ) {
377 450
378 451
    Rcpp::List res;
@@ -418,18 +491,19 @@
Loading
418 491
    }
419 492
420 493
    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;
494 +
    return sfheaders::utils::make_dataframe(res, sfg_rows, df_names );
495 +
496 +
    // res.attr("class") = Rcpp::CharacterVector("data.frame");
497 +
    //
498 +
    // if( sfg_rows > 0 ) {
499 +
    //   Rcpp::IntegerVector rownames = Rcpp::seq( 1, sfg_rows );
500 +
    //   res.attr("row.names") = rownames;
501 +
    // } else {
502 +
    //   res.attr("row.names") = Rcpp::IntegerVector(0); // #nocov
503 +
    // }
504 +
    //
505 +
    // res.attr("names") = df_names;
506 +
    // return res;
433 507
  }
434 508
435 509
} // df

@@ -172,6 +172,26 @@
Loading
172 172
    return res;
173 173
  }
174 174
175 +
  inline int get_sfg_column_index( std::string& sfg ) {
176 +
    if( sfg == "POINT" ) {
177 +
      return POINT_COLUMN;
178 +
    } else if ( sfg == "MULTIPOINT" ) {
179 +
      return MULTIPOINT_COLUMN;
180 +
    } else if ( sfg == "LINESTRING" ) {
181 +
      return LINESTRING_COLUMN;
182 +
    } else if ( sfg == "MULTILINESTRING" ) {
183 +
      return MULTILINESTRING_COLUMN;
184 +
    } else if ( sfg == "POLYGON" ) {
185 +
      return POLYGON_COLUMN;
186 +
    } else if ( sfg == "MULTIPOLYGON" ) {
187 +
      return MULTIPOLYGON_COLUMN;
188 +
    } else if ( sfg == "GEOMETRYCOLLECTION" ) {
189 +
      return GEOMETRYCOLLECTION_COLUMN;
190 +
    } else {
191 +
      Rcpp::stop("sfheaders - unknown sfg type");  // #nocov
192 +
    }
193 +
  }
194 +
175 195
  // sfcs are a list of sfgs.
176 196
  // they can be mixed, or individual.
177 197
  // if indiidual, loop over each one and extract the sfgs, list by list, then collapse the lists??
@@ -203,6 +223,10 @@
Loading
203 223
      Rcpp::List lst = Rcpp::as< Rcpp::List >( sfg );
204 224
      return sfheaders::df::sfg_multipolygon_coordinates( lst, sfc_rows );
205 225
    }
226 +
    case sfheaders::sfg::SFG_GEOMETRYCOLLECTION: {
227 +
      Rcpp::List lst = Rcpp::as< Rcpp::List >( sfg );
228 +
      return sfheaders::df::sfg_geometrycollection_coordinates( lst, sfc_rows );
229 +
    }
206 230
    default: {
207 231
      Rcpp::stop("sfheaders - unknown sfg type");  // #nocov
208 232
    }
@@ -210,44 +234,15 @@
Loading
210 234
    return Rcpp::List::create(); // #nocov never reaches
211 235
  }
212 236
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 -
  inline int get_sfg_column_index( std::string& sfg ) {
232 -
    if( sfg == "POINT" ) {
233 -
      return POINT_COLUMN;
234 -
    } else if ( sfg == "MULTIPOINT" ) {
235 -
      return MULTIPOINT_COLUMN;
236 -
    } else if ( sfg == "LINESTRING" ) {
237 -
      return LINESTRING_COLUMN;
238 -
    } else if ( sfg == "MULTILINESTRING" ) {
239 -
      return MULTILINESTRING_COLUMN;
240 -
    } else if ( sfg == "POLYGON" ) {
241 -
      return POLYGON_COLUMN;
242 -
    } else if ( sfg == "MULTIPOLYGON" ) {
243 -
      return MULTIPOLYGON_COLUMN;
244 -
    } else {
245 -
      Rcpp::stop("sfheaders - unknown sfg type");  // #nocov
246 -
    }
247 -
  }
248 -
249 -
250 -
  // used for any mixed geomtry, or non-POINT, because the total number of rows is varaible
237 +
  /*
238 +
   * get sfc geometry coordinates
239 +
   *
240 +
   * loops into every sfg inside the sfc and fills in the result list
241 +
   * (from \code{setup_result}) for the correct columns, and
242 +
   * at the appropriate row index
243 +
   *
244 +
   * used for any mixed geomtry, or non-POINT, because the total number of rows is varaible
245 +
   */
251 246
  inline Rcpp::List get_sfc_geometry_coordinates(
252 247
      Rcpp::List& sfc,
253 248
      R_xlen_t& total_coordinates
@@ -291,7 +286,7 @@
Loading
291 286
      }
292 287
293 288
      sfg_class = cls[1];
294 -
      sfg_type = get_sfg_type( sfg_class );
289 +
      sfg_type = sfheaders::sfg::get_sfg_type( sfg_class );
295 290
      sfg_column_idx = get_sfg_column_index( sfg_class );
296 291
      columns[ sfg_column_idx ] = true;
297 292

@@ -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
Files Coverage
R 100.00%
inst/include/sfheaders 98.96%
src 97.24%
Project Totals (69 files) 98.93%
1
comment: false
2

3
coverage:
4
  status:
5
    project:
6
      default:
7
        target: auto
8
        threshold: 1%
9
    patch:
10
      default:
11
        target: auto
12
        threshold: 1%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading