关于terra包地理坐标(lon/lat)下面积计算的技术问询
terra Package Lon/Lat Area Calculation Questions Let’s break down your questions about expanse() and cellSize() in the terra package clearly:
1. Are area calculations based on a sphere or ellipsoid?
By default, both functions use the WGS84 ellipsoid (the standard geographic reference for EPSG:4326 coordinates) for highly accurate area calculations. You can toggle this behavior with the ellipsoid parameter:
- Keep
ellipsoid = TRUE(the default) to stick with ellipsoid-based measurements. - Set
ellipsoid = FALSEto switch to a simplified spherical calculation if needed.
Example code snippets:
# Calculate total raster area using ellipsoid (default) total_expanse <- expanse(my_lonlat_raster) # Generate a raster of cell areas using spherical geometry cell_areas_sphere <- cellSize(my_lonlat_raster, ellipsoid = FALSE)
2. How does the algorithm compare to the fixed cell width (median width) method in the raster package?
The raster package’s area calculation (via area()) relies on estimating cell area using the median longitude of each cell to assign a fixed width. This can introduce noticeable errors, especially at high latitudes where the distortion of geographic coordinates makes cell shapes less uniform.
terra’s cellSize() and expanse() use a far more precise approach:
- For every cell, they calculate the area of the polygon formed by the cell’s four corner coordinates.
- This polygon area is computed using geodesic measurements tailored to your chosen ellipsoid (or sphere), which accounts for the actual curved shape of the cell on Earth’s surface.
expanse()then sums these individual, precise cell areas (either for the full raster or a subset) instead of relying on aggregated median width estimates.
This makes terra’s area calculations more accurate across all latitudes compared to the raster package’s method.
内容的提问来源于stack exchange,提问作者Jean-Luc Dupouey

