Skip to content
Back to formatted view

Raw Message

Message-ID: <CD91F36D-7492-4A5B-BB9B-A5A6792F85B8@eva.mpg.de>
Date: 2015-05-12T19:00:00Z
From: Hans-Jörg Bibiko
Subject: Replace a polygon by a new one of a SpatialPolygonsDataFrame [CORRECTION]
In-Reply-To: <4B85CC51-73BA-4F31-9F79-5EAA6E02B402@eva.mpg.de>

!! 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