[R-sig-Geo] Replace a polygon by a new one of a SpatialPolygonsDataFrame [CORRECTION]
Hans-Jörg Bibiko
bibiko at eva.mpg.de
Tue May 12 21:00:00 CEST 2015
!! CORRECTION !!
> @Edzer: wrld_simpl at polygons[237] <- theNew
> doesn't work. Also due to [<- declaration
This is NOT true since I tried unfortunately
wrld_simpl[237] <- theNew
instead of
wrld_simpl at polygons[237] <- theNew
As Edzer suggested this works like a charm!
To reproduce it, here is the code:
library(maptools)
data(wrld_simpl)
plot(wrld_simpl[237,])
r <- bbox(wrld_simpl[237,])
theID <- wrld_simpl[237,]@polygons[[1]]@ID
theNew <- list(Polygons(list(
Polygon(cbind(c(r[1,1],r[1,1],r[1,2],r[1,2],r[1,1]),c(r[2,1],r[2,2],r[2,2],r[2,1],r[2,1])))),
theID))
wrld_simpl at polygons[237] <- theNew
plot(wrld_simpl[237,], border="red", add=T)
Sorry for the confusion!
Notwithstanding many thanks!
Kind regards, Hans
More information about the R-sig-Geo
mailing list