Speed-up time to plot Spatialpolygonsdataframe ext

2019-07-28 06:37发布

I am making plot in R of some SpatialPolygonDataFrames, but it takes forever. I needed three hours to save to a png the plot of one of these layers that has 314 elements and weights (as said by RStudio) 35 Mb. I do not know if that is a lot or not, but it does not take more than a fraction of a second to display it in a GIS software such as QGIS or ArcMap.
It makes so small sense that I wonder if this is how it is supposed to be or something is wrong in my setup. This is the code I am using, where APpat is a shapefile of protected areas

> library(rgdal)
> library(rasterVis)
> APpat <- readOGR("./PAT", "AP_PAT_edited1")
> PAT.alt <- raster("./altitude") # I plot the polygons over this raster, which is very light to plot on its own

# This is how APpat looks like
> APpat

class       : SpatialPolygonsDataFrame 
features    : 314 
extent      : -92.58878, -57.4542, -22.9007, 13.39352  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
variables   : 6
names       :   id,                    category,             name, year,   country,       IUCN 
min values  :    1, Area Nacional de Recreacion, Abra de Rio Frio, 1936,   Bolivia,          I 
max values  : SN09,                  Via Parque,           Yurubi, 2015, Venezuela, VI

# And then save the plot to png
> png(paste0("./ProtectedAreas.png"), width=1300, heigh=1300, res=300)
> levelplot(PAT.alt, margin=FALSE, 
        at=seq(0,6800, by=2000), 
        main=paste0("Protected areas, ", years[y]),
        par.settings=mytheme,
        xlab=NULL, ylab=NULL,
        contour = TRUE, col='dark green',
        colorkey=NULL) +
> layer(sp.polygons(myAP, lwd=0.8, col='black', fill="#fc9272"))
> par(cex=.7)
> dev.off()

It took 3 hours 7 minutes to plot. I have tried using normal plot instead of levelplot as well, with equivalent results. The same if I am not plotting the raster, but the polygons on their own.

> sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: macOS Sierra 10.12.4

I have installed XQuartz. I find similar times when just plotting inside RStudio and when saving the plot to a pdf file. Thanks for your help!

EDIT: This is the shapefile layer I am trying to plot: https://drive.google.com/open?id=0B0XRH7FN95-RSzFRckhXNjVWYlk

EDIT2: It is not a generalizable problem, seems to happen only to me. We were able to plot the figure in different machines in ~20 secs. Still, if someone has an idea what can be wrong with my computer, it will be much appreciated!

0条回答
登录 后发表回答