[R-sig-Geo] split SpatialPolygon after unionSpatialPolygons()

Paulo E. Cardoso pecardoso at netcabo.pt
Thu Jul 16 14:50:56 CEST 2009


Roger,
I'm not being able, even with a very simple image.
Attached file is a bmp image; the type of data I'll need to work with.
labcon is returning a single level when it should return 3.

____________
Paulo E. Cardoso

> -----Mensagem original-----
> De: Roger Bivand [mailto:Roger.Bivand at nhh.no]
> Enviada: quarta-feira, 15 de Julho de 2009 18:04
> Para: pecardoso
> Cc: R-sig-Geo
> Assunto: Re: [R-sig-Geo] split SpatialPolygon after
> unionSpatialPolygons()
> 
> On Tue, 14 Jul 2009, pecardoso wrote:
> 
> > I've used unionSpatialPolygons to dissolve polygons and get a grid as
> a
> > spatialpolygon.
> >
> > A simple example:
> > grelha<-readGDAL(paste("C:/...","teste.bmp",sep=""))
> 
> Please only use examples that refer to a publically available data set.
> 
> > grd <- slot(grelha, "grid")
> > pol <- as.SpatialPolygons.GridTopology(grd)
> > pol <- unionSpatialPolygons(pol, SGDF2PCT(grelha)$idx)
> >
> 
> Exactly. This creates a rectangular polygon for each raster cell
> specified
> by grd, then removes all internal boundaries between those raster cells
> with the same value of the index, additionally placing all the separate
> Polygon objects with the same value of the index in a Polygons object.
> No-one has given them IDs, all the function has to work on are the
> index
> values.
> 
> I think that this is the same question that you asked recently, to
> which I
> replied indicating that you should use labcon() in adehabitat to give a
> separate index to each disconnected cluster with the same index values.
> 
> The alternative is to re-format the output SpatialPolygons object to
> find
> out how many Polygon objects there are in each Polygons object, and
> then
> to flatten those with more than one - that is make each such Polygon
> object into a singleton Polygons object with a unique ID slot value. It
> is
> possible, but you will need some knowledge of the way these objects are
> constructed. If you can post a sample image, it may not be too hard,
> either using labcon() or by re-formatting the representation.
> 
> Roger
> 
> > When the original image have more than one region or 'islands' of a
> > single color (imagine a small logo), the unionSpatialPolygons() will
> > dissolve polygons based on the ID's provided, in such a way that
> > coordinates(pol) will return N lines, as much as different ID's or
> > colors retrieved with SGDF2PCT(grelha)$idx.
> >
> > It means that one cannot get centroids of each individual regions.
> > Beside this, if the original image have this pattern, each number is
> a
> > pixel of a single color:
> >
> > 00100
> > 02000
> > 00020
> > 10000
> >
> > coordinates() will give only 3 centroids and only for three of the
> > polygons (not even a common centroid for 1 and 2 ID's).
> >
> > I'd like to split the spatialpolygon object obtained with
> > unionSpatialPolygons(pol, SGDF2PCT(grelha)$idx) but retaining the
> ID's
> > in order to get individual centroids for each region, in this simple
> > case, two centroids for 1, two for 2 and two for 0.
> >
> > Any idea will be welcome
> >
> >
> >
> > 	[[alternative HTML version deleted]]
> >
> > _______________________________________________
> > 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
> 
> Checked by AVG - www.avg.com
> Version: 8.5.375 / Virus Database: 270.13.16/2241 - Release Date:
> 07/16/09 05:58:00
-------------- next part --------------
A non-text attachment was scrubbed...
Name: teste.bmp
Type: image/bmp
Size: 2782 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20090716/0e510bb9/attachment.bmp>


More information about the R-sig-Geo mailing list