Dear list,
I am struggling with the conversion of a vegetation map of class
SpatialGridDataFrame
into dummy-coded variables of the same class. The resulting
SpatialGridDataFrame should
be combined with additional environmental variables to conduct habitat
selection analyses, but I got the error
"topology is not equal" while it seems to be equal. Below is my script - I
would greatly appreciate any help!
Thanks,
Roland Pape
library(rgdal)
library(adehabitatHS)
# reading data from Esri (same spatial resolution, extent, and projection)
dem <- readGDAL("dem_summer.txt") # digital elevation model
names(dem) <- "dem"
veg <- readGDAL("veg_summer.txt") # vegetation types
names(veg) <- "veg"
class(veg) # SpatialGridDataFrame
projection <- proj4string(veg) # extraction of the projection used
# dummy-coding of vegetation types
veg.df <- data.frame(veg$veg) # extraction of vegetation types as dataframe
veg.df$veg <- as.factor(veg.df$veg)
veg.dum <- acm.disjonctif(veg.df) # needs dataframe as input
# extraction of coordinates from original SpatialGridDataFrame
veg.df2 <- data.frame(veg)
xcoord <- data.frame(veg.df2$x)
names(xcoord) <- "x"
ycoord <- data.frame(veg.df2$y)
names(ycoord) <- "y"
coords <- cbind(xcoord, ycoord)
# conversion of dummy-coded vegetation types back to SpatialGridDataFrame
coordinates(veg.dum) <- coords # yields SpatialPointsDataFrame
veg.dum2 <- as(veg.dum, "SpatialPixelsDataFrame") # yields
SpatialPixelsDataFrame
veg.dum3 <- as(veg.dum2, "SpatialGridDataFrame") # yields SpatialGridDataFrame
proj4string(veg.dum3) <- projection
# let's have a look at the topology
slot(veg, "grid")
# x y
# cellcentre.offset 442805 6747325
# cellsize 30 30
# cells.dim 1500 1348
slot(veg.dum3, "grid")
# x y
# cellcentre.offset 442805 6747325
# cellsize 30 30
# cells.dim 1500 1348
slot(dem, "grid")
# x y
# cellcentre.offset 442805 6747325
# cellsize 30 30
# cells.dim 1500 1348
# joining vegetation types and elevation into one SpatialGridDataFrame
enVar <- cbind(veg.dum3, dem)
# results in "Error in stop.ifnot.equal(x, grds[[1]]) : topology is not equal"
[[alternative HTML version deleted]]
_______________________________________________
R-sig-Geo mailing list
[email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo