[R-sig-Geo] Difference between area calculations by QGIS and sf package

Roger Bivand Roger@B|v@nd @end|ng |rom nhh@no
Mon Sep 27 17:32:32 CEST 2021


On Mon, 27 Sep 2021, Rik Ferreira wrote:

> Dear list members,
>
> Why does sf::st_area returns a different area than the output of QGIS $area
> for the same geometry?
>
> A reproducible example (state of Minas Gerais, Brazil):
>
> library(sf)
>> mg <- geobr::read_state(31)
>> st_area(mg)
>>
>
> sf::st_area: 588358849314 [m^2]
> QGIS $area: 586521037474,860 m²
>
> The layer used in QGIS was exported with st_write() in GeoJSON format.
>
> The error is: 1837811840 m².

> st_is_longlat(mg)
[1] TRUE
> sf_use_s2()
[1] TRUE
> sf_use_s2(FALSE)
Spherical geometry (s2) switched off
> (o <- st_area(mg))
586520883040 [m^2]
> sf_use_s2(TRUE)
Spherical geometry (s2) switched on
> (p <- st_area(mg))
588358849314 [m^2]
> p - o
1837966275 [m^2]

See https://r-spatial.org/r/2020/06/17/s2.html

When sf_use_s2() is FALSE, see ?st_area ("ellipsoidal distances are 
computed using st_geod_distance which uses function 'geod_inverse' from 
GeographicLib (part of PROJ)"). You'd have to establish what code QGIS 
uses to know why it and GeographicLib differ.

Hope this clarifies

Roger


>
> Thank you for the attention.
>
> Att.
>
>

-- 
Roger Bivand
Emeritus Professor
Department of Economics, Norwegian School of Economics,
Postboks 3490 Ytre Sandviken, 5045 Bergen, Norway.
e-mail: Roger.Bivand using nhh.no
https://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en


More information about the R-sig-Geo mailing list