Skip to content

generating object with multiple polygons

7 messages · Karla Shikev, Philippi, Tom, uzzal at gist.ac.kr +2 more

#
Dear all,

This might be a newbie question, so I'd appreciate your patience with this.

I'm obtaining climatic data from worldclim and generating polygons based on
different climatic limits:

library(raster)
xx<-getData('worldclim', var='bio', res=10)$bio1
slice1 <- rasterToPolygons(xx, fun = function(x) {x > 200 & x < 260})
slice2 <- rasterToPolygons(xx, fun = function(x) {x > 250 & x < 300})

Now, I'd like to combine "slice1" and "slice2" into the same
"SpatialPolygonsDataFrame" object, but I do not want to merge them.

Any help will be greatly appreciated.

Karla
#
Karla--
If you want a SpatialPolygonsDataFrame with both slices of polygons, you
can use spatial rbind.  The issue that may trip you up is that your slice1
and slice2 objects might not have unique polygon IDs.  Perhaps the simplest
solution is to use the spChFIDs in sp, with some prefix distinguishing
slice1 from slice2.  I assume you're generating some attributes as
variables in the data frame to distinguish the different polygons; you can
use those values as the prefix.  You can google this, or start with:
http://www.inside-r.org/packages/cran/sp/docs/as.data.frame.SpatialPolygonsDataFrame
http://gis.stackexchange.com/questions/32732/proper-way-to-rbind-spatialpolygonsdataframes-with-identical-polygon-ids

Tom 2
On Sun, Apr 3, 2016 at 6:53 AM, Karla Shikev <karlashikev at gmail.com> wrote:

            

  
  
#
Karla,
You can do

library(raster)
slices <- bind(slice1, slice2)

Robert
On Sun, Apr 3, 2016 at 6:53 AM, Karla Shikev <karlashikev at gmail.com> wrote:
#
Thanks, Robert and Tom. The bind command worked like a charm!

On Mon, Apr 4, 2016 at 1:04 PM, Robert J. Hijmans <r.hijmans at gmail.com>
wrote:

  
  
#
Please don't repeat questions to this list when there is no answer
within 24 hours; there are over 3000 subscribers.

The link you point to demonstrates how to use a for loop to repeat a
certain procedure, such as cross validation. Study it well, and ask
yourself what information you want to retain from each loop iteration,
and what you want to do with it afterwards.
On 05/04/16 07:02, uzzal at gist.ac.kr wrote: