Skip to content

Commit

Permalink
swath and swaths transform with reference points
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveMacenski committed Dec 17, 2023
1 parent 5fe6485 commit 945751d
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 4 deletions.
3 changes: 3 additions & 0 deletions include/fields2cover/types/Swath.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ struct Swath {
/// less than pi
void targetOppositeDirAs(const Swath& s);

/// Moves swath data by a reference point
void moveTo(const Point& ref_pt);

private:
int id_ {0}; // Id of the swath
LineString path_;
Expand Down
1 change: 1 addition & 0 deletions include/fields2cover/types/Swaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ struct Swaths {
double width = 0, SwathType type = SwathType::MAINLAND);
void sort();
void reverseDirOddSwaths();
void moveTo(const Point& ref_pt);

Swaths clone() const;

Expand Down
4 changes: 4 additions & 0 deletions include/fields2cover/utils/transformation.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class Transform {

static F2CPath transformPathWithFieldRef(const F2CPath& path,
const F2CField& field, const std::string& coord_sys_to);
static F2CSwath transformSwathWithFieldRef(const F2CSwath& swath,
const F2CField& field, const std::string& coord_sys_to);
static F2CSwaths transformSwathsWithFieldRef(const F2CSwaths& swaths,
const F2CField& field, const std::string& coord_sys_to);


static void transform(F2CField& field, const std::string& coord_sys_to);
Expand Down
6 changes: 5 additions & 1 deletion src/fields2cover/types/Swath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ void Swath::setType(SwathType type) {
this->type_ = type;
}

void Swath::moveTo(const Point& ref_pt) {
for (auto&& s : this->path_) {
s = s + ref_pt;
}
}

} // namespace f2c::types

5 changes: 5 additions & 0 deletions src/fields2cover/types/Swaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ Swaths Swaths::clone() const {
return new_s;
}

void Swaths::moveTo(const Point& ref_pt) {
for (auto&& s : data) {
s.moveTo(ref_pt);
}
}


} // namespace f2c::types
Expand Down
20 changes: 17 additions & 3 deletions src/fields2cover/utils/transformation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ F2CPath Transform::transformPathWithFieldRef(const F2CPath& path,
return new_path;
}

F2CSwath Transform::transformSwathWithFieldRef(const F2CSwath& swath,
const F2CField& field, const std::string& coord_sys_to) {
return F2CSwath(transform(swath.getPath(), field.getRefPoint(), field.getCRS(), coord_sys_to),
swath.getWidth(), swath.getId());
}

F2CSwaths Transform::transformSwathsWithFieldRef(const F2CSwaths& swaths,
const F2CField& field, const std::string& coord_sys_to) {
F2CSwaths new_swaths;
for (auto&& swath : swaths) {
new_swaths.emplace_back(
transformSwathWithFieldRef(swath, field, coord_sys_to));
}
return new_swaths;
}

F2CStrip Transform::transformStrip(const F2CStrip& strip,
const std::string& coord_sys_from, const std::string& coord_sys_to) {
Expand Down Expand Up @@ -88,7 +103,6 @@ F2CPath Transform::transformPath(const F2CPath& path,
return new_path;
}


void Transform::transformToUTM(F2CField& field, bool is_etrs89_opt) {
std::string field_crs = field.getCRS();
if (!field_crs.empty() && \
Expand Down Expand Up @@ -162,12 +176,12 @@ F2CStrips Transform::transformToPrevCRS(

F2CSwath Transform::transformToPrevCRS(
const F2CSwath& s, const F2CField& field) {
return transformSwath(s, field.getCRS(), field.getPrevCRS());
return transformSwathWithFieldRef(s, field, field.getPrevCRS());
}

F2CSwaths Transform::transformToPrevCRS(
const F2CSwaths& s, const F2CField& field) {
return transformSwaths(s, field.getCRS(), field.getPrevCRS());
return transformSwathsWithFieldRef(s, field, field.getPrevCRS());
}

F2CPoint Transform::getRefPointInGPS(const F2CField& field) {
Expand Down

0 comments on commit 945751d

Please sign in to comment.