Skip to content

Bring data from a field's original CRS into its own frame - #259

Merged
Gonzalo-Mier merged 2 commits into
Fields2Cover:developfrom
u33549:dev/umutc/v2.1.0-devel/ref-point-api
Nov 16, 2026
Merged

Gonzalo-Mier merged 2 commits into
Fields2Cover:developfrom
u33549:dev/umutc/v2.1.0-devel/ref-point-api

Conversation

@u33549

@u33549 u33549 commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Transform can take a result out of a field's frame: transformToPrevCRS adds the reference point back and converts to the CRS the field came in, for a route, a path, a swath, a strip and their collections. There is no way back in. Data that arrives next to a field, such as the robot's start pose or a set of crop rows, comes in the field's original CRS, while the field works in its own CRS with the reference point taken out. Every caller converts and subtracts by hand.

opennav_coverage does it in two places: toFieldFrame for the start pose, and transformRowsWithRef with removeRowsRefPoint for the rows of opennav_row_coverage. The row pair dates from 2023, so this is not a gap only one caller ran into.

The API

/// Bring data given in the field's previous CRS into the field's own frame.
static F2CPoint transformToFieldCRS(const F2CPoint& p, const F2CField& field);
static F2CLineString transformToFieldCRS(const F2CLineString& line, const F2CField& field);

It converts from getPrevCRS() to getCRS() and takes out getRefPoint(). A field that was never transformed has no previous CRS; then only the reference point is taken out, which is what a caller in a local cartesian frame needs. The caller no longer has to tell the two cases apart, the field already knows which one it is in.

Both overloads share one body, built from what Transform and the geometry types already have: transform<T>(t, from, to) and T - Point.

Overloads rather than a template. transformToPrevCRS is written per type, so its inverse is too. It also keeps the function reachable from Python: the existing transform<T> template has no %template in Fields2Cover.i and cannot be called from Python today.

Two types. Point and LineString are the two the callers above need. A MultiPoint overload would mirror transformMultiPointWithFieldRef; I left it out until there is a caller, but it is one line if you would rather have it now.

The name mirrors transformToPrevCRS. Happy to change it if transformFromPrevCRS or something else reads better to you.

Tests

transform_test.cpp:

  • convert_to_field_crs_without_prev_crs: a field never transformed, (5, 5) maps to (0, 0) and (10, 8) to (5, 3), compared exactly.
  • convert_to_field_crs: a field in EPSG:4326 taken to UTM. Its border, run through the new function, has to come out as the border the field itself holds, since both went through the same projection. Also: the first corner maps to (0, 0), the input line is unchanged, and the point goes back out to where it started through the existing transform with the reference point.

The GPS comparisons cannot be exact and use a tolerance close to what was measured: the field added its reference point back before projecting, which rounds in the last digit (4e-14 m against the border, 4e-9 m at the corner, where two UTM northings of about 5.7e6 m are subtracted).

transform_test.py checks both cases from Python.

The first commit adds the tests with a body that hands its input back unchanged, so they fail on the numbers; the second fills it in. C++ 374 tests, Python 120, all passing.

Transform can take a result out of a field's frame but has no way back
in, so a start pose or a set of rows given in the field's original CRS
has to be converted and moved by the caller.

The function added here hands its input back, so the tests are red on
the numbers: a field never transformed only loses its reference point,
and a field taken to UTM has to give back the border it holds itself.
Convert from the field's previous CRS to its own and take out the
reference point, the inverse of transformToPrevCRS. A field that was
never transformed has no previous CRS, so only the reference point
goes, which is what a caller in a local cartesian frame needs.
Copilot AI balanced review requested due to automatic review settings November 13, 2026 23:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@Gonzalo-Mier

Copy link
Copy Markdown
Member

Thank you @u33549! Nice PR

@Gonzalo-Mier
Gonzalo-Mier merged commit 11e72c2 into Fields2Cover:develop Nov 16, 2026
69 of 70 checks passed
@u33549
u33549 deleted the dev/umutc/v2.1.0-devel/ref-point-api branch November 21, 2026 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants