问题
I have a problem to process rasters in R, even if I've done it previously. I can read the data and plot them:
however, when I tried to convert my raster to polygon, the R stops working
I've tried to update packages, re-install R, on OSX, on Windows 7, always with the same result.
Moreover, I've tried to set my projection to NA, but this neither helped. Did you ever experienced problem like this? Do you have some suggestions how to solve the problem? I highly appreciate any suggestions !
MY data are here: https://ulozto.sk/x4pHuyra/data-to-stack-zip
And my code:
library(sp)
library(raster)
library(rgeos)
library(spatstat)
library(rgdal)
library(maptools)
require(spdep)
# read final GFW raster - in JTSK
gfw_13<-raster("H:/.../gfw_ext_forest_03.tif")
projection(gfw_13)<-NA
# read shp
manag<-readOGR(dsn = "H:/...",
layer = "cleared_management_by_NP")
projection(manag)<-NA
# convert raster GFW to shp # !!!!! here it stops to work
pol.gfw<-rasterToPolygons(gfw_13, dissolve = T)
回答1:
I don't have 50 rep yet, so I can't add a comment, but have a look at this web-page. It deals with the rasterToPolygons
function, which I've always found to be mega-slow, and the author (John Baumgartner) offers a function of his to speed up the process. It takes about 1/7000th of the time, according to his tests.
回答2:
This doesn't solve the speed problem, but at least my processes run and R doesn't crashes... I need to define all arguments for rasterToPolygon
function:
pol.gfw <- rasterToPolygons(gfw_13, fun=NULL, n=4, na.rm=TRUE, digits=12, dissolve=TRUE)
Maybe the problem was due to abundant numbers of NA values in the original raster..
来源:https://stackoverflow.com/questions/37382238/r-rastertopolygon-works-slow-then-stop-working