SFCGAL 2.3.0
SFCGAL::Polygon Class Reference

A Polygon in SFA with holes. More...

#include <Polygon.h>

Public Types

using iterator
 Iterator type for polygon rings.
using const_iterator
 Const iterator type for polygon rings.

Public Member Functions

 Polygon ()
 Empty Polygon constructor.
 Polygon (const std::vector< LineString > &rings)
 Constructor with an exterior ring.
 Polygon (const LineString &exteriorRing)
 Constructor with an exterior ring.
 Polygon (LineString *exteriorRing)
 Constructor with an exterior ring (takes ownership).
 Polygon (std::unique_ptr< LineString > exteriorRing)
 Constructor with an exterior ring (takes ownership).
 Polygon (const Triangle &triangle)
 Constructor with a Triangle.
 Polygon (const Polygon &other)
 Copy constructor.
 Polygon (const CGAL::Polygon_2< Kernel > &other)
 Constructor from CGAL::Polygon_2<K>.
 Polygon (const CGAL::Polygon_with_holes_2< Kernel > &poly)
 Constructor from CGAL::Polygon_with_holes_2<K>.
auto operator= (Polygon other) -> Polygon &
 assign operator
 ~Polygon () override
 destructor
auto geometryType () const -> std::string override
 Get the geometry type as string.
auto geometryTypeId () const -> GeometryType override
 Get the geometry type identifier.
auto coordinateDimension () const -> int override
 Get the coordinate dimension.
auto isEmpty () const -> bool override
 Check if the polygon is empty.
auto is3D () const -> bool override
 Check if the polygon has 3D coordinates.
auto isMeasured () const -> bool override
 Check if the polygon has measured coordinates.
auto dropZ () -> bool override
 Drop Z coordinate from all points.
auto dropM () -> bool override
 Drop M coordinate from all points.
auto swapXY () -> void override
 Swap X and Y coordinates of all points.
auto isCounterClockWiseOriented () const -> bool
 Check whether the 2D polygon is pointing up.
void reverse ()
 reverse Polygon orientation
auto exteriorRing () const -> const LineString &
 [OGC/SFA]returns the exterior ring
auto exteriorRing () -> LineString &
 [OGC/SFA]returns the exterior ring
void setExteriorRing (const LineString &ring)
 Sets the exterior ring.
void setExteriorRing (LineString *ring)
 Sets the exterior ring (takes ownership).
void setExteriorRing (std::unique_ptr< LineString > ring)
 Sets the exterior ring.
auto hasInteriorRings () const -> bool
 Test if the polygon has interior rings.
auto numInteriorRings () const -> size_t
 [OGC/SFA]returns the number of interior rings
auto interiorRingN (const size_t &n) const -> const LineString &
 [OGC/SFA]returns the nth interior ring
auto interiorRingN (const size_t &n) -> LineString &
 [OGC/SFA]returns the nth interior ring
auto numRings () const -> size_t
 Returns the number of rings.
auto ringN (const size_t &n) const -> const LineString &
 Returns the n-th ring, 0 is exteriorRing.
auto ringN (const size_t &n) -> LineString &
 Returns the n-th ring, 0 is exteriorRing.
void addInteriorRing (const LineString &ls)
 append a ring to the Polygon
void addInteriorRing (LineString *ls)
 append a ring to the Polygon (take ownership)
void addInteriorRing (std::unique_ptr< LineString > ring)
 Adds a ring to the Polygon.
void addRing (const LineString &ls)
 append a ring to the Polygon
void addRing (LineString *ls)
 append a ring to the Polygon (take ownership)
auto begin () -> iterator
 Get iterator to beginning of rings.
auto begin () const -> const_iterator
 Get const iterator to beginning of rings.
auto end () -> iterator
 Get iterator to end of rings.
auto end () const -> const_iterator
 Get const iterator to end of rings.
auto toPolygon_2 (bool fixOrientation=true) const -> CGAL::Polygon_2< Kernel >
 Convert to CGAL::Polygon_2.
auto toPolygon_with_holes_2 (bool fixOrientation=true) const -> CGAL::Polygon_with_holes_2< Kernel >
 Convert to CGAL::Polygon_with_holes_2.
void accept (GeometryVisitor &visitor) override
 Accept a geometry visitor.
void accept (ConstGeometryVisitor &visitor) const override
 Accept a const geometry visitor.
template<class Archive>
void serialize (Archive &ar, const unsigned int)
 Serializer.

Detailed Description

A Polygon in SFA with holes.

Member Typedef Documentation

◆ const_iterator

Initial value:
std::vector<std::unique_ptr<LineString>>::const_iterator>
Iterator adapter that dereferences unique_ptr elements automatically.
Definition DereferenceIterator.h:22
DereferenceIterator< std::vector< std::unique_ptr< Geometry > >::const_iterator > const_iterator
Const iterator type for geometry collection.
Definition GeometryCollection.h:30

Const iterator type for polygon rings.

◆ iterator

Initial value:
DereferenceIterator< std::vector< std::unique_ptr< Geometry > >::iterator > iterator
Iterator type for geometry collection.
Definition GeometryCollection.h:27

Iterator type for polygon rings.

Constructor & Destructor Documentation

◆ Polygon() [1/9]

SFCGAL::Polygon::Polygon ( )

Empty Polygon constructor.

◆ Polygon() [2/9]

SFCGAL::Polygon::Polygon ( const std::vector< LineString > & rings)

Constructor with an exterior ring.

Parameters
ringsVector of rings (first is exterior, rest are holes)

◆ Polygon() [3/9]

SFCGAL::Polygon::Polygon ( const LineString & exteriorRing)

Constructor with an exterior ring.

Parameters
exteriorRingThe exterior ring of the polygon

◆ Polygon() [4/9]

SFCGAL::Polygon::Polygon ( LineString * exteriorRing)

Constructor with an exterior ring (takes ownership).

Parameters
exteriorRingThe exterior ring of the polygon
Deprecated
The unique_ptr version should be used instead

◆ Polygon() [5/9]

SFCGAL::Polygon::Polygon ( std::unique_ptr< LineString > exteriorRing)

Constructor with an exterior ring (takes ownership).

Parameters
exteriorRingA unique pointer to the exterior ring of the exterior ring

◆ Polygon() [6/9]

SFCGAL::Polygon::Polygon ( const Triangle & triangle)

Constructor with a Triangle.

Parameters
triangleThe triangle to convert to a polygon

◆ Polygon() [7/9]

SFCGAL::Polygon::Polygon ( const Polygon & other)

Copy constructor.

Parameters
otherThe polygon to copy from

◆ Polygon() [8/9]

SFCGAL::Polygon::Polygon ( const CGAL::Polygon_2< Kernel > & other)

Constructor from CGAL::Polygon_2<K>.

Parameters
otherThe CGAL polygon to convert

◆ Polygon() [9/9]

SFCGAL::Polygon::Polygon ( const CGAL::Polygon_with_holes_2< Kernel > & poly)

Constructor from CGAL::Polygon_with_holes_2<K>.

Parameters
polyThe CGAL polygon with holes to convert

◆ ~Polygon()

SFCGAL::Polygon::~Polygon ( )
overridedefault

destructor

Member Function Documentation

◆ accept() [1/2]

void SFCGAL::Polygon::accept ( ConstGeometryVisitor & visitor) const
override

Accept a const geometry visitor.

Parameters
visitorConst visitor to accept

◆ accept() [2/2]

void SFCGAL::Polygon::accept ( GeometryVisitor & visitor)
override

Accept a geometry visitor.

Parameters
visitorVisitor to accept

◆ addInteriorRing() [1/3]

void SFCGAL::Polygon::addInteriorRing ( const LineString & ls)
inline

append a ring to the Polygon

Parameters
lsThe line string to add as interior ring

◆ addInteriorRing() [2/3]

void SFCGAL::Polygon::addInteriorRing ( LineString * ls)
inline

append a ring to the Polygon (take ownership)

Parameters
lsThe line string to add as interior ring
Deprecated
The unique_ptr version should be used instead

◆ addInteriorRing() [3/3]

void SFCGAL::Polygon::addInteriorRing ( std::unique_ptr< LineString > ring)
inline

Adds a ring to the Polygon.

Parameters
ringA unique pointer to the LineString object representing the new ring to add. Ownership of this ring is moved into the Polygon.

◆ addRing() [1/2]

void SFCGAL::Polygon::addRing ( const LineString & ls)
inline

append a ring to the Polygon

Parameters
lsLineString to add as ring
Deprecated
addInteriorRing

◆ addRing() [2/2]

void SFCGAL::Polygon::addRing ( LineString * ls)
inline

append a ring to the Polygon (take ownership)

Parameters
lsPointer to LineString to add as ring
Deprecated
addInteriorRing

◆ begin() [1/2]

auto SFCGAL::Polygon::begin ( ) -> iterator
inline

Get iterator to beginning of rings.

Returns
Iterator to first ring

◆ begin() [2/2]

auto SFCGAL::Polygon::begin ( ) const -> const_iterator
inlinenodiscard

Get const iterator to beginning of rings.

Returns
Const iterator to first ring

◆ coordinateDimension()

auto SFCGAL::Polygon::coordinateDimension ( ) const -> int
nodiscardoverride

Get the coordinate dimension.

Returns
Number of coordinates per point

◆ dropM()

auto SFCGAL::Polygon::dropM ( ) -> bool
override

Drop M coordinate from all points.

Returns
true if M was dropped, false otherwise

◆ dropZ()

auto SFCGAL::Polygon::dropZ ( ) -> bool
override

Drop Z coordinate from all points.

Returns
true if Z was dropped, false otherwise

◆ end() [1/2]

auto SFCGAL::Polygon::end ( ) -> iterator
inline

Get iterator to end of rings.

Returns
Iterator to past-the-end

◆ end() [2/2]

auto SFCGAL::Polygon::end ( ) const -> const_iterator
inlinenodiscard

Get const iterator to end of rings.

Returns
Const iterator to past-the-end

◆ exteriorRing() [1/2]

auto SFCGAL::Polygon::exteriorRing ( ) -> LineString &
inline

[OGC/SFA]returns the exterior ring

Returns
Reference to the exterior ring

◆ exteriorRing() [2/2]

auto SFCGAL::Polygon::exteriorRing ( ) const -> const LineString &
inlinenodiscard

[OGC/SFA]returns the exterior ring

Returns
Const reference to the exterior ring

◆ geometryType()

auto SFCGAL::Polygon::geometryType ( ) const -> std::string
nodiscardoverride

Get the geometry type as string.

Returns
"Polygon"

◆ geometryTypeId()

auto SFCGAL::Polygon::geometryTypeId ( ) const -> GeometryType
nodiscardoverride

Get the geometry type identifier.

Returns
TYPE_POLYGON

◆ hasInteriorRings()

auto SFCGAL::Polygon::hasInteriorRings ( ) const -> bool
inlinenodiscard

Test if the polygon has interior rings.

Returns
true if polygon has holes, false otherwise

◆ interiorRingN() [1/2]

auto SFCGAL::Polygon::interiorRingN ( const size_t & n) -> LineString &
inline

[OGC/SFA]returns the nth interior ring

Parameters
nThe index of the interior ring to get
Returns
Reference to the nth interior ring

◆ interiorRingN() [2/2]

auto SFCGAL::Polygon::interiorRingN ( const size_t & n) const -> const LineString &
inlinenodiscard

[OGC/SFA]returns the nth interior ring

Parameters
nThe index of the interior ring to get
Returns
Const reference to the nth interior ring

◆ is3D()

auto SFCGAL::Polygon::is3D ( ) const -> bool
nodiscardoverride

Check if the polygon has 3D coordinates.

Returns
true if 3D, false otherwise

◆ isCounterClockWiseOriented()

auto SFCGAL::Polygon::isCounterClockWiseOriented ( ) const -> bool
nodiscard

Check whether the 2D polygon is pointing up.

Returns
true if counter-clockwise oriented, false otherwise

◆ isEmpty()

auto SFCGAL::Polygon::isEmpty ( ) const -> bool
nodiscardoverride

Check if the polygon is empty.

Returns
true if empty, false otherwise

◆ isMeasured()

auto SFCGAL::Polygon::isMeasured ( ) const -> bool
nodiscardoverride

Check if the polygon has measured coordinates.

Returns
true if measured, false otherwise

◆ numInteriorRings()

auto SFCGAL::Polygon::numInteriorRings ( ) const -> size_t
inlinenodiscard

[OGC/SFA]returns the number of interior rings

Returns
Number of interior rings (holes)

◆ numRings()

auto SFCGAL::Polygon::numRings ( ) const -> size_t
inlinenodiscard

Returns the number of rings.

Returns
Total number of rings (exterior + interior)

◆ operator=()

auto SFCGAL::Polygon::operator= ( Polygon other) -> Polygon &

assign operator

Parameters
otherThe polygon to assign from
Returns
Reference to this polygon

◆ reverse()

void SFCGAL::Polygon::reverse ( )

reverse Polygon orientation

◆ ringN() [1/2]

auto SFCGAL::Polygon::ringN ( const size_t & n) -> LineString &
inline

Returns the n-th ring, 0 is exteriorRing.

Parameters
nThe ring index (0 for exterior ring)
Returns
Reference to the nth ring
Warning
not standard, avoid conditionnal to access rings

◆ ringN() [2/2]

auto SFCGAL::Polygon::ringN ( const size_t & n) const -> const LineString &
inlinenodiscard

Returns the n-th ring, 0 is exteriorRing.

Parameters
nThe ring index (0 for exterior ring)
Returns
Const reference to the nth ring
Warning
not standard, avoid conditionnal to access rings

◆ serialize()

template<class Archive>
void SFCGAL::Polygon::serialize ( Archive & ar,
const unsigned int  )
inline

Serializer.

Parameters
arArchive for serialization

◆ setExteriorRing() [1/3]

void SFCGAL::Polygon::setExteriorRing ( const LineString & ring)
inline

Sets the exterior ring.

Parameters
ringThe new exterior ring

◆ setExteriorRing() [2/3]

void SFCGAL::Polygon::setExteriorRing ( LineString * ring)
inline

Sets the exterior ring (takes ownership).

Parameters
ringThe new exterior ring
Deprecated
The unique_ptr version should be used instead

◆ setExteriorRing() [3/3]

void SFCGAL::Polygon::setExteriorRing ( std::unique_ptr< LineString > ring)
inline

Sets the exterior ring.

Replaces the exterior ring with the provided one.

Parameters
ringA unique pointer to the ring object to set. Ownership is transferred to this class.

◆ swapXY()

auto SFCGAL::Polygon::swapXY ( ) -> void
override

Swap X and Y coordinates of all points.

◆ toPolygon_2()

auto SFCGAL::Polygon::toPolygon_2 ( bool fixOrientation = true) const -> CGAL::Polygon_2< Kernel >
nodiscard

Convert to CGAL::Polygon_2.

Does not consider holes, if any

Parameters
fixOrientationforce exterior ring orientation to counter clockwise
Returns
CGAL 2D polygon representation

◆ toPolygon_with_holes_2()

auto SFCGAL::Polygon::toPolygon_with_holes_2 ( bool fixOrientation = true) const -> CGAL::Polygon_with_holes_2< Kernel >
nodiscard

Convert to CGAL::Polygon_with_holes_2.

Parameters
fixOrientationforce exterior ring orientation to counter clockwise and interior ring to clockwise.
Returns
CGAL 2D polygon with holes representation