MapWinGIS:Shape Create

This is a back-up of the WIKI.
Not all links might work
We're working on a new wiki.

Main Page | Recent changes | View source | Page history | Log in / create account |

Printable version | Disclaimers | Privacy policy

Create

Creates a new shape of the specified type.
A line or polygon shape is only valid if it has at least one part.


VB.NET Usage

Function Create(ShpType As MapWinGIS.ShpfileType) As Boolean

            Parameters

ShpType

The type of the shape to be created.
ReturnValue A boolean value representing the success or failure of creating the new shape.

Sample Code

    Private Sub CreateShape()
        Dim shape As New MapWinGIS.Shape()
        Dim success As Boolean
        'Create a new polygon shape
        success = shape.Create(MapWinGIS.ShpfileType.SHP_POLYGON)
    End Sub
  

VB 6 Usage
Function Create(ShpType As ShpfileType) As Boolean
            Parameters

ShpType

The type of the shape to be created.
ReturnValue A boolean value representing the success or failure of creating the new shape.

Sample Code

    Private Sub CreateShape()
        Dim shape As New MapWinGIS.shape
        Dim success As Boolean
        'Create a new polygon shape
        success = shape.Create(SHP_POLYGON)
    End Sub


C# Usage
bool IShape.Create(ShpfileType shpType)
            Parameters

ShpType

The type of the shape to be created.
ReturnValue A boolean value representing the success or failure of creating the new shape.

Sample Code

 // Create points:
 MapWinGIS.Point pt1 = new MapWinGIS.Point();
 MapWinGIS.Point pt2 = new MapWinGIS.Point();
 MapWinGIS.Point pt3 = new MapWinGIS.Point();
 MapWinGIS.Point pt4 = new MapWinGIS.Point();
 pt1.x = x + startX; pt1.y = y + startY;
 pt2.x = x + startX + 2; pt2.y = y + startY;
 pt3.x = x + startX + 2; pt3.y = y + startY + 2;
 pt4.x = x + startX; pt4.y = y + startY + 2;
 // Create shape:                         
 MapWinGIS.Shape shape = new MapWinGIS.Shape();
 if (!shape.Create(MapWinGIS.ShpfileType.SHP_POLYGON))
 {
     throw new System.Exception("Error in shape.Create: " + shape.get_ErrorMsg(shape.LastErrorCode));
 }
 // Create first part:
 int partIndex = shape.NumParts;
 if (!shape.InsertPart(0, ref partIndex))
 {
     throw new System.Exception("Error! In shape.InsertPart: " + shape.get_ErrorMsg(shape.LastErrorCode));
 }
 // Insert the point into the shape
 int numPoint = 0;
 if (!shape.InsertPoint(pt1, ref numPoint))
 {
     throw new System.Exception("Error in shape.InsertPoint: " + shape.get_ErrorMsg(shape.LastErrorCode));
 }
 numPoint++;
 shape.InsertPoint(pt2, ref numPoint);
 numPoint++;
 shape.InsertPoint(pt3, ref numPoint);
 numPoint++;
 shape.InsertPoint(pt4, ref numPoint);
 numPoint++;
 shape.InsertPoint(pt1, ref numPoint); // Close the polygon
 if (!shape.IsValid)
 {
     throw new System.Exception("Error! Created shape is not valid.");
 }
 // Add new polygon to shapefile: 
 int numShapes = sf.NumShapes;
 if (!sf.EditInsertShape(shape, ref numShapes))
 {
     throw new System.Exception("Error in sf.EditInsertShape: " + sf.get_ErrorMsg(sf.LastErrorCode));
 }
 // Add value:
 if (!sf.EditCellValue(fldIndex, numShapes, numShapes))
 {
     throw new System.Exception("Error in sf.EditCellValue: " + sf.get_ErrorMsg(sf.LastErrorCode));
 }

Retrieved from "http://mapwindow.org/wiki/index.php/MapWinGIS:Shape_Create"

This page has been accessed 4,356 times. This page was last modified on 16 November 2009, at 08:05.