[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

Micha Silver m|ch@_@||ver+DEV @end|ng |rom proton@me
Fri May 16 18:14:45 CEST 2025


Interesting. Thanks for the MWE!
Obviously, when you transform to WGS84 you'll get different length/perimeter values than the original projection.

Here's what I see (I used plt as variable name to avoid conflicts with the 'plot` func):

st_crs(plt)[1]
$input
[1] "EPSG:2154"

# Calculating ellipsoidal perimeter with st_perimeter()
plt |>  sf::st_perimeter()
129.0982 [m]
# Calculating ellipsoidal perimeter with st_boundary() 
plt |>
  sf::st_boundary() |>
  sf::st_length()
129.0982 [m]
# Calculating ellipsoidal perimeter with st_cast() 
plt |>
  sf::st_cast("MULTILINESTRING") |>
  sf::st_length()
129.0982 [m]
# Looks OK

# Now transformed
plt <- st_transform(plt, 4326) 
# Calculating ellipsoidal perimeter with st_perimeter() 
plt |>  sf::st_perimeter()
129.0982 [m]
# Calculating ellipsoidal perimeter with st_boundary()
plt |>
  sf::st_boundary() |>
  sf::st_length()
129.0982 [m]
# Calculating ellipsoidal perimeter with st_cast()
plt |>
  sf::st_cast("MULTILINESTRING") |>
  sf::st_length()
129.0982 [m]
# Also OK

sessionInfo()
R version 4.2.2 Patched (2022-11-10 r83330)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 12 (bookworm)

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.21.so

locale:
 [1] LC_CTYPE=en_IL.UTF-8          LC_NUMERIC=C                 
 [3] LC_TIME=en_IL.UTF-8           LC_COLLATE=en_IL.UTF-8       
 [5] LC_MONETARY=en_IL.UTF-8       LC_MESSAGES=en_IL.UTF-8      
 [7] LC_PAPER=en_IL.UTF-8          LC_NAME=en_IL.UTF-8          
 [9] LC_ADDRESS=en_IL.UTF-8        LC_TELEPHONE=en_IL.UTF-8     
[11] LC_MEASUREMENT=en_IL.UTF-8    LC_IDENTIFICATION=en_IL.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] sf_1.0-20      rkward_0.7.5   devtools_2.4.5 usethis_3.1.0 


HTH,
Micha



More information about the R-sig-Geo mailing list