Feature Area

Feature Area Naming

Point Reference

Although Area Entity does NOT represent a Feature Area with a single point (latitude, longitude), it is commonly available in most systems e.g. OpenStreetMap which uses the centroid of the area.

Note Point Reference to an area CAN change e.g. as the boundary changes or there is a more accurate or appropriate point.

1. Centroid

A simple way of calculating centroid is to just get the "average" coordinates from all input coordinates.

function get_polygon_centroid(points) {
    //Correction for very small polygons:
    const x0 = points[0].x , y0 = points[0].y;

    let x = 0, y = 0, twiceArea = 0;

    let prev = points[points.length - 1];
    for (const next of points)
    {
        const x1 = prev.x - x0, y1 = prev.y - y0,
              x2 = next.x - x0, y2 = next.y - y0,
              a  = x1 * y2 - x2 * y1;

        twiceArea += a;
        x += (x1 + x2) * a;
        y += (y1 + y2) * a;

        prev = next;
    }

    const factor = 3 * twiceArea;  // 6 * twiceArea/2
    x /= factor;
    y /= factor;

    return { x: x + x0, y: y + y0 };
}

const points = [
    { x: 78.0001462, y: 40.0008827 },
    { x: 78.0000228, y: 40.0008940 },
    { x: 78.0000242, y: 40.0009264 },
];
console.log(get_polygon_centroid(points));

Reference:

2. Furthest from Boundary

For some area shapes, using the point that is furthest away from all boundaries might be more appropriate.

There is a Ploylabel library available.

function get_polygon_centroid(points) {
    var pts = points.map(p => [p.x, p.y]);  // convert {x:x, y:y} into [x, y]
    var centroid = polylabel([pts]);
    return {x:centroid[0], y:centroid[1]};
}
var my_points = [{x:3,y:1},{x:5,y:8},{x:2,y:9}];
console.log('centroid', get_polygon_centroid(my_points));