R/spatial_transformPoints.R

Defines functions transform_points

transform_points <- function(train_dta, new_dta, method = "stdPoly") {

  # Check data parameters:

  if (!assertthat::has_name(
    train_dta, c("x_source", "y_source", "x_map", "y_map"))) {
    stop("Error. The fields in train_dta do not comply with the requirements.")
  }

  if (!assertthat::has_name(
    new_dta, c("x_source", "y_source"))) {
    stop("Error. The fields in test_dta do not comply with the requirements.")

  }

  # Fit Transformation on  train_dta :


  if (method == "elasticnet") {



  } else if (method == "stdPoly") {

    model_x <-
      lm(formula = x_map ~
           poly(x_source, deg, raw = TRUE) +
           poly(y_source, deg, raw = TRUE) +
           poly(x_source * y_source, deg, raw = TRUE),
         data = train_dta)

    model_y <-
      lm(formula = y_map ~
           poly(x_source, deg, raw = TRUE) +
           poly(y_source, deg, raw = TRUE) +
           poly(x_source * y_source, deg, raw = TRUE),
         data = train_dta)

  }


  # Predict Values

  result_df <-
    tibble(
      map_x = predict(model_x, newdata = new_data),
      map_y = predict(model_y, newdata = new_data)
    )

  # Return

  return(result_df)

}
MKyhos/researchTools documentation built on April 14, 2020, 12:07 a.m.