SFCGAL  2.3.0
Public Types | Public Member Functions | List of all members
SFCGAL::Polygon Class Reference

A Polygon in SFA with holes. More...

#include <Polygon.h>

Inherits SFCGAL::GeometryImpl< Derived, Base >.

Public Types

using iterator = DereferenceIterator< std::vector< std::unique_ptr< LineString >>::iterator >
 Iterator type for polygon rings. More...
 
using const_iterator = DereferenceIterator< std::vector< std::unique_ptr< LineString >>::const_iterator >
 Const iterator type for polygon rings. More...
 

Public Member Functions

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

Detailed Description

A Polygon in SFA with holes.

Member Typedef Documentation

Const iterator type for polygon rings.

using SFCGAL::Polygon::iterator = DereferenceIterator<std::vector<std::unique_ptr<LineString>>::iterator>

Iterator type for polygon rings.

Constructor & Destructor Documentation

SFCGAL::Polygon::Polygon ( )

Empty Polygon constructor.

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

Constructor with an exterior ring.

Parameters
ringsVector of rings (first is exterior, rest are holes)
SFCGAL::Polygon::Polygon ( const LineString &  exteriorRing)

Constructor with an exterior ring.

Parameters
exteriorRingThe exterior ring of the polygon
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
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
SFCGAL::Polygon::Polygon ( const Triangle &  triangle)

Constructor with a Triangle.

Parameters
triangleThe triangle to convert to a polygon
SFCGAL::Polygon::Polygon ( const Polygon &  other)

Copy constructor.

Parameters
otherThe polygon to copy from
SFCGAL::Polygon::Polygon ( const CGAL::Polygon_2< Kernel > &  other)

Constructor from CGAL::Polygon_2<K>

Parameters
otherThe CGAL polygon to convert
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
SFCGAL::Polygon::~Polygon ( )
overridedefault

destructor

Member Function Documentation

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

Accept a geometry visitor.

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

Accept a const geometry visitor.

Parameters
visitorConst visitor to accept
void SFCGAL::Polygon::addInteriorRing ( const LineString &  ls)
inline

append a ring to the Polygon

Parameters
lsThe line string to add as interior ring
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
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.
void SFCGAL::Polygon::addRing ( const LineString &  ls)
inline

append a ring to the Polygon

Parameters
lsLineString to add as ring
Deprecated:
addInteriorRing
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
auto SFCGAL::Polygon::begin ( ) -> iterator
inline

Get iterator to beginning of rings.

Returns
Iterator to first ring
auto SFCGAL::Polygon::begin ( ) const -> const_iterator
inline

Get const iterator to beginning of rings.

Returns
Const iterator to first ring
auto SFCGAL::Polygon::coordinateDimension ( ) const -> int
override

Get the coordinate dimension.

Returns
Number of coordinates per point
auto SFCGAL::Polygon::dropM ( ) -> bool
override

Drop M coordinate from all points.

Returns
true if M was dropped, false otherwise
auto SFCGAL::Polygon::dropZ ( ) -> bool
override

Drop Z coordinate from all points.

Returns
true if Z was dropped, false otherwise
auto SFCGAL::Polygon::end ( ) -> iterator
inline

Get iterator to end of rings.

Returns
Iterator to past-the-end
auto SFCGAL::Polygon::end ( ) const -> const_iterator
inline

Get const iterator to end of rings.

Returns
Const iterator to past-the-end
auto SFCGAL::Polygon::exteriorRing ( ) const -> const LineString &
inline

[OGC/SFA]returns the exterior ring

Returns
Const reference to the exterior ring
auto SFCGAL::Polygon::exteriorRing ( ) -> LineString &
inline

[OGC/SFA]returns the exterior ring

Returns
Reference to the exterior ring
auto SFCGAL::Polygon::geometryType ( ) const -> std::string
override

Get the geometry type as string.

Returns
"Polygon"
auto SFCGAL::Polygon::geometryTypeId ( ) const -> GeometryType
override

Get the geometry type identifier.

Returns
TYPE_POLYGON
auto SFCGAL::Polygon::hasInteriorRings ( ) const -> bool
inline

Test if the polygon has interior rings.

Returns
true if polygon has holes, false otherwise
auto SFCGAL::Polygon::interiorRingN ( const size_t &  n) const -> const LineString &
inline

[OGC/SFA]returns the nth interior ring

Parameters
nThe index of the interior ring to get
Returns
Const reference to the nth interior ring
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
auto SFCGAL::Polygon::is3D ( ) const -> bool
override

Check if the polygon has 3D coordinates.

Returns
true if 3D, false otherwise
auto SFCGAL::Polygon::isCounterClockWiseOriented ( ) const -> bool

Check whether the 2D polygon is pointing up.

Returns
true if counter-clockwise oriented, false otherwise
auto SFCGAL::Polygon::isEmpty ( ) const -> bool
override

Check if the polygon is empty.

Returns
true if empty, false otherwise
auto SFCGAL::Polygon::isMeasured ( ) const -> bool
override

Check if the polygon has measured coordinates.

Returns
true if measured, false otherwise
auto SFCGAL::Polygon::numInteriorRings ( ) const -> size_t
inline

[OGC/SFA]returns the number of interior rings

Returns
Number of interior rings (holes)
auto SFCGAL::Polygon::numRings ( ) const -> size_t
inline

Returns the number of rings.

Returns
Total number of rings (exterior + interior)
auto SFCGAL::Polygon::operator= ( Polygon  other) -> Polygon &

assign operator

Parameters
otherThe polygon to assign from
Returns
Reference to this polygon
void SFCGAL::Polygon::reverse ( )

reverse Polygon orientation

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

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
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
template<class Archive >
void SFCGAL::Polygon::serialize ( Archive &  ar,
const unsigned  int 
)
inline

Serializer.

Parameters
arArchive for serialization
void SFCGAL::Polygon::setExteriorRing ( const LineString &  ring)
inline

Sets the exterior ring.

Parameters
ringThe new exterior ring
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
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.
auto SFCGAL::Polygon::swapXY ( ) -> void
override

Swap X and Y coordinates of all points.

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

Convert to CGAL::Polygon_2.

Does not consider holes, if any

Parameters
fixOrientationforce exterior ring orientation to counter clockwise
Returns
CGAL 2D polygon representation
auto SFCGAL::Polygon::toPolygon_with_holes_2 ( bool  fixOrientation = true) const -> CGAL::Polygon_with_holes_2<Kernel>

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