I'm attempting to run some simple plots on some shapefiles with a high number of complex polygons. These aren't massive files - for the example below, the shapefile is 70mb (15872 obs), but plots, buffers, etc. are running extremely slowly, e.g. over an hour in some cases for a single relatively simple plot. Can anyone recommend some ways to optimise these operations? I cannot simplify the geometry of the polygons, as I need to ensure accuracy, but this seems to render R unworkable as a platform for reproducible geospatial research.
Download data as ESRI Shapefile from page at: https://gateway.snh.gov.uk/natural-spaces/dataset.jsp?dsid=SSSI
(install libraries and data ahead of execution)
require(RCurl) # used for fetching reproducible datasets require(sf) # new simplefeature data class, supercedes sp in many ways # using GEOS 3.6.1, GDAL 2.1.3, PROJ 4.9.3 require(sp) # needed for proj4string, deprecated by sf() require(rgdal) # version version: 1.3-6 require(rgeos) # used for buffering below require(devtools) require(ggplot) # Download data as ESRI Shapefile from page at: https://gateway.snh.gov.uk/natural-spaces/dataset.jsp?dsid=SSSI unzip("SSSI_SCOTLAND_ESRI.zip") sssi_sf <- st_read("SSSI_SCOTLAND.shp") sssi_sp <- readOGR("./", "SSSI_SCOTLAND") # First test out plots using spatialfeatures and spdf with core R system.time( plot(sssi_sf) ) system.time( plot(sssi_sp) ) # Then test out plots using spatialfeatures and spdf with ggplot2 system.time( ggplot() + geom_sf(data = sssi_sf) ) system.time( ggplot() + geom_polygon(data = sssi_sp) )
A few notes:
I've updated R and packages as of this morning, so am working with the latest versions (of pre-compiled binaries) of relevant libraries.
Also worth noting is that I've seen indications elsewhere that slow plots might be related to XQuartz limitations, but I've tested and confirmed that plots are terribly slow (> 1hr for
plot(sssi_sf) below for example) on both MacOS and Windows (running in virtualbox).