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

Error message when running readme #25

Closed
Robinlovelace opened this issue Feb 2, 2021 · 5 comments
Closed

Error message when running readme #25

Robinlovelace opened this issue Feb 2, 2021 · 5 comments

Comments

@Robinlovelace
Copy link
Member

I get this:

image

@Robinlovelace
Copy link
Member Author

Reproducible example:

remotes::install_github("itsleeds/slopes")
#> Using github PAT from envvar GITHUB_PAT
#> Skipping install of 'slopes' from a github remote, the SHA1 (4e2ebc5f) has not changed since last install.
#>   Use `force = TRUE` to force installation
library(slopes)
lisbon_route_3d_auto = slope_3d(r = lisbon_route)
#> Loading required namespace: ceramic
#> Error in find_xy_cols(obj): Unable to determine longitude and latitude columns; perhaps try re-naming columns.

Created on 2021-02-02 by the reprex package (v1.0.0)

@Robinlovelace
Copy link
Member Author

Going to try running the contents of the function line-by-line:

slope_3d = function(r, e = NULL, method = "bilinear", terra = has_terra() && methods::is(e, "SpatRaster")) {
  # if("geom" %in% names(r)) {
  #   rgeom = r$geom
  # } else if("geometry" %in% names(r)) {
  #   rgeom = r$geometry
  # } else {
  #   rgeom = sf::st_geometry(r)
  # }
  if(is.null(e)) {
    e = elevations_get(r)
    r_original = r # create copy to deal with projection issues
    r = sf::st_transform(r, raster::crs(e))
    suppressWarnings({sf::st_crs(r) = sf::st_crs(r_original)})
    # plot(e)
    # plot(r$geometry, add = TRUE)
    m = sf::st_coordinates(r)
    mo = sf::st_coordinates(r_original)
    z = as.numeric(elevation_extract(m, e, method = method, terra = terra))
    m_xyz = cbind(mo[, 1:2], z)
  } else {
    m = sf::st_coordinates(r)
    z = as.numeric(elevation_extract(m, e, method = method, terra = terra))
    m_xyz = cbind(m[, 1:2], z)
  }
  n = nrow(r)

  if(n == 1) {
    # currently only works for 1 line, to be generalised

    rgeom3d_line = sf::st_linestring(m_xyz)
    rgeom3d_sfc = sf::st_sfc(rgeom3d_line, crs = sf::st_crs(r))
    # message("Original geometry: ", ncol(rgeom[[1]]))
    sf::st_geometry(r) = rgeom3d_sfc
    # message("New geometry: ", ncol(r$geom[[1]]))
  } else {
    linestrings = lapply(seq(n), function(i){
      rgeom3d_line = sf::st_linestring(m_xyz[m[, 3] == i, ])
    })
    rgeom3d_sfc = sf::st_sfc(linestrings, crs = sf::st_crs(r))
    sf::st_geometry(r) = rgeom3d_sfc
  }
  r
}

@Robinlovelace
Copy link
Member Author

Seems it's an issue with elevations_get():

# slope_3d = function(r, e = NULL, method = "bilinear", terra = has_terra() && methods::is(e, "SpatRaster")) {

r = slopes::lisbon_route
method = "bilinear"
terra = FALSE

  # if("geom" %in% names(r)) {
  #   rgeom = r$geom
  # } else if("geometry" %in% names(r)) {
  #   rgeom = r$geometry
  # } else {
  #   rgeom = sf::st_geometry(r)
  # }
  # if(is.null(e)) {
    e = elevations_get(r)
#> Error in elevations_get(r): could not find function "elevations_get"

Created on 2021-02-02 by the reprex package (v1.0.0)

@Robinlovelace
Copy link
Member Author

And from that it seems the error is:

r = slopes::lisbon_route
mid_ext = slopes:::sf_mid_ext_lonlat(r)
#> Error in find_xy_cols(obj): Unable to determine longitude and latitude columns; perhaps try re-naming columns.

Created on 2021-02-02 by the reprex package (v1.0.0)

@Robinlovelace
Copy link
Member Author

And from that function...

r = slopes::lisbon_route
# mid_ext = slopes:::sf_mid_ext_lonlat(r)
res = list()
if(!sf::st_is_longlat(r)) {
  r = sf::st_transform(r, 4326)
}
bb = sf::st_bbox(r)
res$midpoint = c(mean(c(bb[1], bb[3])), mean(c(bb[2], bb[4])))
res$width = geodist::geodist(c(bb[1], bb[2]), c(bb[3], bb[2]))
res$height = geodist::geodist(c(bb[1], bb[2]), c(bb[1], bb[4]))
r = slopes::lisbon_route
r = sf::st_transform(r, 4326)
bb = sf::st_bbox(r)
geodist::geodist(c(bb[1], bb[2]), c(bb[3], bb[2]))
#>          [,1]
#> [1,] 1329.777
geodist::geodist(c(bb[1], bb[2]), c(bb[1], bb[4]))
#> Error in find_xy_cols(obj): Unable to determine longitude and latitude columns; perhaps try re-naming columns.

Created on 2021-02-02 by the reprex package (v1.0.0)

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

No branches or pull requests

1 participant