[R-sig-Geo] problem to use "perimeter" in RASTER Library

Robert J. Hijmans r.hijmans at gmail.com
Wed Dec 15 17:47:27 CET 2010


Dear Gianni,

perimeter is a function in the geosphere package.

You found a bug in the test whether this is a closed polygon.  (It
should be if  (isTRUE(all.equal(x[1, ], x[nrow(x), ])))  rather than
if (all.equal(x[1, ], x[nrow(x), ]))  ). Thanks for reporting it, it
is fixed in version 1.2-16.

The easy work-around would be

xy <- rbind(c(579471.4,6757500),c(581081.3,6757500),c(579471.4,6761301),c(581081.3,6761301))
xy <- rbind(xy, xy[1,])

perimeter(xy)

But then you get another error, with these data, because these are not
longitude/latitude coordinates. geosphere only does spherical
(lon/lat) computations, not computations with (the easier case of)
planar coordinates .

With these coordinates you can compute the perimeter like this:

library(raster)
x <- rbind(c(579471.4,6757500),c(581081.3,6757500),c(579471.4,6761301),c(581081.3,6761301))
y <- rbind(x[-1,], x[1,])
d <- pointDistance(x, y, lonlat=FALSE)
perimeter <- sum(d)

Robert

> On Wed, Dec 15, 2010 at 5:41 AM, gianni lavaredo <gianni.lavaredo at gmail.com> wrote:
> dera researchers,
>
> I wish to get the value of perimeter in my own area (mywindow), but I have
> the following problem
>
> xy <-
> rbind(c(mywindow$xrange[[1]],mywindow$yrange[[1]]),c(mywindow$xrange[[2]],mywindow$yrange[[1]]),c(mywindow$xrange[[1]],mywindow$yrange[[2]]),c(mywindow$xrange[[2]],mywindow$yrange[[2]]))
> perimeter(xy)
> Error in if (all.equal(x[1, ], x[nrow(x), ])) { :
>  the argument is not logic
>
> xy <-
> rbind(c(579471.4,6757500),c(581081.3,6757500),c(579471.4,6761301),c(581081.3,6761301))
> plot(xy)
> perimeter(xy)
>
> same error
>
> thanks for attention
> Gianni
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



More information about the R-sig-Geo mailing list