Commit 8979c2081bea2140fc0d97d9cbc63e9e36e28b29

Authored by Jordi Inglada
1 parent 455edf30
Exists in master

Indent

include/maassp_utils.h
... ... @@ -6,22 +6,23 @@
6 6  
7 7 // A class to model a tile which intersects another geometry
8 8 struct TileIntersection{
9   - std::string tile_name;
  9 + std::string tile_name;
10 10 double intersection_area;
11 11 otb::ogr::Feature tile_feature; //the tile itself
12 12 };
13 13  
14 14 // A type mapping a departement code to the list of tiles which
15 15 // intersect the department
16   -using DeptToTiles = std::unordered_map<std::string, std::vector<TileIntersection>>;
  16 +using DeptToTiles = std::unordered_map<std::string,
  17 + std::vector<TileIntersection>>;
17 18  
18 19 // Given an ogr data source containing the departements and another
19 20 // one containing the S2 tiles, build the map of intersecting tiles
20 21 // per dept
21   -DeptToTiles get_intersecting_tiles(otb::ogr::DataSource::Pointer& polygon_source,
  22 +DeptToTiles
  23 +get_intersecting_tiles(otb::ogr::DataSource::Pointer& polygon_source,
22 24 otb::ogr::DataSource::Pointer& tile_source)
23 25 {
24   -
25 26 DeptToTiles result{};
26 27 auto polys = get_features(polygon_source);
27 28 auto tiles = get_features(tile_source);
... ... @@ -33,10 +34,10 @@ DeptToTiles get_intersecting_tiles(otb::ogr::DataSource::Pointer&amp; polygon_source
33 34 for(const auto& tile : tiles)
34 35 {
35 36 auto code_tile = tile["Name"].GetValue<std::string>();
36   - auto tile_geo = tile.GetGeometry();
  37 + auto tile_geo = tile.GetGeometry();
37 38 if(dept_geo->Intersects(tile_geo))
38 39 {
39   - auto ti = TileIntersection{code_tile,
  40 + auto ti = TileIntersection{code_tile,
40 41 get_area(dept_geo->Intersection(tile_geo)),
41 42 tile};
42 43 result[code_dept].emplace_back(ti);
... ... @@ -73,7 +74,8 @@ using AreaPerTilePerDept = std::unordered_map&lt;std::string, AreaPerTile&gt;;
73 74 // result is the total area per tile.
74 75 AreaPerTile compute_area_per_tile(otb::ogr::DataSource::Pointer& polygon_source,
75 76 std::vector<TileIntersection>& tiles,
76   - std::vector<std::string> culture_patterns = {"_BLE_"})
  77 + std::vector<std::string>
  78 + culture_patterns = {"_BLE_"})
77 79 {
78 80 auto polys = get_features(polygon_source);
79 81 AreaPerTile result;
... ... @@ -89,10 +91,10 @@ AreaPerTile compute_area_per_tile(otb::ogr::DataSource::Pointer&amp; polygon_source,
89 91 {
90 92 auto tile = t.tile_feature;
91 93 auto code_tile = tile["Name"].GetValue<std::string>();
92   - auto tile_geo = tile.GetGeometry();
  94 + auto tile_geo = tile.GetGeometry();
93 95 if(parcelle_geom->Within(tile_geo))
94 96 {
95   - if(result.find(code_tile) == result.end())
  97 + if(result.find(code_tile) == result.end())
96 98 { result[code_tile] = 0;}
97 99 result[code_tile] += get_area(parcelle_geom);
98 100 }
... ... @@ -104,7 +106,8 @@ AreaPerTile compute_area_per_tile(otb::ogr::DataSource::Pointer&amp; polygon_source,
104 106 }
105 107  
106 108 // Utility to print the total areas per dept and per tile
107   -void print_total_areas(AreaPerTilePerDept aptpd, std::ostream& stream = std::cout)
  109 +void print_total_areas(AreaPerTilePerDept aptpd,
  110 + std::ostream& stream = std::cout)
108 111 {
109 112 for(const auto& dept : aptpd)
110 113 {
... ...
include/ogr_utils.h
... ... @@ -31,7 +31,8 @@ std::vector&lt;Field&gt; get_fields(const otb::ogr::Layer&amp; layer)
31 31 }
32 32  
33 33 // Return the fields of the ogr data source for a particular layer
34   -std::vector<Field> get_fields(otb::ogr::DataSource::Pointer &source, int layer_id=0)
  34 +std::vector<Field> get_fields(otb::ogr::DataSource::Pointer &source,
  35 + int layer_id=0)
35 36 {
36 37 return get_fields(source->GetLayer(layer_id));
37 38 }
... ... @@ -40,7 +41,7 @@ std::vector&lt;Field&gt; get_fields(otb::ogr::DataSource::Pointer &amp;source, int layer_i
40 41 bool has_field(const otb::ogr::Layer& layer, std::string field_name)
41 42 {
42 43 auto fields = get_fields(layer);
43   - return find_if(cbegin(fields), cend(fields),
  44 + return find_if(cbegin(fields), cend(fields),
44 45 [&field_name](auto f){
45 46 return field_name == f.name;
46 47 })!=cend(fields);
... ... @@ -48,7 +49,7 @@ bool has_field(const otb::ogr::Layer&amp; layer, std::string field_name)
48 49  
49 50 // Check if an ogr data source has a field with the given name in a
50 51 // given layer. Case sensitive.
51   -bool has_field(otb::ogr::DataSource::Pointer &source, std::string field_name,
  52 +bool has_field(otb::ogr::DataSource::Pointer &source, std::string field_name,
52 53 int layer_id=0)
53 54 {
54 55 return has_field(source->GetLayer(layer_id), field_name);
... ... @@ -63,13 +64,15 @@ std::vector&lt;std::string&gt; get_field_names(const otb::ogr::Layer&amp; layer)
63 64 }
64 65  
65 66 // Returns the field names in a layer of an ogr data source
66   -std::vector<std::string> get_field_names(otb::ogr::DataSource::Pointer &source, int layer_id=0)
  67 +std::vector<std::string> get_field_names(otb::ogr::DataSource::Pointer &source,
  68 + int layer_id=0)
67 69 {
68 70 return get_field_names(source->GetLayer(layer_id));
69 71 }
70 72  
71 73 // Prints the field names in a layer
72   -void print_fields_in_layer(otb::ogr::Layer& layer, std::ostream& stream = std::cout)
  74 +void print_fields_in_layer(otb::ogr::Layer& layer,
  75 + std::ostream& stream = std::cout)
73 76 {
74 77 for(const auto& f : get_fields(layer))
75 78 {
... ... @@ -87,7 +90,8 @@ void print_fields(otb::ogr::DataSource::Pointer &amp;source, int layer_id=0,
87 90  
88 91  
89 92 // 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)
  93 +std::vector<otb::ogr::Feature>
  94 +get_features(otb::ogr::DataSource::Pointer& source)
91 95 {
92 96 std::vector<otb::ogr::Feature> result;
93 97 otb::ogr::Layer layer = source->GetLayer(0);
... ... @@ -101,7 +105,8 @@ std::vector&lt;otb::ogr::Feature&gt; get_features(otb::ogr::DataSource::Pointer&amp; sourc
101 105  
102 106 // Reprojects the source geometries on to the proj_ref projection and
103 107 // returns a new data source
104   -otb::ogr::DataSource::Pointer reproject_geometries(otb::GeometriesSet::Pointer& source, std::string proj_ref)
  108 +otb::ogr::DataSource::Pointer
  109 +reproject_geometries(otb::GeometriesSet::Pointer& source, std::string proj_ref)
105 110 {
106 111 auto reprojVector = otb::ogr::DataSource::New();
107 112 auto outputGeomSet = otb::GeometriesSet::New(reprojVector);
... ...
src/select.cxx
... ... @@ -5,7 +5,7 @@
5 5 int main()
6 6 {
7 7 std::string s2_tiles_shp{"/home/inglada/stok/DATA/iota2/S22017/Features.shp"};
8   - std::string departements_shp{"/home/inglada/stok/DATA/departements_shp/"
  8 + std::string departements_shp{"/home/inglada/stok/DATA/departements_shp/"
9 9 "departements_lambert93.shp"};
10 10 std::string shape_dir{"/home/inglada/stok/DATA/OSO/MAA_SSP/"};
11 11 std::vector<std::string> cultures_rendement{"_BLE_DUR"};
... ... @@ -19,7 +19,7 @@ int main()
19 19 print_dept_tiles(tile_list);
20 20  
21 21 AreaPerTilePerDept aptpd{};
22   - for(const auto& f : cbutils::file::list_files(shape_dir,
  22 + for(const auto& f : cbutils::file::list_files(shape_dir,
23 23 ".*RPG_TERLAB_DEP.*_2017.7z"))
24 24 {
25 25 std::cout << "Unzipping " << f << '\n';
... ... @@ -34,14 +34,17 @@ int main()
34 34 {
35 35 auto parc_geometries = otb::GeometriesSet::New(parcelles);
36 36 auto parcs = reproject_geometries(parc_geometries,
37   - s2_tiles->GetLayer(0).GetProjectionRef());
  37 + s2_tiles->
  38 + GetLayer(0).GetProjectionRef());
38 39  
39 40 std::cout << "Departement " << code_dept << '\n';
40   - auto apt = compute_area_per_tile(parcs, tile_list[code_dept],
  41 + auto apt = compute_area_per_tile(parcs, tile_list[code_dept],
41 42 cultures_rendement);
42 43 aptpd[code_dept] = apt;
43 44 }
44   - auto files_to_remove = std::string("."+cbutils::string::split(shape, ".")[1]+".*");
  45 + auto files_to_remove = std::string("."+
  46 + cbutils::string::split(shape, ".")[1]
  47 + +".*");
45 48 std::cout << "Remove " << files_to_remove << '\n';
46 49 cbutils::system::call("rm -f "+files_to_remove);
47 50 }
... ... @@ -49,8 +52,8 @@ int main()
49 52 std::ofstream outfile("/tmp/stats.txt");
50 53 print_total_areas(aptpd, outfile);
51 54 auto bt = best_tile_dept(aptpd);
52   - std::cout << "Best tile: " << bt.tile_name << " in Departement " << bt.code_dept << '\n';
  55 + std::cout << "Best tile: " << bt.tile_name << " in Departement "
  56 + << bt.code_dept << '\n';
53 57  
54 58 return EXIT_SUCCESS;
55 59 }
56   -
... ...