Skip to content

Why does the area change wiledly when a square is defined by more than 4 vertices ? #310

@JanPolcher

Description

@JanPolcher

I am testing the area calculation for squares defined by different numbers of vertices. The results are rather unexpected with SphericalGeometry !

I use small squares so that the assumption of local plane is still good. I would expect that as I add points along the sides the area reduces slightly as the sides are not following an arc circle anymore. Here is my test code

from spherical_geometry import polygon
from shapely import Polygon
#
#
#
def boxit(cent, dlon, dlat, polyres) :
    boxll=[]
    loninc = dlon/polyres
    latinc = dlat/polyres
    for pts in range(polyres) :
        boxll.append([cent[0]-dlon/2.0+loninc*pts, cent[1]+dlat/2.0])
    for pts in range(polyres) :
        boxll.append([cent[0]+dlon/2.0, cent[1]+dlat/2.0-latinc*pts])
    for pts in range(polyres) :
        boxll.append([cent[0]+dlon/2.0-loninc*pts, cent[1]-dlat/2.0])
    for pts in range(polyres) :
        boxll.append([cent[0]-dlon/2.0, cent[1]-dlat/2.0+latinc*pts])
    boxll.append(boxll[0])
    return boxll

# Lon, Lat of center point
cent=[19.0, 42.0]
dlon=0.001
dlat=0.001

PlaneArea=[]
SphereArea=[]

for i in range(5) :
    ll=boxit(cent, dlon, dlat, i+1)
    ppoly=Polygon(ll)
    spoly=polygon.SphericalPolygon.from_lonlat([p[0] for p in ll], [p[1] for p in ll], cent)
    PlaneArea.append(ppoly.area)
    SphereArea.append(spoly.area())


print("Areas on Plane : ", PlaneArea)
print("Areas on Sphere : ", SphereArea)

The results are
Areas on Plane : [1.0000000000024443e-06, 1.0000000000024443e-06, 1.000000000002444e-06, 1.0000000000024443e-06, 1.0000000000024445e-06]
Areas on Sphere : [2.2637536289948912e-10, 2.383160335739376e-10, 2.8104452098887123e-10, 1.2860112974522053e-10, 1.5229659311444266e-08]

On a plane, as expected, I always get the same area. With SphericalGeometry on the other hand I get strange numbers. I would expect the area to decrease slightly, but not to jump around like that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions