Commit a76b6e9646545af20b9d5caf10c5c1efa6823b7b

Authored by Jordi Inglada
1 parent 8068e334
Exists in master

Add doc to functions

Showing 2 changed files with 19 additions and 4 deletions   Show diff stats
include/maassp_utils.h
... ... @@ -23,8 +23,8 @@ DeptToTiles get_intersecting_tiles(otb::ogr::DataSource::Pointer& polygon_source
23 23 {
24 24  
25 25 DeptToTiles result{};
26   - auto polys = get_geometries(polygon_source);
27   - auto tiles = get_geometries(tile_source);
  26 + auto polys = get_features(polygon_source);
  27 + auto tiles = get_features(tile_source);
28 28  
29 29 for(const auto& dept : polys)
30 30 {
... ... @@ -75,7 +75,7 @@ AreaPerTile compute_area_per_tile(otb::ogr::DataSource::Pointer& polygon_source,
75 75 std::vector<TileIntersection>& tiles,
76 76 std::vector<std::string> culture_patterns = {"_BLE_"})
77 77 {
78   - auto polys = get_geometries(polygon_source);
  78 + auto polys = get_features(polygon_source);
79 79 AreaPerTile result;
80 80 for(const auto& parcelle : polys)
81 81 {
... ...
include/ogr_utils.h
... ... @@ -10,12 +10,14 @@
10 10  
11 11 using namespace cbutils::operators;
12 12  
  13 +// Simple struct with the name and the type of an OGRField
13 14 struct Field
14 15 {
15 16 std::string name;
16 17 OGRFieldType type;
17 18 };
18 19  
  20 +// Return the fields available in a layer
19 21 std::vector<Field> get_fields(const otb::ogr::Layer& layer)
20 22 {
21 23 std::vector<Field> fields;
... ... @@ -28,11 +30,13 @@ std::vector&lt;Field&gt; get_fields(const otb::ogr::Layer&amp; layer)
28 30 return fields;
29 31 }
30 32  
  33 +// Return the fields of the ogr data source for a particular layer
31 34 std::vector<Field> get_fields(otb::ogr::DataSource::Pointer &source, int layer_id=0)
32 35 {
33 36 return get_fields(source->GetLayer(layer_id));
34 37 }
35 38  
  39 +// Check if a layer has a field with the given name. Case sensitive.
36 40 bool has_field(const otb::ogr::Layer& layer, std::string field_name)
37 41 {
38 42 auto fields = get_fields(layer);
... ... @@ -42,12 +46,15 @@ bool has_field(const otb::ogr::Layer&amp; layer, std::string field_name)
42 46 })!=cend(fields);
43 47 }
44 48  
  49 +// Check if an ogr data source has a field with the given name in a
  50 +// given layer. Case sensitive.
45 51 bool has_field(otb::ogr::DataSource::Pointer &source, std::string field_name,
46 52 int layer_id=0)
47 53 {
48 54 return has_field(source->GetLayer(layer_id), field_name);
49 55 }
50 56  
  57 +// Returns the field names in a layer
51 58 std::vector<std::string> get_field_names(const otb::ogr::Layer& layer)
52 59 {
53 60 std::vector<std::string> field_names;
... ... @@ -55,11 +62,13 @@ std::vector&lt;std::string&gt; get_field_names(const otb::ogr::Layer&amp; layer)
55 62 return field_names;
56 63 }
57 64  
  65 +// Returns the field names in a layer of an ogr data source
58 66 std::vector<std::string> get_field_names(otb::ogr::DataSource::Pointer &source, int layer_id=0)
59 67 {
60 68 return get_field_names(source->GetLayer(layer_id));
61 69 }
62 70  
  71 +// Prints the field names in a layer
63 72 void print_fields_in_layer(otb::ogr::Layer& layer, std::ostream& stream = std::cout)
64 73 {
65 74 for(const auto& f : get_fields(layer))
... ... @@ -68,6 +77,7 @@ void print_fields_in_layer(otb::ogr::Layer&amp; layer, std::ostream&amp; stream = std::c
68 77 }
69 78 }
70 79  
  80 +// Prints the field names in a layer of an ogr data source
71 81 void print_fields(otb::ogr::DataSource::Pointer &source, int layer_id=0,
72 82 std::ostream& stream = std::cout)
73 83 {
... ... @@ -75,7 +85,9 @@ void print_fields(otb::ogr::DataSource::Pointer &amp;source, int layer_id=0,
75 85 print_fields_in_layer(layer, stream);
76 86 }
77 87  
78   -std::vector<otb::ogr::Feature> get_geometries(otb::ogr::DataSource::Pointer& source)
  88 +
  89 +// Returns all the features in an ogr data source. Must fit in memory.
  90 +std::vector<otb::ogr::Feature> get_features(otb::ogr::DataSource::Pointer& source)
79 91 {
80 92 std::vector<otb::ogr::Feature> result;
81 93 otb::ogr::Layer layer = source->GetLayer(0);
... ... @@ -87,6 +99,8 @@ std::vector&lt;otb::ogr::Feature&gt; get_geometries(otb::ogr::DataSource::Pointer&amp; sou
87 99 }
88 100  
89 101  
  102 +// Reprojects the source geometries on to the proj_ref projection and
  103 +// returns a new data source
90 104 otb::ogr::DataSource::Pointer reproject_geometries(otb::GeometriesSet::Pointer& source, std::string proj_ref)
91 105 {
92 106 auto reprojVector = otb::ogr::DataSource::New();
... ... @@ -99,6 +113,7 @@ otb::ogr::DataSource::Pointer reproject_geometries(otb::GeometriesSet::Pointer&amp;
99 113 return reprojVector;
100 114 }
101 115  
  116 +// Returns the area of polygon or multi_polygon
102 117 double get_area(const OGRGeometry* geom)
103 118 {
104 119 auto geo_name = std::string(geom->getGeometryName());
... ...