Calculating the rectangle area from coordinates

If I have two points (51.9925734, 5.65038093), (51.99226769, 5.64991222)

I want to get the rectangle earth area.

I tried this method from other resources:

from area import area
obj_field = {'type':'Polygon','coordinates':[[[51.9925734,5.65038093],
                                     [51.9925734,5.64991222],
                                     [51.99226769,5.64991222],
                                     [51.99226769,5.65038093]]]}
field_area_2 = area(obj_field)
print(f'The total field area is: {field_area_2} square meters')
The total field area is: 1767.018812772391 square meters

But I’m not sure if it is correct.

Answer

For small areas, like your example, the simplest approach is to convert lat/lon coordinates to UTM. Then you can use basic math, like calculating the area of the rectangle, as in this snippet:

import utm

a_geo = 51.9925734, 5.65038093
b_geo = 51.99226769, 5.64991222

# Convert lat, lon to utm
a_easting, a_northing, zone, _ = utm.from_latlon(*a_geo)
b_easting, b_northing, _, _ = utm.from_latlon(*b_geo, force_zone_number=zone)

area = abs((a_easting - b_easting) * (a_northing - b_northing))

Leave a Reply

Your email address will not be published. Required fields are marked *