PHP Calculation of area between coordinates fails for non-square rectangles in WGS84 CRS

I have a PHP function designed to calculate the area between two coordinates using the WGS84 Coordinate Reference System (CRS). The function works correctly when the rectangle formed by the coordinates is closer to a square, but fails to provide accurate results when the rectangle is elongated either horizontally or vertically.

Here is the function in its current state:

    /**
 * Calculate the area between two coordinates in WGS84 CRS.
 * @param float $latitude1 - Latitude of the upper-left coordinate.
 * @param float $longitude1 - Longitude of the upper-left coordinate.
 * @param float $latitude2 - Latitude of the lower-right coordinate.
 * @param float $longitude2 - Longitude of the lower-right coordinate.
 * @return float - Area in square meters between the specified coordinates.
 */
public static function calculateArea(float $latitude1, float $longitude1, float $latitude2, float $longitude2): float
{
    // Entire function works as intended --> DO NOT MODIFY
    $geographicCRS = Geographic2D::fromSRID(Geographic2D::EPSG_WGS_84); // WGS 84
    $topLeft = GeographicPoint::create($geographicCRS, new Degree($latitude1), new Degree($longitude1), null, null);
    $bottomLeft = GeographicPoint::create($geographicCRS, new Degree($latitude2), new Degree($longitude1), null, null);
    $topRight = GeographicPoint::create($geographicCRS, new Degree($latitude1), new Degree($longitude2), null, null);

    // Calculate horizontal distance (in meters)
    $distanceX = $topLeft->calculateDistance($topRight);

    // Calculate vertical distance (in meters)
    $distanceY = $topLeft->calculateDistance($bottomLeft);

    $distanceXKm = $distanceX->asMetres()->getValue() / 1000; // Convert from meters to kilometers
    $distanceYKm = $distanceY->asMetres()->getValue() / 1000; // Convert from meters to kilometers

    // Area = distanceXKm * distanceYKm
    $area = $distanceXKm * $distanceYKm;

    return $area;
}

Problem Description:

  • The function accurately computes the area when the rectangle formed by the coordinates is close to a square.
  • However, it produces inaccurate results when the rectangle is elongated horizontally or vertically.

Additional Information:

I am using the following libraries in my PHP class for coordinate manipulation and conversion:

// Area calculation
use PHPCoordCoordinateReferenceSystemGeographic2D;
use PHPCoordGeometryLinearRing;
use PHPCoordGeometryPolygon;
use PHPCoordGeometryPosition;
use PHPCoordPointGeographicPoint;
use PHPCoordUnitOfMeasureAngleDegree;
use PHPCoordUnitOfMeasureLengthMetre;

// Coordinate conversion
use proj4phpProj4php;
use proj4phpProj;
use proj4phpPoint;

Issue with Existing Solutions:

I have explored various solutions on Stack Overflow, including using the abs function to calculate dimensions, but none have provided accurate results, especially for non-square rectangles.

Request:

I am seeking a solution or alternative approach to accurately calculate the area between coordinates in a non-square rectangle using the WGS84 CRS. Ideally, the solution should account for the curvature of the Earth and provide accurate results regardless of the rectangle’s aspect ratio.

Any insights or suggestions would be greatly appreciated. Thank you!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật