diff --git a/NEWS.md b/NEWS.md index ecdedd7e1..06b842bee 100644 --- a/NEWS.md +++ b/NEWS.md @@ -17,7 +17,7 @@ ## new `compareGeom` for list and SpatRasterCollection [#1207](https://github.com/rspatial/terra/issues/1207) by Sarah Endicott `is.rotated` method [#1229](https://github.com/rspatial/terra/issues/1229) by Andy Lyons - +`forceCCW` method to force counter-clockwise orientation [#1249](https://github.com/rspatial/terra/issues/1249) by srfall. # version 1.7-39 diff --git a/R/geom.R b/R/geom.R index b0440f4c4..e25219087 100644 --- a/R/geom.R +++ b/R/geom.R @@ -661,6 +661,6 @@ setMethod("forceCCW", signature(x="SpatVector"), function(x) { x <- deepcopy(x) x@pnt$make_CCW() - x + messages(x) } ) diff --git a/man/forceCCW.Rd b/man/forceCCW.Rd new file mode 100644 index 000000000..4978f1a69 --- /dev/null +++ b/man/forceCCW.Rd @@ -0,0 +1,33 @@ +\name{forceCCW} + +\alias{forceCCW} +\alias{forceCCW,SpatVector-method} + + +\title{force counter-clockwise polygons} + + +\description{ +Assure that the nodes of outer rings of polygons are in counter-clockwise order. +} + +\usage{ +\S4method{forceCCW}{SpatVector}(x) +} + +\arguments{ + \item{x}{SpatVector of polygons} +} + +\value{ +SpatVector +} + +\examples{ +p <- vect("POLYGON ((2 45, 2 55, 18 55, 18 45, 2 45))") +pcc <- forceCCW(p) +geom(pcc, wkt=TRUE) +} + +\keyword{spatial} + diff --git a/src/geos_methods.cpp b/src/geos_methods.cpp index 5d854db55..53f926865 100644 --- a/src/geos_methods.cpp +++ b/src/geos_methods.cpp @@ -3218,3 +3218,30 @@ bool SpatPart::is_CCW() { } #endif } + + + +void SpatVector::make_CCW() { + #ifndef GEOS370 + setError("GEOS >= 3.7 needed for CCW"); + return; + #else + size_t n = size(); + if (n == 0) return; + if (geoms[0].gtype != polygons) return; + for (size_t i=0; i>>> SpatVector::polygonsL -void SpatVector::make_CCW() { - size_t n = size(); - if (n == 0) return; - if (geoms[0].gtype != polygons) return; - for (size_t i=0; i