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@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo