SpatioTemporal / STAREPandas

STAREpandas adds SpatioTemporal Adaptive Resolution Encoding (STARE) support to pandas DataFrames. https://starepandas.readthedocs.io/en/latest/
MIT License
4 stars 1 forks source link

Issues with CCW #156

Closed NiklasPhabian closed 5 months ago

NiklasPhabian commented 11 months ago

Should this polygon be considered CCW or CW?

lons = [179, -179, -179, 179]
lats =  [  44  , 44,  46, 46]
verts = list(zip(lons, lats))
poly = shapely.geometry.Polygon(verts)

Going by the coordinates, this is of course CW, and shapely's poly.exterior.is_ccw will tell us so. But I am wondering if we want the polygon to be understood as CW.

STAREPandas currently understands this ring as CW and will invert it. However, pystare seems to interpret this inverted ring as an interior ring.

If we defined the coordinates from 0-360, e.g.

lons = [179, 181, 181, 179]
lats =  [  44  , 44,  46, 46]

the ring would be CCW

NiklasPhabian commented 11 months ago

It probably doesn't make too much sense to decide if the ring is CCW or CW on the plane. We should test it on the sphere instead.

NiklasPhabian commented 11 months ago

E.g. chat go:

import numpy as np

def spherical_polygon_orientation(nodes):
    total_cross_product = np.cross(nodes[-1], nodes[0])

    for i in range(len(nodes) - 1):
        total_cross_product += np.cross(nodes[i], nodes[i+1])

    if total_cross_product[2] > 0:
        return "Counterclockwise"
    elif total_cross_product[2] < 0:
        return "Clockwise"
    else:
        return "Undefined (Degenerate Case)"

# Example usage:
vertices = [np.array([x, y, z]) for x, y, z in [(0, 1, 0), (1, 0, 0), (0, 0, 1)]]
orientation = spherical_polygon_orientation(vertices)
print("Orientation:" orientation)
NiklasPhabian commented 11 months ago

(convert lat/Lon to unit-vectors first)