[R-sig-Geo] get coordinates of centroids in a SpatialGridDataFrame object.

Roger Bivand Roger.Bivand at nhh.no
Tue Jul 14 16:30:59 CEST 2009


On Tue, 14 Jul 2009, Paulo E. Cardoso wrote:

> I have a classified images imported as SpatialGridDataFrame. I'd like to get
> centroid coordinates of regions of cells with common values, considering the
> "islands" that represents objects in space.

If you are thinking of "connected components", try labcon() in adehabitat:

library(adehabitat)
data(puechabon)
hr <- getsahrlocs(puechabon$sahr, "hr")
u <- getkasc(hr, "Jean")
p <- labcon(u)
c2a <- kasc2spixdf(as.kasc(list(p)))
names(c2a) <- "patches"
image(c2a)
c2b <- as.SpatialPolygons.SpatialPixels(c2a)
library(maptools)
c2c <- unionSpatialPolygons(c2b, c2a$patches)
plot(c2c, axes=TRUE)
points(coordinates(c2c), pch=3)

How this scales for your data is another matter.

Roger

>
> Any idea?
>
> ____________
>
> Paulo E. Cardoso
>
>
>
>
> 	[[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



More information about the R-sig-Geo mailing list