Need to calculate the area of geographic regions? This guide covers everything you need to know about calculating polygon areas programmatically via API, including geodesic calculations, unit conversions, and implementation examples in multiple languages.
What is Polygon Area Calculation?
Polygon area calculation determines the surface area enclosed by a set of geographic coordinates. Unlike simple 2D geometry, geographic calculations must account for the Earth's curvature to produce accurate results.
For example, calculating the area of Central Park in New York requires geodesic mathematics to handle the Earth's ellipsoidal shape accurately.
Calculation Methods
There are different approaches to calculating geographic areas:
Geodesic Calculation (Recommended)
Uses the WGS84 ellipsoid model to account for Earth's shape. Most accurate for real-world applications.
Spherical Calculation
Treats Earth as a perfect sphere. Simpler but less accurate, especially for large areas or high latitudes.
Planar Calculation
Ignores Earth's curvature entirely. Only suitable for very small areas where curvature is negligible.
Using the Polygon Area API
TinyFn provides a simple endpoint to calculate polygon areas:
POST https://api.tinyfn.io/v1/geo/polygon/area
Headers: X-API-Key: your-api-key
Content-Type: application/json
{
"coordinates": [
[40.7829, -73.9654],
[40.7829, -73.9580],
[40.7649, -73.9580],
[40.7649, -73.9654],
[40.7829, -73.9654]
],
"unit": "hectares"
}
{
"area": 341.25,
"unit": "hectares",
"areaInSquareMeters": 3412500,
"perimeter": 8543.7,
"perimeterUnit": "meters"
}
Parameters
| Parameter | Type | Description |
|---|---|---|
coordinates |
array | Array of [lat, lng] pairs forming a closed polygon |
unit |
string | Output unit: sqm, sqkm, hectares, acres, sqmi (default: sqm) |
Code Examples
JavaScript / Node.js
const response = await fetch(
'https://api.tinyfn.io/v1/geo/polygon/area',
{
method: 'POST',
headers: {
'X-API-Key': 'your-api-key',
'Content-Type': 'application/json'
},
body: JSON.stringify({
coordinates: [
[40.7829, -73.9654],
[40.7829, -73.9580],
[40.7649, -73.9580],
[40.7649, -73.9654],
[40.7829, -73.9654]
],
unit: 'hectares'
})
}
);
const { area, perimeter } = await response.json();
console.log(`Area: ${area} hectares`);
console.log(`Perimeter: ${perimeter} meters`);
Python
import requests
response = requests.post(
'https://api.tinyfn.io/v1/geo/polygon/area',
json={
'coordinates': [
[40.7829, -73.9654],
[40.7829, -73.9580],
[40.7649, -73.9580],
[40.7649, -73.9654],
[40.7829, -73.9654]
],
'unit': 'hectares'
},
headers={'X-API-Key': 'your-api-key'}
)
data = response.json()
print(f"Area: {data['area']} hectares")
print(f"Perimeter: {data['perimeter']} meters")
cURL
curl -X POST "https://api.tinyfn.io/v1/geo/polygon/area" \
-H "X-API-Key: your-api-key" \
-H "Content-Type: application/json" \
-d '{
"coordinates": [
[40.7829, -73.9654],
[40.7829, -73.9580],
[40.7649, -73.9580],
[40.7649, -73.9654],
[40.7829, -73.9654]
],
"unit": "hectares"
}'
Common Use Cases
- Real Estate: Calculate land parcel sizes for property listings
- Agriculture: Measure farm field areas for crop planning
- Urban Planning: Analyze zoning areas and development sites
- Environmental: Measure forest coverage, wetlands, or protected areas
- Delivery Services: Define and measure service coverage zones
Best Practices
- Close your polygons: Ensure the first and last coordinates are identical
- Use consistent winding: Counter-clockwise for outer rings, clockwise for holes
- Validate coordinates: Ensure all points are valid lat/lng pairs
- Choose appropriate units: Use hectares for land, sq km for regions
Use via MCP
Your AI agent can call this tool directly via Model Context Protocol — no HTTP code needed. Add TinyFn to Claude Desktop, Cursor, or any MCP client:
{
"mcpServers": {
"tinyfn-geo": {
"url": "https://api.tinyfn.io/mcp/geo/",
"headers": {
"X-API-Key": "your-api-key"
}
}
}
}
See all geolocation tools available via MCP in our Geolocation MCP Tools for AI Agents guide.
Try the Polygon Area API
Get your free API key and start calculating areas in seconds.
Get Free API Key