[R-sig-Geo] Polygon area in a grid cell/ Progress bar

Angelika Gummert Angelika.Gummert at gmx.de
Thu Jun 25 09:37:55 CEST 2015


Hi,

I want to calculate the area of my polygons in each grid cell. I tried to
follow this example
https://stat.ethz.ch/pipermail/r-sig-geo/2014-December/022096.html  (I don't
know if this is the right method),but I am unable to intersect my polygons
because it is always running for hours and when I want to stop the
calculation its crashing. I don't know if it is actually working or not
(perhaps it is always crashing right at the beginning) : is there a way to
see if R is working? Something like a progress bar? I tried to look into it
and found something like this: txtProgressBar(min = 0, max = numberSteps,
style = 3) but I am not able to include this in the function. Perhaps you
can tell me how to do it? I am afraid that my polygons are too big for this
calculation or that there are too many polygons (http://data.unep-wcmc.org/
the magroves in the Caribbean). I tried to "simplify" the polygon using
gSimplify() but it is not working either way. Here is what I did. 

 

#creating grid

 

bb <- bbox(Caribbean)   #shapefile of the Caribbean

cs <- c(1, 1)*2 # cell size 

 

cc <- bb[, 1] + (cs/2)  # cell offset

cd <- ceiling(diff(t(bb))/cs)  # number of cells per direction

grd <- GridTopology(cellcentre.offset=cc, cellsize=cs, cells.dim=cd)

grd

 

sp_grd <- SpatialGridDataFrame(grd,

                               data=data.frame(id=1:prod(cd)),

                              proj4string=CRS(proj4string(Caribbean)))

 

 

#transform the grid into a Polygon

 

sp_grdSP <-as(sp_grd,"SpatialPolygons") 

 

 

#Simplify SpatialPolygonsDataFrame

 

Simple <- gSimplify(Data,tol = 0.0001,)    # the output Simple is a
SpatialPolygon

 

 

#intersect both polygons

 

crs(sp_grdSP)<-crs(Simple)

 

Intersection<-intersect(sp_grdSP,Simple)

 

.working.working...working.

 

Is there something wrong with the calculation or with my data? I will try to
run the calculation again over the weekend, but I don't think it will work.

It would be great if someone could help me with this problem.

 

With best regards,

A.G.

 

 

 

 

 

 


	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list