Skip to contents

Rewinds each polygon so its exterior and interior rings follow a consistent direction. The geometry type of the output matches the input.

Usage

ga_orient(geometry, direction = "default")

Arguments

geometry

a GeoArrow polygon or multipolygon array

direction

one of "default", "reversed", "ccw", or "cw"

Value

a GeoArrow array of the same geometry type as geometry

Details

"default" gives a counter-clockwise exterior ring and clockwise interior rings, which is the winding the OGC simple features and GeoJSON specifications call for. "reversed" gives the opposite. "ccw" and "cw" are accepted as aliases and refer to the exterior ring.

Rewinding does not change which points a polygon covers, only the order its coordinates are stored in. A null geometry stays null.

References

Orient

See also

Examples

# a clockwise square
ring <- rbind(c(0, 0), c(0, 1), c(1, 1), c(1, 0), c(0, 0))
p <- sf::st_polygon(list(ring))
g <- geoarrow::as_geoarrow_array(sf::st_sfc(p))

ga_winding_order(g)
#> <nanoarrow_array string[1]>
#>  $ length    : int 1
#>  $ null_count: int 0
#>  $ offset    : int 0
#>  $ buffers   :List of 3
#>   ..$ :<nanoarrow_buffer validity<bool>[null] ``
#>   ..$ :<nanoarrow_buffer data_offset<int32>[2][8 b]> `0 9`
#>   ..$ :<nanoarrow_buffer data<string>[9 b]> `clockwise`
#>  $ dictionary: NULL
#>  $ children  : list()
ga_winding_order(ga_orient(g, "default"))
#> <nanoarrow_array string[1]>
#>  $ length    : int 1
#>  $ null_count: int 0
#>  $ offset    : int 0
#>  $ buffers   :List of 3
#>   ..$ :<nanoarrow_buffer validity<bool>[null] ``
#>   ..$ :<nanoarrow_buffer data_offset<int32>[2][8 b]> `0 16`
#>   ..$ :<nanoarrow_buffer data<string>[16 b]> `counterclockwise`
#>  $ dictionary: NULL
#>  $ children  : list()