rcrashpolygonr-raster

RasterToPolygon works slow, then stop working


I have a problem to process rasters in R, even if I've done it previously. I can read the data and plot them:

enter image description here

however, when I tried to convert my raster to polygon, the R stops working

enter image description here

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. Do you have some suggestions how to solve the problem?

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)

Solution

  • 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..