I am converting several functions from the sp
package to terra
and I have encountered an inconsistency in the calculated area of polygons. The code sample below demonstrates my issue.
x = seq(0, 2 * pi, length.out = 100)
circle = cbind(sin(x), cos(x))
# sp/rgeos version
poly.1 = sp::SpatialPolygons(list(sp::Polygons( list(sp::Polygon(circle) ), "circle")))
area.1 = rgeos::gArea(poly.1)
# terra version
poly.2 = terra::vect(circle, type = "polygons", crs = "local")
area.2 = terra::expanse(poly.2, transform = F)
area.1 - area.2 # != 0
I have understood that poly.1
and poly.2
should be describing the same polygon. The area calculations for each are not the same though (similar, but different enough to break compatibility with existing code).
Can anyone piont out whether I am doing something wrong? Or is there an approach that could get terra
to deliver the same value as area.1
?