Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transformers are using meta flags inconsistently when operating on coords #216

Closed
anthonynorth opened this issue Mar 6, 2024 · 1 comment · Fixed by #217
Closed

Transformers are using meta flags inconsistently when operating on coords #216

anthonynorth opened this issue Mar 6, 2024 · 1 comment · Fixed by #217

Comments

@anthonynorth
Copy link
Contributor

Transformers are using meta flags inconsistently when operating on coords.

wk/src/transform.c

Lines 152 to 164 in 67f7013

if (meta->flags & WK_FLAG_HAS_Z && meta->flags & WK_FLAG_HAS_M) {
trans_filter->xyzm_in[2] = coord[2];
trans_filter->xyzm_in[3] = coord[3];
} else if (meta->flags & WK_FLAG_HAS_Z) {
trans_filter->xyzm_in[2] = coord[2];
trans_filter->xyzm_in[3] = R_NaN;
} else if (new_meta->flags & WK_FLAG_HAS_M) {
trans_filter->xyzm_in[2] = R_NaN;
trans_filter->xyzm_in[3] = coord[2];
} else {
trans_filter->xyzm_in[2] = R_NaN;
trans_filter->xyzm_in[3] = R_NaN;
}

I think the bug is line 158, which tests for the m dimension being in the output. This results in garbage output in m dimension, when use_m = TRUE and input dimensions are xy. The below reprex shows what I mean.

If my understanding is correct, fix is a 1-liner.

wk::wk_transform(
  wk::xy(1,1),
  wk::wk_trans_set(wk::xy(1, 1), use_m = TRUE)
)
#> <wk_xym[1]>
#> [1] M (1 1 4.526213e-315)

wk::wk_transform(
  wk::xy(1,1),
  wk::wk_trans_set(wk::xy(1, 1), use_z = TRUE)
)
#> <wk_xyz[1]>
#> [1] Z (1 1 NaN)

wk::wk_transform(
  wk::xy(1,1),
  wk::wk_trans_set(wk::xy(1, 1), use_m = TRUE, use_z = TRUE)
)
#> <wk_xyzm[1]>
#> [1] ZM (1 1 NaN 2.359942e-312)

wk::wk_transform(
  wk::xy(1, 1),
  PROJ::proj_trans_create("OGC:CRS84", "EPSG:3857", use_m = TRUE)
)
#> <wk_xym[1]>
#> [1] M (111319.5 111325.1 2.359942e-312)

wk::wk_transform(
  wk::xy(1, 1),
  PROJ::proj_trans_create("OGC:CRS84", "EPSG:3857", use_z = TRUE)
)
#> <wk_xyz[1]>
#> [1] Z (111319.5 111325.1 NaN)

wk::wk_transform(
  wk::xy(1, 1),
  PROJ::proj_trans_create("OGC:CRS84", "EPSG:3857", use_z = TRUE, use_m = TRUE)
)
#> <wk_xyzm[1]>
#> [1] ZM (111319.5 111325.1 NaN 2.359942e-312)

Created on 2024-03-06 with reprex v2.0.2

anthonynorth added a commit to anthonynorth/wk that referenced this issue Mar 6, 2024
@paleolimbot
Copy link
Owner

Thank you for tracking this down!

paleolimbot pushed a commit that referenced this issue Mar 7, 2024
* fixes #216

* test wk_trans meta flags used consistently

* add news
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 a pull request may close this issue.

2 participants