[R-sig-Geo] Merging separate polygons in administrative entities

Roger Bivand Roger.Bivand at nhh.no
Tue Sep 13 16:48:06 CEST 2005


On Tue, 13 Sep 2005, Paul Hewson wrote:

> Hello,

>  I've imported a file from ArcView which should contain around 300
> administrative entities.  However, I have over 600 polygons, mainly
> because of islands.  I can do mapping and so on by using the merge
> command.
>  

> Is there a way of rearranging the data so that islands etc. are
> associated with the adminstrative entity.  I want to do neighouring
> (poly2nb) and I get a lot of blank entries because all the islands are
> seen as distinct entities, whereas they should presumably only be 300
> $shapes in the polylist?
>  

Yes, it should be possible. What you'll need to check first is that the
att.data contain a suitable ID column with the 300 or so unique output
IDs, which contain duplicates in the input. The sp and maptools packages
contain the functionality you'll need, though it's a bit rough for now. 
The steps are to read the shapefile:

library(maptools) # maptools > 0.5, depends on sp > 0.8
myshp <- read.shape("myshp.shp")

then convert to SpatialPolygons aggregating the geometries by ID:

IDs <- myshp$att.data$myID_field
SP <- maptools:::.asSpatialPolygonsShapes(myshp$Shapes, IDs=IDs)

and back to the polylist object (it's a bit simplistic, the sp objects 
are more advanced):

plist <- maptools:::.SpP2polylist(SP)

Do watch the attr(plist, "region.id") - it will contain your IDs uniquely,
but may not be in the same order as you might think. How you aggregate
what else is in att.data will be up to you. Please let me know how this
goes - the functionality can be exposed easier than using the package
namespace :::  operators.

Roger


> I assume this may have arisen because of the way I handled the data in
> ArcView.
>  
> Thanks for any help
>  
> Paul Hewson
> Lecturer in Statistics
> University of Plymouth
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, 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