[R-sig-Geo] merging polygons by indices

Roger Bivand Roger.Bivand at nhh.no
Tue Aug 16 17:45:24 CEST 2011


On Tue, 16 Aug 2011, majesty wrote:

> Dear R-sig-geo subscribers,
>
> I have the following problem, would be grateful for suggestions. I am doing
> a research on UK output areas, My .shp file contains output areas for UK but
> there are some duplicates. when I type
> which(duplicated(shape$output_area)==TRUE) I get indices of 67 duplicates:
>
> [1] 165713 165723 165724 165786 165788 165814 165815 165819 165820 165821
> [11] 165822 165827 165900 165974 165978 165985 165989 166132 166142 166300
>
> ... and so on
>
> I would like to merge them with the output area polygons of the first
> original instance of a given output_area, so that for instance I would merge
> 16712 with 165713 and 165722 with 165723, etc.
>
> I know I should use unionSpatialPolygons() function from maptools but how to
> do it if I want to merge only particular indices (of which I have a list)?

If there is only one Polygons object to be merged, unionSpatialPolygons() 
should just pass it through, so you should be able to use it as it stands. 
Otherwise, you'd have to subset to the group to be treated or not, and 
combine them afterwards.

Roger

>
> Any input would be appreciated,
> Thanks,
>
> Juta
>
> --
> View this message in context: http://r-sig-geo.2731867.n2.nabble.com/merging-polygons-by-indices-tp6691746p6691746.html
> Sent from the R-sig-geo mailing list archive at Nabble.com.
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list