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

Handle mix of sf and sp classes in filter_spatial() #1

Open
dholstius opened this issue May 11, 2020 · 0 comments
Open

Handle mix of sf and sp classes in filter_spatial() #1

dholstius opened this issue May 11, 2020 · 0 comments

Comments

@dholstius
Copy link
Member

dholstius commented May 11, 2020

Tests in tests/testthat/test-filter_spatial() are not currently passing. To run them: test(filter = "filter_spatial"). Here are two key pieces of the output:

test-filter_spatial.R:31: error: Alameda County (sp)
no applicable method for 'st_transform' applied to an object of class "c('SpatialPolygonsDataFrame', 'SpatialPolygons', 'Spatial', 'SpatialPolygonsNULL', 'SpatialVector')"
Backtrace:
  1. testthat::expect_success(...) tests/testthat/test-filter_spatial.R:31:2
  2. mapview::mapview(test_tracts)
 10. mapview::addFeatures(., ALA_county_WGS84, fill = FALSE, color = "red")
 16. leafem::addFeatures(map = map, data = data, pane = pane, ...)
 17. sf::st_transform(data, sf::st_crs(map@object[[1]]))
test-filter_spatial.R:76: error: Richmond CARE Impact Region
unable to find an inherited method for function 'proj4string' for signature '"sf"'
Backtrace:
 1. testthat::expect_message(...) tests/testthat/test-filter_spatial.R:76:2
 6. geotools::filter_spatial(spobj1, spobj2)
 7. geotools::filter_spatial_sp(x, y, FUN = FUN, ..., verbose = verbose) R/filter_spatial.R:26:4
 8. sp::proj4string(spobj2) R/filter_spatial.R:92:2

It might be necessary to either:

  • Make filter_spatial(spobj1, spobj2, ...) an S4 method, so that it dispatches based on the class of both spobj1 and spobj2; or
  • Retain it as an S3 method — dispatching only on the class of spobj1 — but put some if ... else logic inside filter_spatial() to coerce the class of spobj2 to the class of spobj1, before it dispatches to either filter_spatial_sp() or filter_spatial_sf(), either of which should expect both spobj1 and spobj2 to be of the same class.
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