Skip to content
Prev 29506 / 29559 Next

The sf::st_perimeter() function doesn't seem to work properly when trying to determine the perimeter of an sf object on the ellipsoid

Dear Micha, Josiah and Mike,

First of all, a very big thank you to all three of you for taking the time to share your thoughts on the problem I raised.

Mike, an even bigger thank you for the detailed explanations. It's really appreciated.?
The details of the calculations on your Github post are particularly interesting and confirm the doubt I was expressing about the sf::st_perimeter() function when sf::sf_use_s2() is set as FALSE (i.e. the case where the function returns 129.09815 [m] as shown in my reprex). I understand from your Github post that you validate the fact that there is an error somewhere in the function's code, which will most probably be corrected soon (by you or Edzer, I guess).

Many thanks again for your particularly enlightening and helpful contribution... and thanks in advance to the person who will make the correction in the code.

Cheers,
Lo?c

________________________________________
De :?Michael Sumner <mdsumner at gmail.com>
Envoy? :?samedi 17 mai 2025 14:13
? :?Josiah Parry <josiah.parry at gmail.com>
Cc?:?Lo?c Val?ry <lvalery at outlook.fr>; r-sig-geo <r-sig-geo at r-project.org>
Objet :?Re: [R-sig-Geo] The sf::st_perimeter() function doesn't seem to work properly when trying to determine the perimeter of an sf object on the ellipsoid
?
s2 is actually less accurate, because s2 is spherical (terra always uses ellipsoidal Karney when crs is set, and sf+longlat-s2 uses Karney, as does geodist, but sf uses "the map projection" when crs is nonlonlat?or NA, because this is an appropriate coordinate system in which to calculate distance (within this region)). It's a fun complex to grok, not helpful for inexpert use sadly, or with a lack of deep knowledge of the inter-package history.? Fun stuff.?

There are three numbers in play in this code (I've worked on illustrating this in different ways over the years, trying to get attention on it to no avail, this is a great example and here is some code as a start at unpicking it:?

The numbers in play are?129.285384,?129.248935,?129.09815

https://gist.github.com/mdsumner/5daedfcbee851ca31a7aa9006dbf74cf

Choose your tools very carefully, it's? pretty?treacherous space here.?

Best, Mike




?
On Sat, May 17, 2025 at 8:29?AM Josiah Parry <josiah.parry at gmail.com> wrote:
I believe that using s2 is calculating a *more accurate** perimeter because
it is used _only_ with spherical geometries. It uses a spherical
calculation because you?re using a spherical projection. Otherwise you?re
calculating the perimeter of a geography in 2D ignoring the fact that the
data are not themselves projected onto a 2D plane.
On Fri, May 16, 2025 at 15:18 Lo?c Val?ry <lvalery at outlook.fr> wrote:

            
? ? ? ? [[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


--
Michael Sumner
Research Software Engineer
Australian Antarctic Division
Hobart, Australia
e-mail: mdsumner at gmail.com
Message-ID: <PA4PR02MB809910B14D61CF04D2597E43D092A@PA4PR02MB8099.eurprd02.prod.outlook.com>
In-Reply-To: <CAAcGz98CTQOgqdVXqCTusvGc3Kz=d4FhBG7KfqRgWYNV1Gmzjg@mail.gmail.com>