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

mapview for inherited classes #475

Closed
bart1 opened this issue Mar 20, 2024 · 4 comments
Closed

mapview for inherited classes #475

bart1 opened this issue Mar 20, 2024 · 4 comments

Comments

@bart1
Copy link

bart1 commented Mar 20, 2024

It seems that classes that inherit sf do not get recognized by mapview. In my case the move2 class (representing movement data) . It would be great to have mapview work for inherited classes, is there some way of achieving this? Alternative a separate method can be set (e.g. setMethod('mapView', signature(x = 'move2'), .sf_method), however that seems a less general solution. If desirable I can provide a patch for the later solution.

Current error:

require(mapview)
#> Loading required package: mapview
#> The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
#> which was just loaded, will retire in October 2023.
#> Please refer to R-spatial evolution reports for details, especially
#> https://r-spatial.org/r/2023/05/15/evolution4.html.
#> It may be desirable to make the sf package available;
#> package maintainers should consider adding sf to Suggests:.
#> The sp package is now running under evolution status 2
#>      (status 2 uses the sf package in place of rgdal)
require(move2)
#> Loading required package: move2
data<-mt_read(mt_example())[1:100,]
mapview(data)
#> Error in (function (classes, fdef, mtable) : unable to find an inherited method for function 'mapView' for signature '"move2"'
@bart1
Copy link
Author

bart1 commented Mar 20, 2024

Now thinking a bit more about it maybe a ANY methods can be used to dispatch to inherited classes?

@tim-salabim
Copy link
Member

Could the method be defined in move2?

@edzer
Copy link
Member

edzer commented Mar 20, 2024

mapview dispatches to mapView which has methods for classes. As it uses S4, S3 classes need to be declared as such. Did you set setOldClass("move2") in the packages?

@bart1
Copy link
Author

bart1 commented Mar 21, 2024

@edzer thank you for the hint, I already had set setOldClass("move2") that did not do the trick but diving a bit deeper into it if I set setOldClass(c("move2","sf")) that seems to work. I will check that is does not have unintended consequences but that seems quite a general solution to make many sf methods work.

@bart1 bart1 closed this as completed Mar 21, 2024
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

3 participants