Web API Reference | MapGuide Open Source

- Overview
- Modules
- Classes

# MgCurvePolygon Class Reference
[MgCurvePolygon]

An MgCurvePolygon is a region, defined by 1 exterior boundary and 0 or more interior boundaries. More...

Inherits MgRegion.

List of all members.

## Public Member Functions
virtual MgGeometricEntity * | Copy ()
virtual INT32 | GetDimension ()
virtual MgCurveRing * | GetExteriorRing ()
| Gets the exterior ring of the polygon.
virtual INT32 | GetGeometryType ()
virtual MgCurveRing * | GetInteriorRing (INT32 index)
virtual INT32 | GetInteriorRingCount ()
virtual bool | IsClosed ()
virtual bool | IsEmpty ()
virtual MgGeometricEntity * | Transform (MgTransform *transform)
| Returns a transformed copy of this geometric entity.

## Detailed Description

An MgCurvePolygon is a region, defined by 1 exterior boundary and 0 or more interior boundaries.

Remarks:
  Each interior boundary defines a hole in the polygon. An interior or exterior boundary is defined as an MgCurveRing composed of one or more curve segments. The curve segments are connected to one another so that the end point of each segment is the start point of the next segment in the segment list. The end point of the last segment in the ring is the start point of the first segment.
  An object of this type is constructed by calling the non-static MgGeometryFactory::CreateCurvePolygon() method and, once constructed, is immutable.

Example (PHP)
The following code shows the construction of a circle, which has a circular hole cut out of the middle of it.

     $geometryFactory = new MgGeometryFactory();
     $curveSegmentCollection = new MgCurveSegmentCollection();
     $curveRingCollection = new MgCurveRingCollection();

     // create first curve segment for the external boundary
     $startCoordinate = $geometryFactory->CreateCoordinateXY(0,2);
     $controlCoordinate = $geometryFactory->CreateCoordinateXY(2,4);
     $endCoordinate = $geometryFactory->CreateCoordinateXY(4,2);
     $arcSegment = $geometryFactory->CreateArcSegment($startCoordinate, $endCoordinate, $controlCoordinate);
     $index = $curveSegmentCollection->Add($arcSegment);

     // create second curve segment for the external boundary
     $startCoordinate = $geometryFactory->CreateCoordinateXY(4,2);
     $controlCoordinate = $geometryFactory->CreateCoordinateXY(2,0);
     $endCoordinate = $geometryFactory->CreateCoordinateXY(0,2);
     $arcSegment = $geometryFactory->CreateArcSegment($startCoordinate, $endCoordinate, $controlCoordinate);
     $index = $curveSegmentCollection->Add($arcSegment);

     // create curve ring for the external boundary
     $exteriorCurveRing = $geometryFactory->CreateCurveRing($curveSegmentCollection);

     // clear the collection before adding the next curve segment
     $curveSegmentCollection->Clear();

     // create first curve segment for an internal boundary
     $startCoordinate = $geometryFactory->CreateCoordinateXY(1,2);
     $controlCoordinate = $geometryFactory->CreateCoordinateXY(2,3);
     $endCoordinate = $geometryFactory->CreateCoordinateXY(3,2);
     $arcSegment = $geometryFactory->CreateArcSegment($startCoordinate, $endCoordinate, $controlCoordinate);
     $index = $curveSegmentCollection->Add($arcSegment);

     // create second curve segment for an internal boundary
     $startCoordinate = $geometryFactory->CreateCoordinateXY(3,2);
     $controlCoordinate = $geometryFactory->CreateCoordinateXY(2,1);
     $endCoordinate = $geometryFactory->CreateCoordinateXY(1,2);
     $arcSegment = $geometryFactory->CreateArcSegment($startCoordinate, $endCoordinate, $controlCoordinate);
     $index = $curveSegmentCollection->Add($arcSegment);

     // create curve ring for an internal boundary
     $interiorCurveRing = $geometryFactory->CreateCurveRing($curveSegmentCollection);
     $index = $curveRingCollection->Add($interiorCurveRing);

     // create curve polygon
     $curvePolygon = $geometryFactory->CreateCurvePolygon($exteriorCurveRing, $curveRingCollection);

     // print out the Agf Text string for the geometry
     $curvePolygonAgfText = $wktReaderWriter->Write($curvePolygon);
     echo "AGF Text representation of CurvePolygon: $curvePolygonAgfText\n";

Example (C#)
The following code shows the construction of a circle, which has a circular hole cut out of the middle of it. The CreateACurvePolygonXY method calls the CreateACurveSegmentCollectionXY method. The code for the CreateACurveSegmentCollectionXY method is in the MgCurveString example code.

     using OSGeo.MapGuide;
     private MgWktReaderWriter wktReaderWriter;
     private MgGeometryFactory geometryFactory;
     private MgCurvePolygon cpnEr0224422002Ir12233212;
     private double[,] as022042 = { { 0, 0 }, { 0, 2 }, { 2, 0 }, { 4, 2 } };
     private double[,] as422402 = { { 0, 0 }, { 4, 2 }, { 2, 4 }, { 0, 2 } };
     private double[,] as122332 = { { 0, 0 }, { 1, 2 }, { 2, 3 }, { 3, 2 } };
     private double[,] as322112 = { { 0, 0 }, { 3, 2 }, { 2, 1 }, { 1, 2 } };
     private double[][,] cpEr0220422402;
     private double[][,] cpIr122332112;
     private double[][][,] cpEr0220422402Ir122332112Data;
     private String geometryAgfText;

     // The following BNF is for the construction of a string representation of the geometry
     // <CurvePolygon> ::= '(' <CurveStringCollection> ')'
     // <CurveStringCollection> ::= <CurveString>
     //                             | <CurveStringCollection> ',' <CurveString>
     // See the comments preceding CreateACurveStringXY() in the example code for MgCurveString
     // for the rest of the BNF.
     public MgCurvePolygon CreateACurvePolygonXY(double[][][,] ringsData)
     {
         MgCurveSegmentCollection segments = CreateACurveSegmentCollectionXY(ringsData[0]);
         MgCurveRing exteriorRing = geometryFactory.CreateCurveRing(segments);
         MgCurveRingCollection interiorRings = new MgCurveRingCollection();
         for (int i = 1; i < ringsData.GetLength(0); i++)
         {
             segments = CreateACurveSegmentCollectionXY(ringsData[i]);
             interiorRings.Add(geometryFactory.CreateCurveRing(segments));
         }
         return geometryFactory.CreateCurvePolygon(exteriorRing, interiorRings);
     }

     geometryFactory = new MgGeometryFactory();
     cpEr0220422402 = new double[2][,];
     cpEr0220422402[0] = as022042;
     cpEr0220422402[1] = as422402;
     cpIr122332112 = new double[2][,];
     cpIr122332112[0] = as122332;
     cpIr122332112[1] = as322112;
     cpEr0220422402Ir122332112Data = new double[2][][,];
     cpEr0220422402Ir122332112Data[0] = cpEr0220422402;
     cpEr0220422402Ir122332112Data[1] = cpIr122332112;
     cpnEr0224422002Ir12233212 = CreateACurvePolygonXY(cpEr0220422402Ir122332112Data);

     // print out the Agf Text string for the geometry
     wktReaderWriter = new MgWktReaderWriter();
     geometryAgfText = wktReaderWriter.Write(cpnEr0224422002Ir12233212);
     // geometryAgfText now contains:
     // "CURVEPOLYGON XY (( 0 2 (CIRCULARARCSEGMENT( 2 0, 4 2), CIRCULARARCSEGMENT( 2 4, 0 2))), ( 1 2 ( CIRCULARARCSEGMENT( 2 3, 3 2), CIRCULARARCSEGMENT( 2 1, 1 2))))"

Comments or suggestions? Send us feedback.