Commit 8068e334e3f646fd41e4aea7c18a0380fceafd8b

Authored by Jordi Inglada
1 parent 3d90ae7f
Exists in master

Add doc for functions

Showing 1 changed file with 21 additions and 3 deletions   Show diff stats
include/maassp_utils.h
... ... @@ -4,13 +4,20 @@
4 4 #include "ogr_utils.h"
5 5 #include <unordered_map>
6 6  
  7 +// A class to model a tile which intersects another geometry
7 8 struct TileIntersection{
8   - std::string tile_name;
  9 + std::string tile_name;
9 10 double intersection_area;
10   - otb::ogr::Feature tile_feature;
  11 + otb::ogr::Feature tile_feature; //the tile itself
11 12 };
  13 +
  14 +// A type mapping a departement code to the list of tiles which
  15 +// intersect the department
12 16 using DeptToTiles = std::unordered_map<std::string, std::vector<TileIntersection>>;
13 17  
  18 +// Given an ogr data source containing the departements and another
  19 +// one containing the S2 tiles, build the map of intersecting tiles
  20 +// per dept
14 21 DeptToTiles get_intersecting_tiles(otb::ogr::DataSource::Pointer& polygon_source,
15 22 otb::ogr::DataSource::Pointer& tile_source)
16 23 {
... ... @@ -39,6 +46,7 @@ DeptToTiles get_intersecting_tiles(otb::ogr::DataSource::Pointer&amp; polygon_source
39 46 return result;
40 47 }
41 48  
  49 +// Utility to display the map from depts to tiles
42 50 void print_dept_tiles(DeptToTiles tile_list, std::ostream& stream = std::cout)
43 51 {
44 52 for(const auto& d : tile_list)
... ... @@ -53,10 +61,16 @@ void print_dept_tiles(DeptToTiles tile_list, std::ostream&amp; stream = std::cout)
53 61 }
54 62  
55 63  
  64 +// A type mapping a tile name to an area
56 65 using AreaPerTile = std::unordered_map<std::string, double>;
57   -using AreaPerTilePerDept = std::unordered_map<std::string, AreaPerTile>;
58 66  
  67 +// A type mapping a dept to its AreaPerTile
  68 +using AreaPerTilePerDept = std::unordered_map<std::string, AreaPerTile>;
59 69  
  70 +// Given the dept crop parcels, the tile polygons and the list of crop
  71 +// names to match, compute the total area in the department for the
  72 +// whole set of matching crops and for each intersecting tile. The
  73 +// result is the total area per tile.
60 74 AreaPerTile compute_area_per_tile(otb::ogr::DataSource::Pointer& polygon_source,
61 75 std::vector<TileIntersection>& tiles,
62 76 std::vector<std::string> culture_patterns = {"_BLE_"})
... ... @@ -89,6 +103,7 @@ AreaPerTile compute_area_per_tile(otb::ogr::DataSource::Pointer&amp; polygon_source,
89 103 return result;
90 104 }
91 105  
  106 +// Utility to print the total areas per dept and per tile
92 107 void print_total_areas(AreaPerTilePerDept aptpd, std::ostream& stream = std::cout)
93 108 {
94 109 for(const auto& dept : aptpd)
... ... @@ -101,11 +116,14 @@ void print_total_areas(AreaPerTilePerDept aptpd, std::ostream&amp; stream = std::cou
101 116 }
102 117 }
103 118  
  119 +// Simple struct to store a tile name and a dept code.
104 120 struct TileDept{
105 121 std::string tile_name;
106 122 std::string code_dept;
107 123 };
108 124  
  125 +// Among all the total areas per tile for each dept, find the
  126 +// combination of dept and tile with the largest area
109 127 TileDept best_tile_dept(AreaPerTilePerDept aptpd)
110 128 {
111 129 double max_area{0};
... ...