# OGRPolygon Class Reference

`#include <ogr_geometry.h>`

Inheritance diagram for OGRPolygon:

List of all members.

## Public Member Functions
| OGRPolygon ()
| Create an empty polygon.
virtual const char * | getGeometryName () const
| Fetch WKT name for geometry type.
virtual OGRwkbGeometryType | getGeometryType () const
| Fetch geometry type.
virtual OGRGeometry * | clone () const
| Make a copy of this object.
virtual void | empty ()
| Clear geometry information. This restores the geometry to it's initial state after construction, and before assignment of actual geometry.
virtual OGRErr | transform (OGRCoordinateTransformation *poCT)
| Apply arbitrary coordinate transformation to geometry.
virtual void | flattenTo2D ()
| Convert geometry to strictly 2D. In a sense this converts all Z coordinates to 0.0.
virtual OGRBoolean | IsEmpty () const
| Returns TRUE (non-zero) if the object has no points.
virtual void | segmentize (double dfMaxLength)
| Modify the geometry such it has no segment longer then the given distance.
virtual double | get_Area () const
| Compute area of polygon.
virtual int | Centroid (OGRPoint *poPoint) const
| Compute the polygon centroid.
virtual int | PointOnSurface (OGRPoint *poPoint) const
| This method relates to the SFCOM ISurface::get_PointOnSurface() method.
virtual int | WkbSize () const
| Returns size of related binary representation.
virtual OGRErr | importFromWkb (unsigned char *, int=-1)
| Assign geometry from well known binary data.
virtual OGRErr | exportToWkb (OGRwkbByteOrder, unsigned char *) const
| Convert a geometry into well known binary format.
virtual OGRErr | importFromWkt (char **)
| Assign geometry from well known text data.
virtual OGRErr | exportToWkt (char **ppszDstText) const
| Convert a geometry into well known text format.
virtual int | getDimension () const
| Get the dimension of this object.
virtual void | getEnvelope (OGREnvelope *psEnvelope) const
| Computes and returns the bounding envelope for this geometry in the passed psEnvelope structure.
virtual OGRBoolean | Equals (OGRGeometry *) const
| Returns TRUE if two geometries are equivalent.
virtual void | setCoordinateDimension (int nDimension)
| Set the coordinate dimension.
void | addRing (OGRLinearRing *)
| Add a ring to a polygon.
void | addRingDirectly (OGRLinearRing *)
| Add a ring to a polygon.
OGRLinearRing * | getExteriorRing ()
| Fetch reference to external polygon ring.
int | getNumInteriorRings () const
| Fetch the number of internal rings.
OGRLinearRing * | getInteriorRing (int)
| Fetch reference to indicated internal ring.
virtual void | closeRings ()
| Force rings to be closed.

## Detailed Description

Concrete class representing polygons.

Note that the OpenGIS simple features polygons consist of one outer ring, and zero or more inner rings. A polygon cannot represent disconnected regions (such as multiple islands in a political body). The OGRMultiPolygon must be used for this.

## Member Function Documentation

void OGRPolygon::addRing | ( | OGRLinearRing * | poNewRing | ) |

Add a ring to a polygon.

If the polygon has no external ring (it is empty) this will be used as the external ring, otherwise it is used as an internal ring. The passed OGRLinearRing remains the responsibility of the caller (an internal copy is made).

This method has no SFCOM analog.

Parameters:

  | poNewRing | ring to be added to the polygon.

References OGRGeometry::getCoordinateDimension().

Referenced by clone(), OGRGeometryFactory::forceToPolygon(), and OGRLayer::SetSpatialFilterRect().

void OGRPolygon::addRingDirectly | ( | OGRLinearRing * | poNewRing | ) |

Add a ring to a polygon.

If the polygon has no external ring (it is empty) this will be used as the external ring, otherwise it is used as an internal ring. Ownership of the passed ring is assumed by the OGRPolygon, but otherwise this method operates the same as OGRPolygon::AddRing().

This method has no SFCOM analog.

Parameters:

  | poNewRing | ring to be added to the polygon.

References OGRGeometry::getCoordinateDimension().

Referenced by OGRGeometryFactory::createFromFgf(), OGRMultiPolygon::importFromWkt(), and OGRBuildPolygonFromEdges().

int OGRPolygon::Centroid | ( | OGRPoint * | poPoint | ) | const`[virtual]`

Compute the polygon centroid.

The centroid location is applied to the passed in OGRPoint object.

Returns:
  OGRERR_NONE on success or OGRERR_FAILURE on error.

Implements OGRSurface.

References OGRPoint::getGeometryType(), OGRPoint::getX(), OGRPoint::getY(), OGRPoint::setX(), OGRPoint::setY(), and wkbPoint.

OGRGeometry * OGRPolygon::clone | ( |  | ) | const`[virtual]`

Make a copy of this object.

This method relates to the SFCOM IGeometry::clone() method.

This method is the same as the C function OGR_G_Clone().

Returns:
  a new object instance with the same geometry, and spatial reference system as the original.

Implements OGRGeometry.

References addRing(), OGRGeometry::assignSpatialReference(), and OGRGeometry::getSpatialReference().

void OGRPolygon::closeRings | ( |  | ) | `[virtual]`

Force rings to be closed.

If this geometry, or any contained geometries has polygon rings that are not closed, they will be closed by adding the starting point at the end.

Reimplemented from OGRGeometry.

void OGRPolygon::empty | ( |  | ) | `[virtual]`

Clear geometry information. This restores the geometry to it's initial state after construction, and before assignment of actual geometry.

This method relates to the SFCOM IGeometry::Empty() method.

This method is the same as the C function OGR_G_Empty().

Implements OGRGeometry.

OGRBoolean OGRPolygon::Equals | ( | OGRGeometry * | poOtherGeom | ) | const`[virtual]`

Returns TRUE if two geometries are equivalent.

This method is the same as the C function OGR_G_Equals().

Returns:
  TRUE if equivalent or FALSE otherwise.

Implements OGRGeometry.

References OGRLineString::Equals(), getExteriorRing(), getGeometryType(), OGRGeometry::getGeometryType(), getInteriorRing(), and getNumInteriorRings().

OGRErr OGRPolygon::exportToWkb | ( | OGRwkbByteOrder | eByteOrder,
|  | unsigned char * | pabyData |
| ) |  |  | const`[virtual]`

Convert a geometry into well known binary format.

This method relates to the SFCOM IWks::ExportToWKB() method.

This method is the same as the C function OGR_G_ExportToWkb().

Parameters:

  | eByteOrder | One of wkbXDR or wkbNDR indicating MSB or LSB byte order respectively.
  | pabyData | a buffer into which the binary representation is written. This buffer must be at least OGRGeometry::WkbSize() byte in size.

Returns:
  Currently OGRERR_NONE is always returned.

Implements OGRGeometry.

References OGRLinearRing::_exportToWkb(), OGRLinearRing::_WkbSize(), OGRGeometry::getCoordinateDimension(), and getGeometryType().

OGRErr OGRPolygon::exportToWkt | ( | char ** | ppszDstText | ) | const`[virtual]`

Convert a geometry into well known text format.

This method relates to the SFCOM IWks::ExportToWKT() method.

This method is the same as the C function OGR_G_ExportToWkt().

Parameters:

  | ppszDstText | a text buffer is allocated by the program, and assigned to the passed pointer.

Returns:
  Currently OGRERR_NONE is always returned.

Implements OGRGeometry.

References OGRLineString::exportToWkt(), OGRGeometry::getCoordinateDimension(), getExteriorRing(), IsEmpty(), and OGRLineString::setCoordinateDimension().

void OGRPolygon::flattenTo2D | ( |  | ) | `[virtual]`

Convert geometry to strictly 2D. In a sense this converts all Z coordinates to 0.0.

This method is the same as the C function OGR_G_FlattenTo2D().

Implements OGRGeometry.

double OGRPolygon::get_Area | ( |  | ) | const`[virtual]`

Compute area of polygon.

The area is computed as the area of the outer ring less the area of all internal rings.

Returns:
  computed area.

Implements OGRSurface.

References OGRLinearRing::get_Area(), getExteriorRing(), getInteriorRing(), and getNumInteriorRings().

Referenced by OGRMultiPolygon::get_Area().

int OGRPolygon::getDimension | ( |  | ) | const`[virtual]`

Get the dimension of this object.

This method corresponds to the SFCOM IGeometry::GetDimension() method. It indicates the dimension of the object, but does not indicate the dimension of the underlying space (as indicated by OGRGeometry::getCoordinateDimension()).

This method is the same as the C function OGR_G_GetDimension().

Returns:
  0 for points, 1 for lines and 2 for surfaces.

Implements OGRGeometry.

void OGRPolygon::getEnvelope | ( | OGREnvelope * | psEnvelope | ) | const`[virtual]`

Computes and returns the bounding envelope for this geometry in the passed psEnvelope structure.

This method is the same as the C function OGR_G_GetEnvelope().

Parameters:

  | psEnvelope | the structure in which to place the results.

Implements OGRGeometry.

References OGRLineString::getEnvelope(), OGREnvelope::MaxX, OGREnvelope::MaxY, OGREnvelope::MinX, and OGREnvelope::MinY.

OGRLinearRing * OGRPolygon::getExteriorRing | ( |  | ) |

Fetch reference to external polygon ring.

Note that the returned ring pointer is to an internal data object of the OGRPolygon. It should not be modified or deleted by the application, and the pointer is only valid till the polygon is next modified. Use the OGRGeometry::clone() method to make a separate copy within the application.

Relates to the SFCOM IPolygon::get_ExteriorRing() method.

Returns:
  pointer to external ring. May be NULL if the OGRPolygon is empty.

Referenced by OGRGeometry::dumpReadable(), Equals(), exportToWkt(), OGRGeometryFactory::forceToMultiLineString(), OGRGeometryFactory::forceToPolygon(), and get_Area().

const char * OGRPolygon::getGeometryName | ( |  | ) | const`[virtual]`

Fetch WKT name for geometry type.

There is no SFCOM analog to this method.

This method is the same as the C function OGR_G_GetGeometryName().

Returns:
  name used for this geometry type in well known text format. The returned pointer is to a static internal string and should not be modified or freed.

Implements OGRGeometry.

OGRwkbGeometryType OGRPolygon::getGeometryType | ( |  | ) | const`[virtual]`

Fetch geometry type.

Note that the geometry type may include the 2.5D flag. To get a 2D flattened version of the geometry type apply the wkbFlatten() macro to the return result.

This method is the same as the C function OGR_G_GetGeometryType().

Returns:
  the geometry type code.

Implements OGRGeometry.

References OGRGeometry::getCoordinateDimension(), wkbPolygon, and wkbPolygon25D.

Referenced by Equals(), and exportToWkb().

OGRLinearRing * OGRPolygon::getInteriorRing | ( | int | iRing | ) |

Fetch reference to indicated internal ring.

Note that the returned ring pointer is to an internal data object of the OGRPolygon. It should not be modified or deleted by the application, and the pointer is only valid till the polygon is next modified. Use the OGRGeometry::clone() method to make a separate copy within the application.

Relates to the SFCOM IPolygon::get_InternalRing() method.

Parameters:

  | iRing | internal ring index from 0 to getNumInternalRings() - 1.

Returns:
  pointer to external ring. May be NULL if the OGRPolygon is empty.

Referenced by OGRGeometry::dumpReadable(), Equals(), OGRGeometryFactory::forceToMultiLineString(), OGRGeometryFactory::forceToPolygon(), and get_Area().

int OGRPolygon::getNumInteriorRings | ( |  | ) | const

Fetch the number of internal rings.

Relates to the SFCOM IPolygon::get_NumInteriorRings() method.

Returns:
  count of internal rings, zero or more.

Referenced by OGRGeometry::dumpReadable(), Equals(), OGRGeometryFactory::forceToMultiLineString(), OGRGeometryFactory::forceToPolygon(), get_Area(), and OGRBuildPolygonFromEdges().

OGRErr OGRPolygon::importFromWkb | ( | unsigned char * | pabyData,
|  | int | nSize = `-1` |
| ) |  |  | `[virtual]`

Assign geometry from well known binary data.

The object must have already been instantiated as the correct derived type of geometry object to match the binaries type. This method is used by the OGRGeometryFactory class, but not normally called by application code.

This method relates to the SFCOM IWks::ImportFromWKB() method.

This method is the same as the C function OGR_G_ImportFromWkb().

Parameters:

  | pabyData | the binary input data.
  | nSize | the size of pabyData in bytes, or zero if not known.

Returns:
  OGRERR_NONE if all goes well, otherwise any of OGRERR_NOT_ENOUGH_DATA, OGRERR_UNSUPPORTED_GEOMETRY_TYPE, or OGRERR_CORRUPT_DATA may be returned.

Implements OGRGeometry.

References OGRLinearRing::_importFromWkb(), OGRLinearRing::_WkbSize(), VSIMalloc2(), and wkbPolygon.

OGRErr OGRPolygon::importFromWkt | ( | char ** | ppszInput | ) | `[virtual]`

Assign geometry from well known text data.

The object must have already been instantiated as the correct derived type of geometry object to match the text type. This method is used by the OGRGeometryFactory class, but not normally called by application code.

This method relates to the SFCOM IWks::ImportFromWKT() method.

This method is the same as the C function OGR_G_ImportFromWkt().

Parameters:

  | ppszInput | pointer to a pointer to the source text. The pointer is updated to pointer after the consumed text.

Returns:
  OGRERR_NONE if all goes well, otherwise any of OGRERR_NOT_ENOUGH_DATA, OGRERR_UNSUPPORTED_GEOMETRY_TYPE, or OGRERR_CORRUPT_DATA may be returned.

Implements OGRGeometry.

References OGRLineString::setPoints().

OGRBoolean OGRPolygon::IsEmpty | ( |  | ) | const`[virtual]`

Returns TRUE (non-zero) if the object has no points.

Normally this returns FALSE except between when an object is instantiated and points have been assigned.

This method relates to the SFCOM IGeometry::IsEmpty() method.

Returns:
  TRUE if object is empty, otherwise FALSE.

Implements OGRGeometry.

Referenced by exportToWkt().

int OGRPolygon::PointOnSurface | ( | OGRPoint * | poPoint | ) | const`[virtual]`

This method relates to the SFCOM ISurface::get_PointOnSurface() method.

NOTE: Only implemented when GEOS included in build.

Parameters:

  | poPoint | point to be set with an internal point.

Returns:
  OGRERR_NONE if it succeeds or OGRERR_FAILURE otherwise.

Implements OGRSurface.

References OGRPoint::getGeometryType(), OGRPoint::getX(), OGRPoint::getY(), OGRPoint::setX(), OGRPoint::setY(), and wkbPoint.

void OGRPolygon::segmentize | ( | double | dfMaxLength | ) | `[virtual]`

Modify the geometry such it has no segment longer then the given distance.

Interpolated points will have Z and M values (if needed) set to 0. Distance computation is performed in 2d only

This function is the same as the C function OGR_G_Segmentize()

Parameters:

  | dfMaxLength | the maximum distance between 2 points after segmentization

Reimplemented from OGRGeometry.

void OGRPolygon::setCoordinateDimension | ( | int | nNewDimension | ) | `[virtual]`

Set the coordinate dimension.

This method sets the explicit coordinate dimension. Setting the coordinate dimension of a geometry to 2 should zero out any existing Z values. Setting the dimension of a geometry collection will not necessarily affect the children geometries.

Parameters:

  | nNewDimension | New coordinate dimension value, either 2 or 3.

Reimplemented from OGRGeometry.

OGRErr OGRPolygon::transform | ( | OGRCoordinateTransformation * | poCT | ) | `[virtual]`

Apply arbitrary coordinate transformation to geometry.

This method will transform the coordinates of a geometry from their current spatial reference system to a new target spatial reference system. Normally this means reprojecting the vectors, but it could include datum shifts, and changes of units.

Note that this method does not require that the geometry already have a spatial reference system. It will be assumed that they can be treated as having the source spatial reference system of the OGRCoordinateTransformation object, and the actual SRS of the geometry will be ignored. On successful completion the output OGRSpatialReference of the OGRCoordinateTransformation will be assigned to the geometry.

This method is the same as the C function OGR_G_Transform().

Parameters:

  | poCT | the transformation to apply.

Returns:
  OGRERR_NONE on success or an error code.

Implements OGRGeometry.

References OGRGeometry::assignSpatialReference(), OGRCoordinateTransformation::GetTargetCS(), and OGRLineString::transform().

int OGRPolygon::WkbSize | ( |  | ) | const`[virtual]`

Returns size of related binary representation.

This method returns the exact number of bytes required to hold the well known binary representation of this geometry object. Its computation may be slightly expensive for complex geometries.

This method relates to the SFCOM IWks::WkbSize() method.

This method is the same as the C function OGR_G_WkbSize().

Returns:
  size of binary representation in bytes.

Implements OGRGeometry.

References OGRLinearRing::_WkbSize(), and OGRGeometry::getCoordinateDimension().

The documentation for this class was generated from the following files:

- ogr_geometry.h
- ogrpolygon.cpp

Generated for GDAL by 1.5.7.1.