Ivan Petrushenko - 1 year ago 109
Python Question

# How to calculate area of a polygon with latitude and longitude using shapely lib?

I have the following method that checks whether is

`points`
are polygon

``````from shapely import wkt

def validate_polygon(points):
try:
except Exception as ex:
raise WrongRequestDataError("Incorrect points format. " + str(ex))
``````

How can I calculate area of the
`polygon`
and throw exception if it's greater than 400 square miles?

I have tried to check this:

``````polygon = wkt.loads("POLYGON((%s))" % "34.093523 -118.274893,34.091414 -118.275887,34.092082 -118.278062,34.093867 -118.276609,34.093523 -118.274893")
print(polygon.area)

4.406979500001112e-06
``````

but it seems like the incorrect answer or what type of units it uses for this value and how to translate it to square miles or km^2?

typically you would compute the area like this:

``````from shapely.geometry import Polygon
points = [(34.093523, -118.274893), (34.091414, -118.275887), (34.092082, -118.278062), (34.093867, -118.276609), (34.093523, -118.274893)]
polygon = Polygon(points)