lonboard
lonboard copied to clipboard
Polygon winding order
The deck.gl SolidPolygonLayer has a render option _windingOrder which says
This prop is only effective with
_normalize: false. It specifies the winding order of rings in the polygon data, one of:
'CW': outer-ring is clockwise, and holes are counter-clockwise'CCW': outer-ring is counter-clockwise, and holes are clockwiseThe proper value depends on the source of your data. Most geometry formats enforce a specific winding order. Incorrectly set winding order will cause an extruded polygon's surfaces to be flipped, affecting culling and the lighting effect.
Thus, this is probably not the highest priority, given that it only happens with extruded polygons, but should be fixed eventually.
In GEOS, polygon winding order is unspecified, so we'd need to check/force it manually. There's no vectorized shapely function to do this, ref https://github.com/shapely/shapely/issues/1366. So the options are either:
- non-vectorized shapely implementation of orient. This would be unacceptably slow.
- geoarrow-based orient implementation in python. This would be ideal but not likely to be imminently implemented.
- JS-based orientation implementation. This either brings in a wasm implementation (not ideal here) or implements a custom JS function on geoarrow arrays (preferred, but the tooling for geoarrow in pure JS isn't there yet)
So the end goal here is:
- Implement a fast winding order algorithm in rust on geoarrow memory to do in python.
- Implement an orientation checking function in pure JS on geoarrow memory (maybe in geoarrow/deck.gl-layers for now)
- Set the geoarrow winding order flag when winding order is checked/validated in python so it doesn't get done again in js.
Ref https://github.com/geoarrow/deck.gl-layers/issues/36
Note that geoarrow-js now has a winding order check and fix https://github.com/geoarrow/geoarrow-js/blob/main/src/algorithm/winding.ts