parser_test.cpp
Go to the documentation of this file.
1 //=============================================================================
2 // Copyright (C) 2021-2024 Wageningen University - All Rights Reserved
3 // Author: Gonzalo Mier
4 // BSD-3 License
5 //=============================================================================
6 
7 
8 #include <gtest/gtest.h>
12 
13 TEST(fields2cover_utils_parser, import_gml) {
14  F2CFields fields;
15 
16  f2c::Parser::importGml(std::string(DATA_PATH) + "test1.xml",
17  fields);
18 
19  EXPECT_EQ(fields[0].getId(), "b913fe9d-ed9f-4cc4-aa77-a10652165455");
20  EXPECT_EQ(fields[0].getCRS(), "EPSG:4258");
21 }
22 
23 TEST(fields2cover_utils_parser, get_area_imported) {
24  F2CFields fields;
25  f2c::Parser::importGml(std::string(DATA_PATH) + "test1.xml", fields);
26  f2c::Transform::transform(fields[0], "EPSG:28992");
27  EXPECT_NEAR(fields[0].area(), 10000.0 * 17.2581, 5.0);
28 }
29 
30 TEST(fields2cover_utils_parser, file_not_found) {
31  F2CFields fields;
32  EXPECT_THROW(f2c::Parser::importGml("file_not_found.xml",
33  fields), std::invalid_argument);
34 }
35 
36 
37 TEST(fields2cover_utils_parser, import_json) {
38  // Need more complex tests
39  F2CFields fields;
40  f2c::Parser::importJson(std::string(DATA_PATH) + "test.json", fields);
41  auto field = fields[0];
42  field.setEPSGCoordSystem(4326);
43 
44  f2c::Transform::transform(field, "UTM:32N datum:etrs89");
45 
46  EXPECT_EQ(field.getId(), "test parcel");
47  EXPECT_EQ(field.getCRS(), "UTM:32N datum:etrs89");
48 }
49 
50 TEST(fields2cover_utils_parser, import_json_two_cells) {
51  F2CFields fields;
52  f2c::Parser::importJson(std::string(DATA_PATH) + "test_2_cell.json", fields);
53  EXPECT_EQ(fields.size(), 2);
54  EXPECT_EQ(fields[0].getId(), "field1");
55  EXPECT_EQ(fields[1].getId(), "field2");
56  EXPECT_GT(fields[0].area(), 0);
57  EXPECT_GT(fields[1].area(), 0);
58 }
59 
60 TEST(fields2cover_utils_parser, import_cell_json) {
61  F2CCell cell;
62  cell = f2c::Parser::importCellJson(std::string(DATA_PATH) + "test.json");
63  EXPECT_EQ(cell.size(), 1);
64  EXPECT_EQ(cell.getGeometry(0).size(), 20);
65  EXPECT_GT(cell.area(), 0);
66 }
67 
68 TEST(fields2cover_utils_parser, import_strips_json) {
69  F2CStrips strips = f2c::Parser::importStripsJson(std::string(DATA_PATH) + "strips.geojson");
70  EXPECT_EQ(strips.size(), 3);
71  EXPECT_EQ(strips[0].getName(), "Winter barley");
72  EXPECT_EQ(strips[1].getName(), "Potato (late)");
73  EXPECT_GT(strips[0].getCell().area(), 0);
74  EXPECT_GT(strips[1].getCell().area(), 0);
75  EXPECT_NE(strips[0].getCell().area(), strips[1].getCell().area());
76 }
77 
78 TEST(fields2cover_utils_parser, import_swaths_json) {
79  F2CSwaths swaths = f2c::Parser::importSwathsJson(std::string(DATA_PATH) + "swaths.geojson");
80  EXPECT_EQ(swaths.size(), 3);
81  EXPECT_EQ(swaths[0].getWidth(), 0.3);
82  EXPECT_EQ(swaths[1].getWidth(), 0.3);
83  EXPECT_EQ(swaths[0].getId(), 44);
84  EXPECT_EQ(swaths[1].getId(), 25);
85  EXPECT_GT(swaths[0].length(), 0);
86  EXPECT_GT(swaths[1].length(), 0);
87  EXPECT_NE(swaths[0].length(), swaths[1].length());
88 }
89 
90 TEST(fields2cover_utils_parser, import_json_ring) {
91  F2CFields fields;
92  f2c::Parser::importJson(std::string(DATA_PATH) + "test_ring.json", fields);
93  EXPECT_EQ(fields.size(), 1);
94  EXPECT_EQ(fields[0].getId(), "Ring");
95  EXPECT_EQ(fields[0].area(), 10*10 - 8*8);
96 }
97 
5_route_planning.swaths
swaths
Definition: 5_route_planning.py:58
TEST
TEST(fields2cover_utils_parser, import_gml)
Definition: parser_test.cpp:13
transformation.h
f2c::Transform::transform
static void transform(F2CField &field, const std::string &coord_sys_to)
Definition: transformation.cpp:20
1_basic_types.cell
cell
Definition: 1_basic_types.py:88
F2CStrips
std::vector< F2CStrip > F2CStrips
Definition: types.h:57
f2c::Parser::importGml
static void importGml(const std::string &file, F2CFields &fields)
Definition: parser.cpp:17
f2c::Parser::importStripsJson
static F2CStrips importStripsJson(const std::string &file)
Definition: parser.cpp:141
f2c::types::Cell
Definition: Cell.h:32
visualizer.h
f2c::Parser::importSwathsJson
static F2CSwaths importSwathsJson(const std::string &file)
Definition: parser.cpp:125
f2c::Parser::importJson
static int importJson(const std::string &file, F2CFields &fields)
Definition: parser.cpp:107
parser_test.DATA_PATH
string DATA_PATH
Definition: parser_test.py:10
F2CFields
std::vector< F2CField > F2CFields
Definition: types.h:58
parser.h
2_objective_functions.field
field
Definition: 2_objective_functions.py:16
f2c::Parser::importCellJson
static F2CCell importCellJson(const std::string &file)
Definition: parser.cpp:119
f2c::types::Swaths
Definition: Swaths.h:20


fields2cover
Author(s):
autogenerated on Fri Apr 25 2025 02:18:31