An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20110907/05a297b0/attachment.pl>
rgeos 'union' causes R crash
2 messages · Ben Weinstein, Colin Rundel
Hi Ben, My best guess based on the information you have provided is that R is running out of memory, particularly for complex polygons Unions can use a huge amount of memory. Can you check with the task manager what the memory usage looks like when running your code? -Colin
On Sep 7, 2011, at 8:26 AM, Ben Weinstein wrote:
Hi all-
I'm having an odd issue with the gUnion family of commands from the rgeos
package. I'm importing a series of polygons (species) and trying to find the
centroid. Each species is only allowed one centroids, so i need to union the
multiple polygons. this code works great when run line by line. But when run
as an actual loop, but adding the {} at beginning and end, it gives me a
runtime error. I have debugged it to the level that i know it is the union
polygon step. I am running R 2.13, and it was designed for 2.13.1, is that
really making the difference? When run, R completely freezes and windows
shuts it down.
library(rgdal)
library(PBSmapping)
library(maptools)
library(raster)
library(rgeos)
#Enter File Directory Below
setwd("D:/Ben/R/Trochilidae")
#Pull in all shapefiles in that folder that are polygons
a<-list.files(pattern='pl.shp$', full.names=FALSE)
output<-matrix(nrow=length(a),ncol=3)
colnames(output)<-c("Sci_Name","X_centroid","Y_centroid")
for(x in 1:length(a)){
output[(x),1]<-paste(gsub(".shp","",a[x]))
range<-readShapePoly(a[x], delete_null_obj=TRUE)
subsetx<-range[range$PRESENCE == 1,]
subsetx2<-subsetx[subsetx$ORIGIN ==1|subsetx$ORIGIN==2,]
z<-matrix(length(subsetx2),1, data=1)
Union<-unionSpatialPolygons(subsetx2,z)
Breeding.ps<- SpatialPolygons2PolySet(Union)
Breeding.centroids<- calcCentroid(Breeding.ps, rollup=1)
output[x,2:3]<-as.matrix(Breeding.centroids[2:3])}
thanks
ben weinstein
--
Ben Weinstein
Graduate Student
Ecology and Evolution
Stony Brook University
[[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo