Skip to content

Commit 13164ea

Browse files
authored
fix: throw an error when X and Y columns are present in an sf object (#96)
* fix: throw an error when X and Y columns are present in an sf object * ...
1 parent f8e4174 commit 13164ea

12 files changed

+49
-8
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Config/testthat/parallel: false
4949
Encoding: UTF-8
5050
LazyData: true
5151
Roxygen: list(markdown = TRUE)
52-
RoxygenNote: 7.3.1
52+
RoxygenNote: 7.3.2
5353
Collate:
5454
'DataBackendRaster.R'
5555
'DataBackendVector.R'

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# mlr3spatial (development version)
22

3+
* fix: Throw an error when `X` and `Y` columns are present in an sf object
4+
35
# mlr3spatial 0.5.0
46

57
* compatibility: Work with new paradox version 1.0.0

R/as_task_classif_st.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ as_task_classif_st.sf = function(x, target = NULL, id = deparse(substitute(x)),
5555
stop("Simple feature may not contain geometries of type '%s'", str_collapse(setdiff(geometries, "POINT")))
5656
}
5757

58+
if (any(c("X", "Y") %in% colnames(x))) {
59+
stopf("Data contains columns named 'X' and 'Y' which are reserved for coordinates. The sf object might contain coordinates in the geometry column and the `X` and `Y` columns. Please remove or rename them before converting to a task.")
60+
}
61+
62+
5863
# extract spatial meta data
5964
crs = sf::st_crs(x)$wkt
6065
coordinates = as.data.frame(sf::st_coordinates(x))

R/as_task_regr_st.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ as_task_regr_st.sf = function(x, target = NULL, id = deparse(substitute(x)), coo
5555
stop("Simple feature may not contain geometries of type '%s'", str_collapse(setdiff(geometries, "POINT")))
5656
}
5757

58+
if (any(c("X", "Y") %in% colnames(x))) {
59+
stopf("Data contains columns named 'X' and 'Y' which are reserved for coordinates. The sf object might contain coordinates in the geometry column and the `X` and `Y` columns. Please remove or rename them before converting to a task.")
60+
}
61+
5862
# extract spatial meta data
5963
crs = sf::st_crs(x)$wkt
6064
coordinates = as.data.frame(sf::st_coordinates(x))
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
#' @param coords_as_features (`logical(1)`)\cr
2-
#' If `TRUE`, coordinates are used as features.
2+
#' If `TRUE`, coordinates are used as features.
3+
#' This is a shortcut for `task$set_col_roles(c("x", "y"), role = "feature")` with the assumption that the coordinates in the data are named "x" and "y".

man/TaskClassifST.Rd

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/TaskRegrST.Rd

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/as_task_classif_st.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/as_task_regr_st.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/mlr3spatial-package.Rd

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)