Skip to content
Prev 4140 / 29559 Next

How to remove polygons according to their attributes?

Hi Lin,

I think you can simply do your selection as with any dataframe, e.g.

require(rgdal)
Ctries=readOGR(dsn='C:/data/datasets/HornOfAfrica', layer='HornOfAfrica',
p4s=NULL)
str(Ctries at data)
try<-Ctries[Ctries$AREA>100,]
spplot(try, zcol='ADM0_CODE')
# or:
Kenya<-Ctries[Ctries$ADM0_NAME=='Kenya',]
spplot(Ctries, zcol='ADM0_CODE',sp.layout=list(list("sp.polygons",Kenya,
col="red")), scales=list(draw=TRUE), xlim=c(30,52), ylim=c(-10,18),
col.regions='transparent', colorkey=FALSE)

Hope this helps,
Friderike


-----Original Message-----
From: r-sig-geo-bounces at stat.math.ethz.ch
[mailto:r-sig-geo-bounces at stat.math.ethz.ch] On Behalf Of Xin LIN
Sent: 05 September 2008 10:07
To: r-sig-geo at stat.math.ethz.ch
Subject: [R-sig-Geo] How to remove polygons according to their attributes?


Hi, everyone

I have a shapefile with many adjacent polygons in. Each has a series of
attributes such as ID and area. Now I want to remove some of them based on
attributes, e.g. to remove polygons with areas less than a given value. How
can I proceed?

Thanks a lot.=)

Lin Xin