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

Upcoming maptools retirement #5244

Closed
yutannihilation opened this issue Mar 22, 2023 · 12 comments
Closed

Upcoming maptools retirement #5244

yutannihilation opened this issue Mar 22, 2023 · 12 comments

Comments

@yutannihilation
Copy link
Member

A year ago, R-spatial announced rgdal, rgeos, and maptools will retire by the end of 2023.

https://r-spatial.org//r/2022/04/12/evolution.html

ggplot2 doesn't use rgdal, and just removed rgeos in #5242. However, maptools is still used in fortify.SpatialPolygonsDataFrame() (and the examples section of the document).

unioned <- maptools::unionSpatialPolygons(cp, attr[, region])

We need to decide how to deal with this. I think we have several options:

  1. Replace maptools::unionSpatialPolygons() with sf functions (convert to an sf object, transform it and convert back to an sp object)
  2. Remove the functionality related to maptools::unionSpatialPolygons()
  3. Drop fortify() methods for sp objects altogether
@thomasp85
Copy link
Member

I'm fine with either 1 or 3

The only argument for 1 is to preserve the function of very old code as I assume everyone has moved to sf by now

@yutannihilation
Copy link
Member Author

@hadley
Copy link
Member

hadley commented Jun 7, 2023

I think we can drop it. We should schedule this for the next release.

@yutannihilation
Copy link
Member Author

Thanks, let's drop it.

Note that the reason I couldn't decide is that I was afraid this assumption

everyone has moved to sf by now

might not be really true. For example, I read a book about spatial statistics using R, which was published in 2022, and it still uses rgoes and rgdal in several places although it primarily uses sf. I thought this probably means, even if the internal implementations were already replaced with sf, these longstanding packages might still generate the result as sp (I'm not familiar with spatial statistics, so I'm not sure).

But, converting an sp object to sf should be easy, and the sp ecosystem is about to retire anyway. So, it's probably time to drop it.

@hadley
Copy link
Member

hadley commented Jun 8, 2023

Alternatively, if ggplot2 still has a sf dependency, we could switch to sf::st_union() instead. Or maybe fortify.SpatialPolygonsDataFrame() could convert to an sf object and then fortify that?

@thomasp85
Copy link
Member

Agreed - leaning heavily into dropping it

@Ludecan
Copy link

Ludecan commented Nov 27, 2023

Hey there. I'm currently maintaining a very old spatial data codebase that heavily used sp for spatial data manipulation and ggplot2 for plotting. As a part of it I did both plots of point and raster data while plotting using a background shapefile like this:
redesDisponibles

I have several functions (one for points, one for points + text, one for rasters) that plot the data using custom x and y aesthetics and then plot the shapefile on top. To plot the base shapefile I'm using a single function that serves all 3 methods and uses fortify on a SpatialPolygonsDataFrame.

I take it it's because of this? Would it be possible to implement the functionality using sf as you suggest?
Or is there a way I can implement an alternative version of it in my codebase?
Thanks in advance

@teunbrand
Copy link
Collaborator

I think the recommendation from r-spatial is to move away from {sp} in favour of {sf}. More information can be found in the readme of https://github.com/r-spatial/evolution with various links to other places.

@Ludecan
Copy link

Ludecan commented Nov 27, 2023

Yes, will definitely try to go that way, but this is an older codebase that is currently in maintenance mode, it's going to be a major change to migrate all of it to sf. I will try to start doing it gradually but it's not going to be an easy task.

@hadley
Copy link
Member

hadley commented Nov 27, 2023

@Ludecan if it's in maintenance mode, you could use renv::snapshot() to capture all the dependencies as of a certain date, and just continue to use sp.

@Ludecan
Copy link

Ludecan commented Nov 30, 2023

@Ludecan if it's in maintenance mode, you could use renv::snapshot() to capture all the dependencies as of a certain date, and just continue to use sp.

Thanks @hadley, I tried your suggestion and it worked fine.

Then I realized I don't need to fortify the entire SpatialPolygonsDataFrame but rather only it's geometry, which is a SpatialPolygons object for which fortify doesn't seem to use maptools. This was the only use in my codebase so I dropped the dependency altogether.

I'll get into removing usage of rgdal and rgeos from the rest of my code but this will give me some time to do so.
Thanks for your help!

@teunbrand
Copy link
Collaborator

Closing this as fixed by #5327.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants