[R-sig-Geo] Polygon edge smoothing

Alexandre Villers villers.alexandre at gmail.com
Mon Dec 6 07:42:11 CET 2010


Le 06/12/2010 03:55, Sébastien Durand a écrit :
> Here is what I found as a temporary solution:
>
> Here is my example:
>
>
> library(akima)
> library(maptools)
> library(zoo)
> gpclibPermit()
> library(raster)
> data(akima)
>
> # define de dimension of grid
> dimgrid<- 50
>
> # Interpolate to regular grid
> ak.li<- interp(akima$x, akima$y, akima$z, xo=seq(min(akima$x),
> max(akima$x), length = dimgrid),yo=seq(min(akima$y), max(akima$y),
> length = dimgrid),linear = TRUE, extrap=FALSE, duplicate = "mean")
>
> # Show interpolation
> image(ak.li)
> points(akima)
> with(akima, text(x, y, formatC(z,dig=2), adj = -0.1))
>
> r<- raster(ak.li)
> plot(r)
>
> pol<- rasterToPolygons(r, fun=function(x){x>20&  x<25})
>
> # Show the polygons
> plot(pol, add=T, col='red')
>
> ### new code
> digits<- 6
> for (i in 1:length(pol at polygons)) {
> 	for (j in 1:length(pol at polygons[[i]]@Polygons)) {
> 			pol at polygons[[i]]@Polygons[[j]]@coords<-
> 			round(pol at polygons[[i]]@Polygons[[j]]@coords, digits)
> 	}
> }
>
>
> # Attempt to merge similar adjacent into one polygon
> union = unionSpatialPolygons(pol, ID=rep(1, times=length(pol at polygons)))
>
> # Show
> plot(union, add=TRUE, col="white")
>
> # Nombre de vertices
> crds=union at polygons[[1]]@Polygons[[1]]@coords
> tmp=length(crds[,1])
>
> nexCoordX= rollmean(c(crds[tmp,1], crds[,1], crds[1,1]), k=2)
> nexCoordY= rollmean(c(crds[tmp,2], crds[,2], crds[1,2]), k=2)
> lines(nexCoordX, nexCoordY, col="yellow", lwd=2)
>
>
> If you have any knowledge of a function that would do something similar, I would be happy to ear about it!
>
> Thanks a lot!
>
> Sébastien
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>    
Hey,

Hey,

You can also have a look at the spatstat package and the simplify.owin() 
function. Maptools package provides function to convert objects between 
sp and spatstat formats.
HTH

Alex

-- 
Alexandre Villers, PhD.
Postdoc researcher
Spatial Ecology & Population Dynamics
Section of Ecology, Department of Biology
University of Turku
FIN-20014 Turku
Finland

@mail: alexandre.villers at utu.fi
phone: 00358 (0)2 333 5039

Skype You can skype me (but think of using Ekiga instead !) 
<skype:aquila06?call>


*Use open source and free softwares*
<http://cran.r-project.org/> <http://grass.itc.it/> 
<http://www.qgis.org/> <http://fr.openoffice.org/> 
<http://www.mozilla-europe.org/fr/> <http://www.mozilla-europe.org/fr/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20101206/4b802d57/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Rlogo.jpg
Type: image/jpeg
Size: 1753 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20101206/4b802d57/attachment.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: GRASSlogo.png
Type: image/png
Size: 3277 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20101206/4b802d57/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: QGIS.png
Type: image/png
Size: 4144 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20101206/4b802d57/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OOlogo.gif
Type: image/gif
Size: 4246 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20101206/4b802d57/attachment.gif>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TBlogo.jpg
Type: image/jpeg
Size: 1385 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20101206/4b802d57/attachment-0001.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: FFlogo.jpg
Type: image/jpeg
Size: 1686 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20101206/4b802d57/attachment-0002.jpg>


More information about the R-sig-Geo mailing list