Sunteți pe pagina 1din 43

Examples - Reading a ShapeFile Page 1 of 43

Using the OCX - Examples

How To Read a ShapeFile

In the following example it is assumed that you have dragged an instance of the ShapeFile Control
from the IDE over to your Visual Basic project and renamed the OCX instance as ShapeIn.

In this case the ShapeFile Control is used to read in a polygon ShapeFile consisting of a series of
squares, one of which has a hole in it.

VB 6 VB .Net C#

Visual Basic 6 Example:

Sub ReadShape()

Dim ThisRecord As Long, ThisData As Long, ThisPart As Long, VertCount As Long

' ShapeIn is the name of the ShapeOCX instance


With ShapeIn

.ReadDataOnMove
.OpenShape "C:\Temp\Polygon.shp", shpOpen

' Read in each shape record in turn


For ThisRecord = 1 To .RecordCount

' Print out the name and values of the ShapeFile attribute data.
For ThisData = 1 To .ShapeFields.Count

Debug.Print .ShapeFields(ThisData).FieldName, .ShapeFields(ThisData).Value

Next ThisData

' Print out the coordinates that make up this shape file
' Because we’re dealing with a polygon file, it is best to output by Parts
' You can also just output from 1 To .Vertice.Count
For ThisPart = 1 To .Parts.Count

For VertCount = .Parts(ThisPart).Begins To .Parts(ThisPart).Ends

Debug.Print .Vertices(VertCount).X_Cord, .Vertices


(VertCount).Y_Cord, .Vertices(VertCount).PartNo

Next VertCount

Next ThisPart

.MoveNext

Next ThisRecord

End With

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 2 of 43

End Sub

VB .NET Example:

Imports crpShape = ArcViewShapeFileDLL

Sub ReadShape()

Dim ShapeIn As New crpShape.ShapeFiles

With ShapeIn
.ReadDataOnMove = FullRead This is the default
OpenShape automatically moves to the first record and loads it
.OpenShape("C:\Temp\Polygon.shp", shpOpen)

For ThisRecord As Integer = 1 To .RecordCount()


Console.WriteLine("Record Number: " + ThisRecord.ToString())

Print out the name and values of the ShapeFile attribute data.
For Each mF As crpShape.ShapeField In ShapeIn.ShapeFields
Console.WriteLine(mF.FieldName + " " + mF.Value.ToString())
Next

Print out the coordinates that make up this shape file


Because we’re dealing with a polygon file, it is best to output by Parts
You can also just output from 1 To .Vertice.Count

For ThisPart As Integer = 1 To .Parts.Count

For VertCount As Integer = .Parts(ThisPart).Begins To .Parts(ThisPart).Ends


Console.WriteLine(.Vertices(VertCount).X_Cord.ToString() + ", " + .Vertices
(VertCount).Y_Cord.ToString())
Next
Next

Next

End With

End Sub

C# Example:

using crpShape = ArcViewShapeFileDLL;

public void ReadShape()


{

crpShape.ShapeFiles ShapeIn = new crpShape.ShapeFiles();

{
ShapeIn.ReadDataOnMove = FullRead;
// This is the default
// OpenShape automatically moves to the first record and loads it

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 3 of 43

ShapeIn.OpenShape("C:\\Temp\\Polygon.shp", shpOpen);

for (int ThisRecord = 1; ThisRecord <= ShapeIn.RecordCount(); ThisRecord++)


Console.WriteLine("Record Number: " + ThisRecord.ToString());

// Printout the name and values of the ShapeFile attribute data.


foreach (crpShape.ShapeField mF in ShapeIn.ShapeFields)
Console.WriteLine(mF.FieldName + " " + mF.Value.ToString());

// Print out the coordinates that make up this shape file


// Because we’re dealing with a polygon file, it is best to output by Parts
// You can also just output from 1 To .Vertice.Count

for (int ThisPart = 1; ThisPart <= ShapeIn.Parts.Count; ThisPart++) {

for (int VertCount = ShapeIn.Parts(ThisPart).Begins; VertCount <= ShapeIn.Parts


(ThisPart).Ends; VertCount++)
Console.WriteLine(ShapeIn.Vertices(VertCount).X_Cord.ToString() + ", " +
ShapeIn.Vertices(VertCount).Y_Cord.ToString());
}
}
}
}

Using the OCX - Examples

How To Create a ShapeFile

In the following example it is assumed that you have dragged an instance of the ShapeFile Control
from the IDE over to your Visual Basic project and renamed the OCX instance as ShapeOut.

In this case the ShapeFile Control is used to write a series of ShapeFiles. The polygon shapes
consist of a series of squares, one of which has a hole in it.

VB 6 VB .Net C#

Visual Basic 6 Example:

Sub WriteShapes()

Dim NewFld As ShapeField


Dim NewVert As Vertice

With ShapeOut

' *******************************
' * Point *
' *******************************
.OpenShape "C:\Shapes\Point_create.shp", shpCreate, shpPoint
Set NewFld = .ShapeFields.CreateField("TextField", shpText, 10)
Set NewFld = .ShapeFields.CreateField("NumField", shpNumeric, 5, 2)
Set NewFld = .ShapeFields.CreateField("DateField", shpDate)
.AppendFieldDefs

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 4 of 43

Set NewVert = .Vertices.AddVertice(1, 1)


.ShapeFields(1).Value = "ROSS" + Chr(189)
.ShapeFields(2).Value = 1.23
.ShapeFields(3).Value = CDate(Now)
.CreateShape
Set NewVert = .Vertices.AddVertice(1, 10)
.ShapeFields(1).Value = "ROSS" + Chr(190)
.ShapeFields(2).Value = 2.34
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape
Set NewVert = .Vertices.AddVertice(10, 10)
.ShapeFields(1).Value = "ROSS" + Chr(191)
.ShapeFields(2).Value = 3.45
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape

' *******************************
' * PointM *
' *******************************
.OpenShape "C:\Shapes\PointM_create.shp", shpCreate, shpPointM
Set NewFld = .ShapeFields.CreateField("TextField", shpText, 10)
Set NewFld = .ShapeFields.CreateField("NumField", shpNumeric, 5, 2)
Set NewFld = .ShapeFields.CreateField("DateField", shpDate)
.AppendFieldDefs

Set NewVert = .Vertices.AddVertice(1, 1, , 10)


.ShapeFields(1).Value = "ROSS" + Chr(189)
.ShapeFields(2).Value = 1.23
.ShapeFields(3).Value = CDate(Now)
.CreateShape
Set NewVert = .Vertices.AddVertice(1, 10, , 20)
.ShapeFields(1).Value = "ROSS" + Chr(190)
.ShapeFields(2).Value = 2.34
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape
Set NewVert = .Vertices.AddVertice(10, 10, , 30)
.ShapeFields(1).Value = "ROSS" + Chr(191)
.ShapeFields(2).Value = 3.45
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape

' *******************************
' * PointZ *
' *******************************
.OpenShape "C:\Shapes\PointZ_create.shp", shpCreate, shpPointZ
Set NewFld = .ShapeFields.CreateField("TextField", shpText, 10)
Set NewFld = .ShapeFields.CreateField("NumField", shpNumeric, 5, 2)
Set NewFld = .ShapeFields.CreateField("DateField", shpDate)
.AppendFieldDefs

Set NewVert = .Vertices.AddVertice(1, 1, , 10, 111)


.ShapeFields(1).Value = "ROSS" + Chr(189)
.ShapeFields(2).Value = 1.23
.ShapeFields(3).Value = CDate(Now)
.CreateShape

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 5 of 43

Set NewVert = .Vertices.AddVertice(1, 10, , , 222)


.ShapeFields(1).Value = "ROSS" + Chr(190)
.ShapeFields(2).Value = 2.34
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape
Set NewVert = .Vertices.AddVertice(10, 10, , 30, 333)
.ShapeFields(1).Value = "ROSS" + Chr(191)
.ShapeFields(2).Value = 3.45
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape

' *******************************
' * MultiPoint *
' *******************************
.OpenShape "C:\Shapes\MultiPoint_create.shp", shpCreate, shpMultiPoint
Set NewFld = .ShapeFields.CreateField("TextField", shpText, 10)
Set NewFld = .ShapeFields.CreateField("NumField", shpNumeric, 5, 2)
Set NewFld = .ShapeFields.CreateField("DateField", shpDate)
.AppendFieldDefs

Set NewVert = .Vertices.AddVertice(1, 1)


Set NewVert = .Vertices.AddVertice(1, 2)
Set NewVert = .Vertices.AddVertice(1, 3)
.ShapeFields(1).Value = "ROSS" + Chr(189)
.ShapeFields(2).Value = 1.23
.ShapeFields(3).Value = CDate(Now)
.CreateShape
Set NewVert = .Vertices.AddVertice(1, 11)
Set NewVert = .Vertices.AddVertice(1, 12)
Set NewVert = .Vertices.AddVertice(1, 13)
.ShapeFields(1).Value = "ROSS" + Chr(190)
.ShapeFields(2).Value = 2.34
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape
Set NewVert = .Vertices.AddVertice(10, 10)
Set NewVert = .Vertices.AddVertice(10, 11)
Set NewVert = .Vertices.AddVertice(10, 12)
.ShapeFields(1).Value = "ROSS" + Chr(191)
.ShapeFields(2).Value = 3.45
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape

' *******************************
' * MultiPointM *
' *******************************
.OpenShape "C:\Shapes\MultiPointM_create.shp", shpCreate, shpMultiPointM
Set NewFld = .ShapeFields.CreateField("TextField", shpText, 10)
Set NewFld = .ShapeFields.CreateField("NumField", shpNumeric, 5, 2)
Set NewFld = .ShapeFields.CreateField("DateField", shpDate)
.AppendFieldDefs

Set NewVert = .Vertices.AddVertice(1, 1, , 10)


Set NewVert = .Vertices.AddVertice(1, 2)
Set NewVert = .Vertices.AddVertice(1, 3, , 11)
.ShapeFields(1).Value = "ROSS" + Chr(189)
.ShapeFields(2).Value = 1.23

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 6 of 43

.ShapeFields(3).Value = CDate(Now)
.CreateShape
Set NewVert = .Vertices.AddVertice(1, 11, , 20)
Set NewVert = .Vertices.AddVertice(1, 12)
Set NewVert = .Vertices.AddVertice(1, 13, , 21)
.ShapeFields(1).Value = "ROSS" + Chr(190)
.ShapeFields(2).Value = 2.34
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape
Set NewVert = .Vertices.AddVertice(10, 10, , 30)
Set NewVert = .Vertices.AddVertice(10, 11)
Set NewVert = .Vertices.AddVertice(10, 12, , 31)
.ShapeFields(1).Value = "ROSS" + Chr(191)
.ShapeFields(2).Value = 3.45
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape

' *******************************
' * MultiPointZ *
' *******************************
.OpenShape "C:\Shapes\MultiPointZ_create.shp", shpCreate, shpMultiPointZ
Set NewFld = .ShapeFields.CreateField("TextField", shpText, 10)
Set NewFld = .ShapeFields.CreateField("NumField", shpNumeric, 5, 2)
Set NewFld = .ShapeFields.CreateField("DateField", shpDate)
.AppendFieldDefs

Set NewVert = .Vertices.AddVertice(1, 1, , 10, 110)


Set NewVert = .Vertices.AddVertice(1, 2, , , 111)
Set NewVert = .Vertices.AddVertice(1, 3, , 11, 112)
.ShapeFields(1).Value = "ROSS" + Chr(189)
.ShapeFields(2).Value = 1.23
.ShapeFields(3).Value = CDate(Now)
.CreateShape
Set NewVert = .Vertices.AddVertice(1, 11, , 20, 220)
Set NewVert = .Vertices.AddVertice(1, 12, , , 221)
Set NewVert = .Vertices.AddVertice(1, 13, , 21, 222)
.ShapeFields(1).Value = "ROSS" + Chr(190)
.ShapeFields(2).Value = 2.34
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape
Set NewVert = .Vertices.AddVertice(10, 10, , 30, 330)
Set NewVert = .Vertices.AddVertice(10, 11, , , 331)
Set NewVert = .Vertices.AddVertice(10, 12, , 31, 332)
.ShapeFields(1).Value = "ROSS" + Chr(191)
.ShapeFields(2).Value = 3.45
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape

' *******************************
' * PolyLine *
' *******************************
.OpenShape "C:\Shapes\PolyLine_create.shp", shpCreate, shpPolyLine
Set NewFld = .ShapeFields.CreateField("TextField", shpText, 10)
Set NewFld = .ShapeFields.CreateField("NumField", shpNumeric, 5, 2)
Set NewFld = .ShapeFields.CreateField("DateField", shpDate)
.AppendFieldDefs

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 7 of 43

Set NewVert = .Vertices.AddVertice(1, 1)


Set NewVert = .Vertices.AddVertice(1, 10)
Set NewVert = .Vertices.AddVertice(10, 10)
Set NewVert = .Vertices.AddVertice(10, 1)
Set NewVert = .Vertices.AddVertice(1, 1)
.ShapeFields(1).Value = "ROSS" + Chr(189)
.ShapeFields(2).Value = 1.23
.ShapeFields(3).Value = CDate(Now)
.CreateShape

Set NewVert = .Vertices.AddVertice(10, 1, 1)


Set NewVert = .Vertices.AddVertice(10, 10, 1)
Set NewVert = .Vertices.AddVertice(20, 10, 1)
Set NewVert = .Vertices.AddVertice(20, 1, 1)
Set NewVert = .Vertices.AddVertice(10, 1, 1)
Set NewVert = .Vertices.AddVertice(14, 4, 2)
Set NewVert = .Vertices.AddVertice(14, 6, 2)
Set NewVert = .Vertices.AddVertice(16, 6, 2)
Set NewVert = .Vertices.AddVertice(16, 4, 2)
Set NewVert = .Vertices.AddVertice(14, 4, 2)
.ShapeFields(1).Value = "ROSS" + Chr(190)
.ShapeFields(2).Value = 2.34
.ShapeFields(3).Value = CDate(DateAdd("d", 1, Now))
.CreateShape

Set NewVert = .Vertices.AddVertice(20, 1)


Set NewVert = .Vertices.AddVertice(20, 10)
Set NewVert = .Vertices.AddVertice(30, 10)
Set NewVert = .Vertices.AddVertice(30, 1)
Set NewVert = .Vertices.AddVertice(20, 1)
.ShapeFields(1).Value = "ROSS" + Chr(191)
.ShapeFields(2).Value = 3.45
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape

' *******************************
' * PolyLineM *
' *******************************
.OpenShape "C:\Shapes\PolyLineM_create.shp", shpCreate, shpPolyLineM
Set NewFld = .ShapeFields.CreateField("TextField", shpText, 10)
Set NewFld = .ShapeFields.CreateField("NumField", shpNumeric, 5, 2)
Set NewFld = .ShapeFields.CreateField("DateField", shpDate)
.AppendFieldDefs

Set NewVert = .Vertices.AddVertice(1, 1, , 10)


Set NewVert = .Vertices.AddVertice(1, 10)
Set NewVert = .Vertices.AddVertice(10, 10, , 11)
Set NewVert = .Vertices.AddVertice(10, 1, , 12)
Set NewVert = .Vertices.AddVertice(1, 1, , 13)
.ShapeFields(1).Value = "ROSS" + Chr(189)
.ShapeFields(2).Value = 1.23
.ShapeFields(3).Value = CDate(Now)
.CreateShape

Set NewVert = .Vertices.AddVertice(10, 1, 1, 20)

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 8 of 43

Set NewVert = .Vertices.AddVertice(10, 10, 1)


Set NewVert = .Vertices.AddVertice(20, 10, 1, 21)
Set NewVert = .Vertices.AddVertice(20, 1, 1, 22)
Set NewVert = .Vertices.AddVertice(10, 1, 1, 23)
Set NewVert = .Vertices.AddVertice(14, 4, 2, 24)
Set NewVert = .Vertices.AddVertice(14, 6, 2, 25)
Set NewVert = .Vertices.AddVertice(16, 6, 2, 26)
Set NewVert = .Vertices.AddVertice(16, 4, 2, 27)
Set NewVert = .Vertices.AddVertice(14, 4, 2, 28)
.ShapeFields(1).Value = "ROSS" + Chr(190)
.ShapeFields(2).Value = 2.34
.ShapeFields(3).Value = CDate(DateAdd("d", 1, Now))
.CreateShape

Set NewVert = .Vertices.AddVertice(20, 1, , 30)


Set NewVert = .Vertices.AddVertice(20, 10)
Set NewVert = .Vertices.AddVertice(30, 10, , 31)
Set NewVert = .Vertices.AddVertice(30, 1, , 32)
Set NewVert = .Vertices.AddVertice(20, 1, , 33)
.ShapeFields(1).Value = "ROSS" + Chr(191)
.ShapeFields(2).Value = 3.45
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape

' *******************************
' * PolyLineZ *
' *******************************
.OpenShape "C:\Shapes\PolyLineZ_create.shp", shpCreate, shpPolyLineZ
Set NewFld = .ShapeFields.CreateField("TextField", shpText, 10)
Set NewFld = .ShapeFields.CreateField("NumField", shpNumeric, 5, 2)
Set NewFld = .ShapeFields.CreateField("DateField", shpDate)
.AppendFieldDefs

Set NewVert = .Vertices.AddVertice(1, 1, , 11, 110)


Set NewVert = .Vertices.AddVertice(1, 10, , , 111)
Set NewVert = .Vertices.AddVertice(10, 10, , 12, 112)
Set NewVert = .Vertices.AddVertice(10, 1, , 13, 113)
Set NewVert = .Vertices.AddVertice(1, 1, , 14, 114)
.ShapeFields(1).Value = "ROSS" + Chr(189)
.ShapeFields(2).Value = 1.23
.ShapeFields(3).Value = CDate(Now)
.CreateShape

Set NewVert = .Vertices.AddVertice(10, 1, 1, 20, 220)


Set NewVert = .Vertices.AddVertice(10, 10, 1, , 221)
Set NewVert = .Vertices.AddVertice(20, 10, 1, 21, 222)
Set NewVert = .Vertices.AddVertice(20, 1, 1, 22, 223)
Set NewVert = .Vertices.AddVertice(10, 1, 1, 23, 224)
Set NewVert = .Vertices.AddVertice(14, 4, 2, 24, 225)
Set NewVert = .Vertices.AddVertice(14, 6, 2, 25, 226)
Set NewVert = .Vertices.AddVertice(16, 6, 2, 26, 227)
Set NewVert = .Vertices.AddVertice(16, 4, 2, 27, 228)
Set NewVert = .Vertices.AddVertice(14, 4, 2, 28, 229)
.ShapeFields(1).Value = "ROSS" + Chr(190)
.ShapeFields(2).Value = 2.34
.ShapeFields(3).Value = CDate(DateAdd("d", 1, Now))

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 9 of 43

.CreateShape

Set NewVert = .Vertices.AddVertice(20, 1, , 30, 330)


Set NewVert = .Vertices.AddVertice(20, 10, , , 331)
Set NewVert = .Vertices.AddVertice(30, 10, , 31, 332)
Set NewVert = .Vertices.AddVertice(30, 1, , 32, 333)
Set NewVert = .Vertices.AddVertice(20, 1, , 33, 334)
.ShapeFields(1).Value = "ROSS" + Chr(191)
.ShapeFields(2).Value = 3.45
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape

' *******************************
' * Polygon *
' *******************************
.OpenShape "C:\Shapes\Polygon_create.shp", shpCreate, shpPolygon
Set NewFld = .ShapeFields.CreateField("TextField", shpText, 10)
Set NewFld = .ShapeFields.CreateField("NumField", shpNumeric, 5, 2)
Set NewFld = .ShapeFields.CreateField("DateField", shpDate)
.AppendFieldDefs

Set NewVert = .Vertices.AddVertice(1, 1)


Set NewVert = .Vertices.AddVertice(1, 10)
Set NewVert = .Vertices.AddVertice(10, 10)
Set NewVert = .Vertices.AddVertice(10, 1)
Set NewVert = .Vertices.AddVertice(1, 1)
.ShapeFields(1).Value = "ROSS" + Chr(189)
.ShapeFields(2).Value = 1.23
.ShapeFields(3).Value = CDate(Now)
.CreateShape

Set NewVert = .Vertices.AddVertice(10, 1, 1)


Set NewVert = .Vertices.AddVertice(10, 10, 1)
Set NewVert = .Vertices.AddVertice(20, 10, 1)
Set NewVert = .Vertices.AddVertice(20, 1, 1)
Set NewVert = .Vertices.AddVertice(10, 1, 1)
Set NewVert = .Vertices.AddVertice(14, 4, 2)
Set NewVert = .Vertices.AddVertice(14, 6, 2)
Set NewVert = .Vertices.AddVertice(16, 6, 2)
Set NewVert = .Vertices.AddVertice(16, 4, 2)
Set NewVert = .Vertices.AddVertice(14, 4, 2)
.ShapeFields(1).Value = "ROSS" + Chr(190)
.ShapeFields(2).Value = 2.34
.ShapeFields(3).Value = CDate(DateAdd("d", 1, Now))
.CreateShape

Set NewVert = .Vertices.AddVertice(20, 1)


Set NewVert = .Vertices.AddVertice(20, 10)
Set NewVert = .Vertices.AddVertice(30, 10)
Set NewVert = .Vertices.AddVertice(30, 1)
Set NewVert = .Vertices.AddVertice(20, 1)
.ShapeFields(1).Value = "ROSS" + Chr(191)
.ShapeFields(2).Value = 3.45
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 10 of 43

' *******************************
' * PolygonM *
' *******************************
.OpenShape "C:\Shapes\PolygonM_create.shp", shpCreate, shpPolygonM
Set NewFld = .ShapeFields.CreateField("TextField", shpText, 10)
Set NewFld = .ShapeFields.CreateField("NumField", shpNumeric, 5, 2)
Set NewFld = .ShapeFields.CreateField("DateField", shpDate)
.AppendFieldDefs

Set NewVert = .Vertices.AddVertice(1, 1, , 10)


Set NewVert = .Vertices.AddVertice(1, 10)
Set NewVert = .Vertices.AddVertice(10, 10, , 11)
Set NewVert = .Vertices.AddVertice(10, 1, , 12)
Set NewVert = .Vertices.AddVertice(1, 1, , 13)
.ShapeFields(1).Value = "ROSS" + Chr(189)
.ShapeFields(2).Value = 1.23
.ShapeFields(3).Value = CDate(Now)
.CreateShape

Set NewVert = .Vertices.AddVertice(10, 1, 1, 20)


Set NewVert = .Vertices.AddVertice(10, 10, 1)
Set NewVert = .Vertices.AddVertice(20, 10, 1, 21)
Set NewVert = .Vertices.AddVertice(20, 1, 1, 22)
Set NewVert = .Vertices.AddVertice(10, 1, 1, 23)
Set NewVert = .Vertices.AddVertice(14, 4, 2, 24)
Set NewVert = .Vertices.AddVertice(14, 6, 2, 25)
Set NewVert = .Vertices.AddVertice(16, 6, 2, 26)
Set NewVert = .Vertices.AddVertice(16, 4, 2, 27)
Set NewVert = .Vertices.AddVertice(14, 4, 2, 28)
.ShapeFields(1).Value = "ROSS" + Chr(190)
.ShapeFields(2).Value = 2.34
.ShapeFields(3).Value = CDate(DateAdd("d", 1, Now))
.CreateShape

Set NewVert = .Vertices.AddVertice(20, 1, , 30)


Set NewVert = .Vertices.AddVertice(20, 10)
Set NewVert = .Vertices.AddVertice(30, 10, , 31)
Set NewVert = .Vertices.AddVertice(30, 1, , 32)
Set NewVert = .Vertices.AddVertice(20, 1, , 33)
.ShapeFields(1).Value = "ROSS" + Chr(191)
.ShapeFields(2).Value = 3.45
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape

' *******************************
' * PolygonZ *
' *******************************
.OpenShape "C:\Shapes\PolygonZ_create.shp", shpCreate, shpPolygonZ
Set NewFld = .ShapeFields.CreateField("TextField", shpText, 10)
Set NewFld = .ShapeFields.CreateField("NumField", shpNumeric, 5, 2)
Set NewFld = .ShapeFields.CreateField("DateField", shpDate)
.AppendFieldDefs

Set NewVert = .Vertices.AddVertice(1, 1, , 11, 110)


Set NewVert = .Vertices.AddVertice(1, 10, , , 111)
Set NewVert = .Vertices.AddVertice(10, 10, , 12, 112)

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 11 of 43

Set NewVert = .Vertices.AddVertice(10, 1, , 13, 113)


Set NewVert = .Vertices.AddVertice(1, 1, , 14, 114)
.ShapeFields(1).Value = "ROSS" + Chr(189)
.ShapeFields(2).Value = 1.23
.ShapeFields(3).Value = CDate(Now)
.CreateShape

Set NewVert = .Vertices.AddVertice(10, 1, 1, 20, 220)


Set NewVert = .Vertices.AddVertice(10, 10, 1, , 221)
Set NewVert = .Vertices.AddVertice(20, 10, 1, 21, 222)
Set NewVert = .Vertices.AddVertice(20, 1, 1, 22, 223)
Set NewVert = .Vertices.AddVertice(10, 1, 1, 23, 224)
Set NewVert = .Vertices.AddVertice(14, 4, 2, 24, 225)
Set NewVert = .Vertices.AddVertice(14, 6, 2, 25, 226)
Set NewVert = .Vertices.AddVertice(16, 6, 2, 26, 227)
Set NewVert = .Vertices.AddVertice(16, 4, 2, 27, 228)
Set NewVert = .Vertices.AddVertice(14, 4, 2, 28, 229)
.ShapeFields(1).Value = "ROSS" + Chr(190)
.ShapeFields(2).Value = 2.34
.ShapeFields(3).Value = CDate(DateAdd("d", 1, Now))
.CreateShape

Set NewVert = .Vertices.AddVertice(20, 1, , 30, 330)


Set NewVert = .Vertices.AddVertice(20, 10, , , 331)
Set NewVert = .Vertices.AddVertice(30, 10, , 31, 332)
Set NewVert = .Vertices.AddVertice(30, 1, , 32, 333)
Set NewVert = .Vertices.AddVertice(20, 1, , 33, 334)
.ShapeFields(1).Value = "ROSS" + Chr(191)
.ShapeFields(2).Value = 3.45
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape

' *******************************
' * MultiPatch *
' *******************************
.OpenShape "C:\Shapes\MultiPatch_create.shp", shpCreate, shpMultiPatch
Set NewFld = .ShapeFields.CreateField("TextField", shpText, 10)
Set NewFld = .ShapeFields.CreateField("NumField", shpNumeric, 5, 2)
Set NewFld = .ShapeFields.CreateField("DateField", shpDate)
.AppendFieldDefs

.ShapeFields(1).Value = "ROSS" + Chr(189)


.ShapeFields(2).Value = 1.23
.ShapeFields(3).Value = CDate(Now)

Set NewVert = .Vertices.AddVertice(10, 1, 1, 20, 220, shpOuterRing)


Set NewVert = .Vertices.AddVertice(10, 10, 1, , 221, shpOuterRing)
Set NewVert = .Vertices.AddVertice(20, 10, 1, 21, 222, shpOuterRing)
Set NewVert = .Vertices.AddVertice(20, 1, 1, 22, 223, shpOuterRing)
Set NewVert = .Vertices.AddVertice(10, 1, 1, 23, 224, shpOuterRing)
Set NewVert = .Vertices.AddVertice(14, 4, 2, 24, 225, shpInnerRing)
Set NewVert = .Vertices.AddVertice(14, 6, 2, 25, 226, shpInnerRing)
Set NewVert = .Vertices.AddVertice(16, 6, 2, 26, 227, shpInnerRing)
Set NewVert = .Vertices.AddVertice(16, 4, 2, 27, 228, shpInnerRing)
Set NewVert = .Vertices.AddVertice(14, 4, 2, 28, 229, shpInnerRing)
.CreateShape

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 12 of 43

End With

End Sub

VB .NET Example:

Imports crpShape = ArcViewShapeFileDLL


Imports ArcShapeFileDLL.ShapeFiles.eNew
Imports ArcShapeFileDLL.ShapeFiles.eFieldType
Imports ArcShapeFileDLL.ShapeFiles.eShapeType
Imports ArcShapeFileDLL.ShapeFiles.eReadMode
Imports ArcShapeFileDLL.ShapeFiles.ePartType

Module Examples

Sub CreateShapes()
Dim ShapeOut As New crpShape.ShapeFiles
Dim NewFld As crpShape.ShapeField
Dim NewVert As crpShape.Vertice

With ShapeOut

' *******************************
' * Point *
' *******************************
.OpenShape("C:\Shapes\Point_Net_create.shp", shpCreate, shpPoint)
NewFld = .ShapeFields.CreateField("TextField", shpText, 10)
NewFld = .ShapeFields.CreateField("NumField", shpNumeric, 5, 2)
NewFld = .ShapeFields.CreateField("DateField", shpDate)
.AppendFieldDefs()

NewVert = .Vertices.AddVertice(1, 1)
.ShapeFields(1).Value = "Ross" + Chr(189)
.ShapeFields(2).Value = 1.23
.ShapeFields(3).Value = CDate(Now)
.CreateShape()
NewVert = .Vertices.AddVertice(1, 10)
.ShapeFields(1).Value = "Ross" + Chr(190)
.ShapeFields(2).Value = 2.34
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape()
NewVert = .Vertices.AddVertice(10, 10)
.ShapeFields(1).Value = "Ross" + Chr(191)
.ShapeFields(2).Value = 3.45
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape()

' *******************************
' * PointM *
' *******************************
.OpenShape("C:\Shapes\PointM_Net_create.shp", shpCreate, shpPointM)
NewFld = .ShapeFields.CreateField("TextField", shpText, 10)
NewFld = .ShapeFields.CreateField("NumField", shpNumeric, 5, 2)
NewFld = .ShapeFields.CreateField("DateField", shpDate)

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 13 of 43

.AppendFieldDefs()

NewVert = .Vertices.AddVertice(1, 1, , 10)


.ShapeFields(1).Value = "Ross" + Chr(189)
.ShapeFields(2).Value = 1.23
.ShapeFields(3).Value = CDate(Now)
.CreateShape()
NewVert = .Vertices.AddVertice(1, 10, , 20)
.ShapeFields(1).Value = "Ross" + Chr(190)
.ShapeFields(2).Value = 2.34
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape()
NewVert = .Vertices.AddVertice(10, 10, , 30)
.ShapeFields(1).Value = "Ross" + Chr(191)
.ShapeFields(2).Value = 3.45
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape()

' *******************************
' * PointZ *
' *******************************
.OpenShape("C:\Shapes\PointZ_Net_create.shp", shpCreate, shpPointZ)
NewFld = .ShapeFields.CreateField("TextField", shpText, 10)
NewFld = .ShapeFields.CreateField("NumField", shpNumeric, 5, 2)
NewFld = .ShapeFields.CreateField("DateField", shpDate)
.AppendFieldDefs()

NewVert = .Vertices.AddVertice(1, 1, , 10, 111)


.ShapeFields(1).Value = "Ross" + Chr(189)
.ShapeFields(2).Value = 1.23
.ShapeFields(3).Value = CDate(Now)
.CreateShape()
NewVert = .Vertices.AddVertice(1, 10, , , 222)
.ShapeFields(1).Value = "Ross" + Chr(190)
.ShapeFields(2).Value = 2.34
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape()
NewVert = .Vertices.AddVertice(10, 10, , 30, 333)
.ShapeFields(1).Value = "Ross" + Chr(191)
.ShapeFields(2).Value = 3.45
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape()

' *******************************
' * MultiPoint *
' *******************************
.OpenShape("C:\Shapes\MultiPoint_Net_create.shp", shpCreate, shpMultiPoint)
NewFld = .ShapeFields.CreateField("TextField", shpText, 10)
NewFld = .ShapeFields.CreateField("NumField", shpNumeric, 5, 2)
NewFld = .ShapeFields.CreateField("DateField", shpDate)
.AppendFieldDefs()

NewVert = .Vertices.AddVertice(1, 1)
NewVert = .Vertices.AddVertice(1, 2)
NewVert = .Vertices.AddVertice(1, 3)
.ShapeFields(1).Value = "Ross" + Chr(189)

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 14 of 43

.ShapeFields(2).Value = 1.23
.ShapeFields(3).Value = CDate(Now)
.CreateShape()
NewVert = .Vertices.AddVertice(1, 11)
NewVert = .Vertices.AddVertice(1, 12)
NewVert = .Vertices.AddVertice(1, 13)
.ShapeFields(1).Value = "Ross" + Chr(190)
.ShapeFields(2).Value = 2.34
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape()
NewVert = .Vertices.AddVertice(10, 10)
NewVert = .Vertices.AddVertice(10, 11)
NewVert = .Vertices.AddVertice(10, 12)
.ShapeFields(1).Value = "Ross" + Chr(191)
.ShapeFields(2).Value = 3.45
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape()

' *******************************
' * MultiPointM *
' *******************************
.OpenShape("C:\Shapes\MultiPointM_Net_create.shp", shpCreate, shpMultiPointM)
NewFld = .ShapeFields.CreateField("TextField", shpText, 10)
NewFld = .ShapeFields.CreateField("NumField", shpNumeric, 5, 2)
NewFld = .ShapeFields.CreateField("DateField", shpDate)
.AppendFieldDefs()

NewVert = .Vertices.AddVertice(1, 1, , 10)


NewVert = .Vertices.AddVertice(1, 2)
NewVert = .Vertices.AddVertice(1, 3, , 11)
.ShapeFields(1).Value = "Ross" + Chr(189)
.ShapeFields(2).Value = 1.23
.ShapeFields(3).Value = CDate(Now)
.CreateShape()
NewVert = .Vertices.AddVertice(1, 11, , 20)
NewVert = .Vertices.AddVertice(1, 12)
NewVert = .Vertices.AddVertice(1, 13, , 21)
.ShapeFields(1).Value = "Ross" + Chr(190)
.ShapeFields(2).Value = 2.34
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape()
NewVert = .Vertices.AddVertice(10, 10, , 30)
NewVert = .Vertices.AddVertice(10, 11)
NewVert = .Vertices.AddVertice(10, 12, , 31)
.ShapeFields(1).Value = "Ross" + Chr(191)
.ShapeFields(2).Value = 3.45
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape()

' *******************************
' * MultiPointZ *
' *******************************
.OpenShape("C:\Shapes\MultiPointZ_Net_create.shp", shpCreate, shpMultiPointZ)
NewFld = .ShapeFields.CreateField("TextField", shpText, 10)
NewFld = .ShapeFields.CreateField("NumField", shpNumeric, 5, 2)
NewFld = .ShapeFields.CreateField("DateField", shpDate)

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 15 of 43

.AppendFieldDefs()

NewVert = .Vertices.AddVertice(1, 1, , 10, 110)


NewVert = .Vertices.AddVertice(1, 2, , , 111)
NewVert = .Vertices.AddVertice(1, 3, , 11, 112)
.ShapeFields(1).Value = "Ross" + Chr(189)
.ShapeFields(2).Value = 1.23
.ShapeFields(3).Value = CDate(Now)
.CreateShape()
NewVert = .Vertices.AddVertice(1, 11, , 20, 220)
NewVert = .Vertices.AddVertice(1, 12, , , 221)
NewVert = .Vertices.AddVertice(1, 13, , 21, 222)
.ShapeFields(1).Value = "Ross" + Chr(190)
.ShapeFields(2).Value = 2.34
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape()
NewVert = .Vertices.AddVertice(10, 10, , 30, 330)
NewVert = .Vertices.AddVertice(10, 11, , , 331)
NewVert = .Vertices.AddVertice(10, 12, , 31, 332)
.ShapeFields(1).Value = "Ross" + Chr(191)
.ShapeFields(2).Value = 3.45
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape()

' *******************************
' * PolyLine *
' *******************************
.OpenShape("C:\Shapes\PolyLine_Net_create.shp", shpCreate, shpPolyLine)
NewFld = .ShapeFields.CreateField("TextField", shpText, 10)
NewFld = .ShapeFields.CreateField("NumField", shpNumeric, 5, 2)
NewFld = .ShapeFields.CreateField("DateField", shpDate)
.AppendFieldDefs()

NewVert = .Vertices.AddVertice(1, 1)
NewVert = .Vertices.AddVertice(1, 10)
NewVert = .Vertices.AddVertice(10, 10)
NewVert = .Vertices.AddVertice(10, 1)
NewVert = .Vertices.AddVertice(1, 1)
.ShapeFields(1).Value = "Ross" + Chr(189)
.ShapeFields(2).Value = 1.23
.ShapeFields(3).Value = CDate(Now)
.CreateShape()

NewVert = .Vertices.AddVertice(10, 1, 1)
NewVert = .Vertices.AddVertice(10, 10, 1)
NewVert = .Vertices.AddVertice(20, 10, 1)
NewVert = .Vertices.AddVertice(20, 1, 1)
NewVert = .Vertices.AddVertice(10, 1, 1)
NewVert = .Vertices.AddVertice(14, 4, 2)
NewVert = .Vertices.AddVertice(14, 6, 2)
NewVert = .Vertices.AddVertice(16, 6, 2)
NewVert = .Vertices.AddVertice(16, 4, 2)
NewVert = .Vertices.AddVertice(14, 4, 2)
.ShapeFields(1).Value = "Ross" + Chr(190)
.ShapeFields(2).Value = 2.34
.ShapeFields(3).Value = CDate(DateAdd("d", 1, Now))

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 16 of 43

.CreateShape()

NewVert = .Vertices.AddVertice(20, 1)
NewVert = .Vertices.AddVertice(20, 10)
NewVert = .Vertices.AddVertice(30, 10)
NewVert = .Vertices.AddVertice(30, 1)
NewVert = .Vertices.AddVertice(20, 1)
.ShapeFields(1).Value = "Ross" + Chr(191)
.ShapeFields(2).Value = 3.45
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape()

' *******************************
' * PolyLineM *
' *******************************
.OpenShape("C:\Shapes\PolyLineM_Net_create.shp", shpCreate, shpPolyLineM)
NewFld = .ShapeFields.CreateField("TextField", shpText, 10)
NewFld = .ShapeFields.CreateField("NumField", shpNumeric, 5, 2)
NewFld = .ShapeFields.CreateField("DateField", shpDate)
.AppendFieldDefs()

NewVert = .Vertices.AddVertice(1, 1, , 10)


NewVert = .Vertices.AddVertice(1, 10)
NewVert = .Vertices.AddVertice(10, 10, , 11)
NewVert = .Vertices.AddVertice(10, 1, , 12)
NewVert = .Vertices.AddVertice(1, 1, , 13)
.ShapeFields(1).Value = "Ross" + Chr(189)
.ShapeFields(2).Value = 1.23
.ShapeFields(3).Value = CDate(Now)
.CreateShape()

NewVert = .Vertices.AddVertice(10, 1, 1, 20)


NewVert = .Vertices.AddVertice(10, 10, 1)
NewVert = .Vertices.AddVertice(20, 10, 1, 21)
NewVert = .Vertices.AddVertice(20, 1, 1, 22)
NewVert = .Vertices.AddVertice(10, 1, 1, 23)
NewVert = .Vertices.AddVertice(14, 4, 2, 24)
NewVert = .Vertices.AddVertice(14, 6, 2, 25)
NewVert = .Vertices.AddVertice(16, 6, 2, 26)
NewVert = .Vertices.AddVertice(16, 4, 2, 27)
NewVert = .Vertices.AddVertice(14, 4, 2, 28)
.ShapeFields(1).Value = "Ross" + Chr(190)
.ShapeFields(2).Value = 2.34
.ShapeFields(3).Value = CDate(DateAdd("d", 1, Now))
.CreateShape()

NewVert = .Vertices.AddVertice(20, 1, , 30)


NewVert = .Vertices.AddVertice(20, 10)
NewVert = .Vertices.AddVertice(30, 10, , 31)
NewVert = .Vertices.AddVertice(30, 1, , 32)
NewVert = .Vertices.AddVertice(20, 1, , 33)
.ShapeFields(1).Value = "Ross" + Chr(191)
.ShapeFields(2).Value = 3.45
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape()

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 17 of 43

' *******************************
' * PolyLineZ *
' *******************************
.OpenShape("C:\Shapes\PolyLineZ_Net_create.shp", shpCreate, shpPolyLineZ)
NewFld = .ShapeFields.CreateField("TextField", shpText, 10)
NewFld = .ShapeFields.CreateField("NumField", shpNumeric, 5, 2)
NewFld = .ShapeFields.CreateField("DateField", shpDate)
.AppendFieldDefs()

NewVert = .Vertices.AddVertice(1, 1, , 11, 110)


NewVert = .Vertices.AddVertice(1, 10, , , 111)
NewVert = .Vertices.AddVertice(10, 10, , 12, 112)
NewVert = .Vertices.AddVertice(10, 1, , 13, 113)
NewVert = .Vertices.AddVertice(1, 1, , 14, 114)
.ShapeFields(1).Value = "Ross" + Chr(189)
.ShapeFields(2).Value = 1.23
.ShapeFields(3).Value = CDate(Now)
.CreateShape()

NewVert = .Vertices.AddVertice(10, 1, 1, 20, 220)


NewVert = .Vertices.AddVertice(10, 10, 1, , 221)
NewVert = .Vertices.AddVertice(20, 10, 1, 21, 222)
NewVert = .Vertices.AddVertice(20, 1, 1, 22, 223)
NewVert = .Vertices.AddVertice(10, 1, 1, 23, 224)
NewVert = .Vertices.AddVertice(14, 4, 2, 24, 225)
NewVert = .Vertices.AddVertice(14, 6, 2, 25, 226)
NewVert = .Vertices.AddVertice(16, 6, 2, 26, 227)
NewVert = .Vertices.AddVertice(16, 4, 2, 27, 228)
NewVert = .Vertices.AddVertice(14, 4, 2, 28, 229)
.ShapeFields(1).Value = "Ross" + Chr(190)
.ShapeFields(2).Value = 2.34
.ShapeFields(3).Value = CDate(DateAdd("d", 1, Now))
.CreateShape()

NewVert = .Vertices.AddVertice(20, 1, , 30, 330)


NewVert = .Vertices.AddVertice(20, 10, , , 331)
NewVert = .Vertices.AddVertice(30, 10, , 31, 332)
NewVert = .Vertices.AddVertice(30, 1, , 32, 333)
NewVert = .Vertices.AddVertice(20, 1, , 33, 334)
.ShapeFields(1).Value = "Ross" + Chr(191)
.ShapeFields(2).Value = 3.45
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape()

' *******************************
' * Polygon *
' *******************************
.OpenShape("C:\Shapes\Polygon_Net_create.shp", shpCreate, shpPolygon)
NewFld = .ShapeFields.CreateField("TextField", shpText, 10)
NewFld = .ShapeFields.CreateField("NumField", shpNumeric, 5, 2)
NewFld = .ShapeFields.CreateField("DateField", shpDate)
.AppendFieldDefs()

NewVert = .Vertices.AddVertice(1, 1)
NewVert = .Vertices.AddVertice(1, 10)
NewVert = .Vertices.AddVertice(10, 10)

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 18 of 43

NewVert = .Vertices.AddVertice(10, 1)
NewVert = .Vertices.AddVertice(1, 1)
.ShapeFields(1).Value = "Ross" + Chr(189)
.ShapeFields(2).Value = 1.23
.ShapeFields(3).Value = CDate(Now)
.CreateShape()

NewVert = .Vertices.AddVertice(10, 1, 1)
NewVert = .Vertices.AddVertice(10, 10, 1)
NewVert = .Vertices.AddVertice(20, 10, 1)
NewVert = .Vertices.AddVertice(20, 1, 1)
NewVert = .Vertices.AddVertice(10, 1, 1)
NewVert = .Vertices.AddVertice(14, 4, 2)
NewVert = .Vertices.AddVertice(14, 6, 2)
NewVert = .Vertices.AddVertice(16, 6, 2)
NewVert = .Vertices.AddVertice(16, 4, 2)
NewVert = .Vertices.AddVertice(14, 4, 2)
.ShapeFields(1).Value = "Ross" + Chr(190)
.ShapeFields(2).Value = 2.34
.ShapeFields(3).Value = CDate(DateAdd("d", 1, Now))
.CreateShape()

NewVert = .Vertices.AddVertice(20, 1)
NewVert = .Vertices.AddVertice(20, 10)
NewVert = .Vertices.AddVertice(30, 10)
NewVert = .Vertices.AddVertice(30, 1)
NewVert = .Vertices.AddVertice(20, 1)
.ShapeFields(1).Value = "Ross" + Chr(191)
.ShapeFields(2).Value = 3.45
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape()

' *******************************
' * PolygonM *
' *******************************
.OpenShape("C:\Shapes\PolygonM_Net_create.shp", shpCreate, shpPolygonM)
NewFld = .ShapeFields.CreateField("TextField", shpText, 10)
NewFld = .ShapeFields.CreateField("NumField", shpNumeric, 5, 2)
NewFld = .ShapeFields.CreateField("DateField", shpDate)
.AppendFieldDefs()

NewVert = .Vertices.AddVertice(1, 1, , 10)


NewVert = .Vertices.AddVertice(1, 10)
NewVert = .Vertices.AddVertice(10, 10, , 11)
NewVert = .Vertices.AddVertice(10, 1, , 12)
NewVert = .Vertices.AddVertice(1, 1, , 13)
.ShapeFields(1).Value = "Ross" + Chr(189)
.ShapeFields(2).Value = 1.23
.ShapeFields(3).Value = CDate(Now)
.CreateShape()

NewVert = .Vertices.AddVertice(10, 1, 1, 20)


NewVert = .Vertices.AddVertice(10, 10, 1)
NewVert = .Vertices.AddVertice(20, 10, 1, 21)
NewVert = .Vertices.AddVertice(20, 1, 1, 22)
NewVert = .Vertices.AddVertice(10, 1, 1, 23)

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 19 of 43

NewVert = .Vertices.AddVertice(14, 4, 2, 24)


NewVert = .Vertices.AddVertice(14, 6, 2, 25)
NewVert = .Vertices.AddVertice(16, 6, 2, 26)
NewVert = .Vertices.AddVertice(16, 4, 2, 27)
NewVert = .Vertices.AddVertice(14, 4, 2, 28)
.ShapeFields(1).Value = "Ross" + Chr(190)
.ShapeFields(2).Value = 2.34
.ShapeFields(3).Value = CDate(DateAdd("d", 1, Now))
.CreateShape()

NewVert = .Vertices.AddVertice(20, 1, , 30)


NewVert = .Vertices.AddVertice(20, 10)
NewVert = .Vertices.AddVertice(30, 10, , 31)
NewVert = .Vertices.AddVertice(30, 1, , 32)
NewVert = .Vertices.AddVertice(20, 1, , 33)
.ShapeFields(1).Value = "Ross" + Chr(191)
.ShapeFields(2).Value = 3.45
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape()

' *******************************
' * PolygonZ *
' *******************************
.OpenShape("C:\Shapes\PolygonZ_Net_create.shp", shpCreate, shpPolygonZ)
NewFld = .ShapeFields.CreateField("TextField", shpText, 10)
NewFld = .ShapeFields.CreateField("NumField", shpNumeric, 5, 2)
NewFld = .ShapeFields.CreateField("DateField", shpDate)
.AppendFieldDefs()

NewVert = .Vertices.AddVertice(1, 1, , 11, 110)


NewVert = .Vertices.AddVertice(1, 10, , , 111)
NewVert = .Vertices.AddVertice(10, 10, , 12, 112)
NewVert = .Vertices.AddVertice(10, 1, , 13, 113)
NewVert = .Vertices.AddVertice(1, 1, , 14, 114)
.ShapeFields(1).Value = "Ross" + Chr(189)
.ShapeFields(2).Value = 1.23
.ShapeFields(3).Value = CDate(Now)
.CreateShape()

NewVert = .Vertices.AddVertice(10, 1, 1, 20, 220)


NewVert = .Vertices.AddVertice(10, 10, 1, , 221)
NewVert = .Vertices.AddVertice(20, 10, 1, 21, 222)
NewVert = .Vertices.AddVertice(20, 1, 1, 22, 223)
NewVert = .Vertices.AddVertice(10, 1, 1, 23, 224)
NewVert = .Vertices.AddVertice(14, 4, 2, 24, 225)
NewVert = .Vertices.AddVertice(14, 6, 2, 25, 226)
NewVert = .Vertices.AddVertice(16, 6, 2, 26, 227)
NewVert = .Vertices.AddVertice(16, 4, 2, 27, 228)
NewVert = .Vertices.AddVertice(14, 4, 2, 28, 229)
.ShapeFields(1).Value = "Ross" + Chr(190)
.ShapeFields(2).Value = 2.34
.ShapeFields(3).Value = CDate(DateAdd("d", 1, Now))
.CreateShape()

NewVert = .Vertices.AddVertice(20, 1, , 30, 330)


NewVert = .Vertices.AddVertice(20, 10, , , 331)

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 20 of 43

NewVert = .Vertices.AddVertice(30, 10, , 31, 332)


NewVert = .Vertices.AddVertice(30, 1, , 32, 333)
NewVert = .Vertices.AddVertice(20, 1, , 33, 334)
.ShapeFields(1).Value = "Ross" + Chr(191)
.ShapeFields(2).Value = 3.45
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape()

' *******************************
' * MultiPatch *
' *******************************
.OpenShape("C:\Shapes\MultiPatch_Net_create.shp", shpCreate, shpMultiPatch)
NewFld = .ShapeFields.CreateField("TextField", shpText, 10)
NewFld = .ShapeFields.CreateField("NumField", shpNumeric, 5, 2)
NewFld = .ShapeFields.CreateField("DateField", shpDate)
.AppendFieldDefs()

.ShapeFields(1).Value = "Ross" + Chr(189)


.ShapeFields(2).Value = 1.23
.ShapeFields(3).Value = CDate(Now)

NewVert = .Vertices.AddVertice(10, 1, 1, 20, 220, shpOuterRing)


NewVert = .Vertices.AddVertice(10, 10, 1, , 221, shpOuterRing)
NewVert = .Vertices.AddVertice(20, 10, 1, 21, 222, shpOuterRing)
NewVert = .Vertices.AddVertice(20, 1, 1, 22, 223, shpOuterRing)
NewVert = .Vertices.AddVertice(10, 1, 1, 23, 224, shpOuterRing)
NewVert = .Vertices.AddVertice(14, 4, 2, 24, 225, shpInnerRing)
NewVert = .Vertices.AddVertice(14, 6, 2, 25, 226, shpInnerRing)
NewVert = .Vertices.AddVertice(16, 6, 2, 26, 227, shpInnerRing)
NewVert = .Vertices.AddVertice(16, 4, 2, 27, 228, shpInnerRing)
NewVert = .Vertices.AddVertice(14, 4, 2, 28, 229, shpInnerRing)
.CreateShape()

End With

End Sub

End Module

C# Example:

using crpShape = ArcViewShapeFileDLL;


using ArcShapeFileDLL.ShapeFiles.eNew;
using ArcShapeFileDLL.ShapeFiles.eFieldType;
using ArcShapeFileDLL.ShapeFiles.eShapeType;
using ArcShapeFileDLL.ShapeFiles.eReadMode;
using ArcShapeFileDLL.ShapeFiles.ePartType;

public void CreateShapes()


{
crpShape.ShapeFiles ShapeOut = new crpShape.ShapeFiles();
crpShape.ShapeField NewFld;
crpShape.Vertice NewVert;

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 21 of 43

// *******************************
// * Point *
// *******************************
ShapeOut.OpenShape("C:\\Shapes\\Point_Net_create.shp", shpCreate, shpPoint);
NewFld = ShapeOut.ShapeFields.CreateField("TextField", shpText, 10);
NewFld = ShapeOut.ShapeFields.CreateField("NumField", shpNumeric, 5, 2);
NewFld = ShapeOut.ShapeFields.CreateField("DateField", shpDate);
ShapeOut.AppendFieldDefs();

NewVert = ShapeOut.Vertices.AddVertice(1, 1);


ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(189);
ShapeOut.ShapeFields(2).Value = 1.23;
ShapeOut.ShapeFields(3).Value = (System.DateTime)Now;
ShapeOut.CreateShape();
NewVert = ShapeOut.Vertices.AddVertice(1, 10);
ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(190);
ShapeOut.ShapeFields(2).Value = 2.34;
ShapeOut.ShapeFields(3).Value = (System.DateTime)DateAdd("d", 2, Now);
ShapeOut.CreateShape();
NewVert = ShapeOut.Vertices.AddVertice(10, 10);
ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(191);
ShapeOut.ShapeFields(2).Value = 3.45;
ShapeOut.ShapeFields(3).Value = (System.DateTime)DateAdd("d", 2, Now);
ShapeOut.CreateShape();

// *******************************
// * PointM *
// *******************************
ShapeOut.OpenShape("C:\\Shapes\\PointM_Net_create.shp", shpCreate, shpPointM);
NewFld = ShapeOut.ShapeFields.CreateField("TextField", shpText, 10);
NewFld = ShapeOut.ShapeFields.CreateField("NumField", shpNumeric, 5, 2);
NewFld = ShapeOut.ShapeFields.CreateField("DateField", shpDate);
ShapeOut.AppendFieldDefs();

NewVert = ShapeOut.Vertices.AddVertice(1, 1, 0, 10);


ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(189);
ShapeOut.ShapeFields(2).Value = 1.23;
ShapeOut.ShapeFields(3).Value = (System.DateTime)Now;
ShapeOut.CreateShape();
NewVert = ShapeOut.Vertices.AddVertice(1, 10, 0, 20);
ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(190);
ShapeOut.ShapeFields(2).Value = 2.34;
ShapeOut.ShapeFields(3).Value = (System.DateTime)DateAdd("d", 2, Now);
ShapeOut.CreateShape();
NewVert = ShapeOut.Vertices.AddVertice(10, 10, 0, 30);
ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(191);
ShapeOut.ShapeFields(2).Value = 3.45;
ShapeOut.ShapeFields(3).Value = (System.DateTime)DateAdd("d", 2, Now);
ShapeOut.CreateShape();

// *******************************
// * PointZ *
// *******************************
ShapeOut.OpenShape("C:\\Shapes\\PointZ_Net_create.shp", shpCreate, shpPointZ);

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 22 of 43

NewFld = ShapeOut.ShapeFields.CreateField("TextField", shpText, 10);


NewFld = ShapeOut.ShapeFields.CreateField("NumField", shpNumeric, 5, 2);
NewFld = ShapeOut.ShapeFields.CreateField("DateField", shpDate);
ShapeOut.AppendFieldDefs();

NewVert = ShapeOut.Vertices.AddVertice(1, 1, 0, 10, 111);


ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(189);
ShapeOut.ShapeFields(2).Value = 1.23;
ShapeOut.ShapeFields(3).Value = (System.DateTime)Now;
ShapeOut.CreateShape();
NewVert = ShapeOut.Vertices.AddVertice(1, 10, 0, , 222);
ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(190);
ShapeOut.ShapeFields(2).Value = 2.34;
ShapeOut.ShapeFields(3).Value = (System.DateTime)DateAdd("d", 2, Now);
ShapeOut.CreateShape();
NewVert = ShapeOut.Vertices.AddVertice(10, 10, 0, 30, 333);
ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(191);
ShapeOut.ShapeFields(2).Value = 3.45;
ShapeOut.ShapeFields(3).Value = (System.DateTime)DateAdd("d", 2, Now);
ShapeOut.CreateShape();

// *******************************
// * MultiPoint *
// *******************************
ShapeOut.OpenShape("C:\\Shapes\\MultiPoint_Net_create.shp", shpCreate,
shpMultiPoint);
NewFld = ShapeOut.ShapeFields.CreateField("TextField", shpText, 10);
NewFld = ShapeOut.ShapeFields.CreateField("NumField", shpNumeric, 5, 2);
NewFld = ShapeOut.ShapeFields.CreateField("DateField", shpDate);
ShapeOut.AppendFieldDefs();

NewVert = ShapeOut.Vertices.AddVertice(1, 1);


NewVert = ShapeOut.Vertices.AddVertice(1, 2);
NewVert = ShapeOut.Vertices.AddVertice(1, 3);
ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(189);
ShapeOut.ShapeFields(2).Value = 1.23;
ShapeOut.ShapeFields(3).Value = (System.DateTime)Now;
ShapeOut.CreateShape();
NewVert = ShapeOut.Vertices.AddVertice(1, 11);
NewVert = ShapeOut.Vertices.AddVertice(1, 12);
NewVert = ShapeOut.Vertices.AddVertice(1, 13);
ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(190);
ShapeOut.ShapeFields(2).Value = 2.34;
ShapeOut.ShapeFields(3).Value = (System.DateTime)DateAdd("d", 2, Now);
ShapeOut.CreateShape();
NewVert = ShapeOut.Vertices.AddVertice(10, 10);
NewVert = ShapeOut.Vertices.AddVertice(10, 11);
NewVert = ShapeOut.Vertices.AddVertice(10, 12);
ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(191);
ShapeOut.ShapeFields(2).Value = 3.45;
ShapeOut.ShapeFields(3).Value = (System.DateTime)DateAdd("d", 2, Now);
ShapeOut.CreateShape();

// *******************************
// * MultiPointM *
// *******************************

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 23 of 43

ShapeOut.OpenShape("C:\\Shapes\\MultiPointM_Net_create.shp", shpCreate,
shpMultiPointM);
NewFld = ShapeOut.ShapeFields.CreateField("TextField", shpText, 10);
NewFld = ShapeOut.ShapeFields.CreateField("NumField", shpNumeric, 5, 2);
NewFld = ShapeOut.ShapeFields.CreateField("DateField", shpDate);
ShapeOut.AppendFieldDefs();

NewVert = ShapeOut.Vertices.AddVertice(1, 1, 0, 10);


NewVert = ShapeOut.Vertices.AddVertice(1, 2);
NewVert = ShapeOut.Vertices.AddVertice(1, 3, 0, 11);
ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(189);
ShapeOut.ShapeFields(2).Value = 1.23;
ShapeOut.ShapeFields(3).Value = (System.DateTime)Now;
ShapeOut.CreateShape();
NewVert = ShapeOut.Vertices.AddVertice(1, 11, 0, 20);
NewVert = ShapeOut.Vertices.AddVertice(1, 12);
NewVert = ShapeOut.Vertices.AddVertice(1, 13, 0, 21);
ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(190);
ShapeOut.ShapeFields(2).Value = 2.34;
ShapeOut.ShapeFields(3).Value = (System.DateTime)DateAdd("d", 2, Now);
ShapeOut.CreateShape();
NewVert = ShapeOut.Vertices.AddVertice(10, 10, 0, 30);
NewVert = ShapeOut.Vertices.AddVertice(10, 11);
NewVert = ShapeOut.Vertices.AddVertice(10, 12, 0, 31);
ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(191);
ShapeOut.ShapeFields(2).Value = 3.45;
ShapeOut.ShapeFields(3).Value = (System.DateTime)DateAdd("d", 2, Now);
ShapeOut.CreateShape();

// *******************************
// * MultiPointZ *
// *******************************
ShapeOut.OpenShape("C:\\Shapes\\MultiPointZ_Net_create.shp", shpCreate,
shpMultiPointZ);
NewFld = ShapeOut.ShapeFields.CreateField("TextField", shpText, 10);
NewFld = ShapeOut.ShapeFields.CreateField("NumField", shpNumeric, 5, 2);
NewFld = ShapeOut.ShapeFields.CreateField("DateField", shpDate);
ShapeOut.AppendFieldDefs();

NewVert = ShapeOut.Vertices.AddVertice(1, 1, 0, 10, 110);


NewVert = ShapeOut.Vertices.AddVertice(1, 2, 0, , 111);
NewVert = ShapeOut.Vertices.AddVertice(1, 3, 0, 11, 112);
ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(189);
ShapeOut.ShapeFields(2).Value = 1.23;
ShapeOut.ShapeFields(3).Value = (System.DateTime)Now;
ShapeOut.CreateShape();
NewVert = ShapeOut.Vertices.AddVertice(1, 11, 0, 20, 220);
NewVert = ShapeOut.Vertices.AddVertice(1, 12, 0, , 221);
NewVert = ShapeOut.Vertices.AddVertice(1, 13, 0, 21, 222);
ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(190);
ShapeOut.ShapeFields(2).Value = 2.34;
ShapeOut.ShapeFields(3).Value = (System.DateTime)DateAdd("d", 2, Now);
ShapeOut.CreateShape();
NewVert = ShapeOut.Vertices.AddVertice(10, 10, 0, 30, 330);
NewVert = ShapeOut.Vertices.AddVertice(10, 11, 0, , 331);
NewVert = ShapeOut.Vertices.AddVertice(10, 12, 0, 31, 332);

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 24 of 43

ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(191);


ShapeOut.ShapeFields(2).Value = 3.45;
ShapeOut.ShapeFields(3).Value = (System.DateTime)DateAdd("d", 2, Now);
ShapeOut.CreateShape();

// *******************************
// * PolyLine *
// *******************************
ShapeOut.OpenShape("C:\\Shapes\\PolyLine_Net_create.shp", shpCreate, shpPolyLine);
NewFld = ShapeOut.ShapeFields.CreateField("TextField", shpText, 10);
NewFld = ShapeOut.ShapeFields.CreateField("NumField", shpNumeric, 5, 2);
NewFld = ShapeOut.ShapeFields.CreateField("DateField", shpDate);
ShapeOut.AppendFieldDefs();

NewVert = ShapeOut.Vertices.AddVertice(1, 1);


NewVert = ShapeOut.Vertices.AddVertice(1, 10);
NewVert = ShapeOut.Vertices.AddVertice(10, 10);
NewVert = ShapeOut.Vertices.AddVertice(10, 1);
NewVert = ShapeOut.Vertices.AddVertice(1, 1);
ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(189);
ShapeOut.ShapeFields(2).Value = 1.23;
ShapeOut.ShapeFields(3).Value = (System.DateTime)Now;
ShapeOut.CreateShape();

NewVert = ShapeOut.Vertices.AddVertice(10, 1, 1);


NewVert = ShapeOut.Vertices.AddVertice(10, 10, 1);
NewVert = ShapeOut.Vertices.AddVertice(20, 10, 1);
NewVert = ShapeOut.Vertices.AddVertice(20, 1, 1);
NewVert = ShapeOut.Vertices.AddVertice(10, 1, 1);
NewVert = ShapeOut.Vertices.AddVertice(14, 4, 2);
NewVert = ShapeOut.Vertices.AddVertice(14, 6, 2);
NewVert = ShapeOut.Vertices.AddVertice(16, 6, 2);
NewVert = ShapeOut.Vertices.AddVertice(16, 4, 2);
NewVert = ShapeOut.Vertices.AddVertice(14, 4, 2);
ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(190);
ShapeOut.ShapeFields(2).Value = 2.34;
ShapeOut.ShapeFields(3).Value = (System.DateTime)DateAdd("d", 1, Now);
ShapeOut.CreateShape();

NewVert = ShapeOut.Vertices.AddVertice(20, 1);


NewVert = ShapeOut.Vertices.AddVertice(20, 10);
NewVert = ShapeOut.Vertices.AddVertice(30, 10);
NewVert = ShapeOut.Vertices.AddVertice(30, 1);
NewVert = ShapeOut.Vertices.AddVertice(20, 1);
ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(191);
ShapeOut.ShapeFields(2).Value = 3.45;
ShapeOut.ShapeFields(3).Value = (System.DateTime)DateAdd("d", 2, Now);
ShapeOut.CreateShape();

// *******************************
// * PolyLineM *
// *******************************
ShapeOut.OpenShape("C:\\Shapes\\PolyLineM_Net_create.shp", shpCreate,
shpPolyLineM);
NewFld = ShapeOut.ShapeFields.CreateField("TextField", shpText, 10);
NewFld = ShapeOut.ShapeFields.CreateField("NumField", shpNumeric, 5, 2);

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 25 of 43

NewFld = ShapeOut.ShapeFields.CreateField("DateField", shpDate);


ShapeOut.AppendFieldDefs();

NewVert = ShapeOut.Vertices.AddVertice(1, 1, 0, 10);


NewVert = ShapeOut.Vertices.AddVertice(1, 10);
NewVert = ShapeOut.Vertices.AddVertice(10, 10, 0, 11);
NewVert = ShapeOut.Vertices.AddVertice(10, 1, 0, 12);
NewVert = ShapeOut.Vertices.AddVertice(1, 1, 0, 13);
ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(189);
ShapeOut.ShapeFields(2).Value = 1.23;
ShapeOut.ShapeFields(3).Value = (System.DateTime)Now;
ShapeOut.CreateShape();

NewVert = ShapeOut.Vertices.AddVertice(10, 1, 1, 20);


NewVert = ShapeOut.Vertices.AddVertice(10, 10, 1);
NewVert = ShapeOut.Vertices.AddVertice(20, 10, 1, 21);
NewVert = ShapeOut.Vertices.AddVertice(20, 1, 1, 22);
NewVert = ShapeOut.Vertices.AddVertice(10, 1, 1, 23);
NewVert = ShapeOut.Vertices.AddVertice(14, 4, 2, 24);
NewVert = ShapeOut.Vertices.AddVertice(14, 6, 2, 25);
NewVert = ShapeOut.Vertices.AddVertice(16, 6, 2, 26);
NewVert = ShapeOut.Vertices.AddVertice(16, 4, 2, 27);
NewVert = ShapeOut.Vertices.AddVertice(14, 4, 2, 28);
ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(190);
ShapeOut.ShapeFields(2).Value = 2.34;
ShapeOut.ShapeFields(3).Value = (System.DateTime)DateAdd("d", 1, Now);
ShapeOut.CreateShape();

NewVert = ShapeOut.Vertices.AddVertice(20, 1, 0, 30);


NewVert = ShapeOut.Vertices.AddVertice(20, 10);
NewVert = ShapeOut.Vertices.AddVertice(30, 10, 0, 31);
NewVert = ShapeOut.Vertices.AddVertice(30, 1, 0, 32);
NewVert = ShapeOut.Vertices.AddVertice(20, 1, 0, 33);
ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(191);
ShapeOut.ShapeFields(2).Value = 3.45;
ShapeOut.ShapeFields(3).Value = (System.DateTime)DateAdd("d", 2, Now);
ShapeOut.CreateShape();

// *******************************
// * PolyLineM *
// *******************************
ShapeOut.OpenShape("C:\\Shapes\\PolyLineZ_Net_create.shp", shpCreate,
shpPolyLineZ);
NewFld = ShapeOut.ShapeFields.CreateField("TextField", shpText, 10);
NewFld = ShapeOut.ShapeFields.CreateField("NumField", shpNumeric, 5, 2);
NewFld = ShapeOut.ShapeFields.CreateField("DateField", shpDate);
ShapeOut.AppendFieldDefs();

NewVert = ShapeOut.Vertices.AddVertice(1, 1, 0, 11, 110);


NewVert = ShapeOut.Vertices.AddVertice(1, 10, 0, , 111);
NewVert = ShapeOut.Vertices.AddVertice(10, 10, 0, 12, 112);
NewVert = ShapeOut.Vertices.AddVertice(10, 1, 0, 13, 113);
NewVert = ShapeOut.Vertices.AddVertice(1, 1, 0, 14, 114);
ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(189);
ShapeOut.ShapeFields(2).Value = 1.23;
ShapeOut.ShapeFields(3).Value = (System.DateTime)Now;

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 26 of 43

ShapeOut.CreateShape();

NewVert = ShapeOut.Vertices.AddVertice(10, 1, 1, 20, 220);


NewVert = ShapeOut.Vertices.AddVertice(10, 10, 1, 0, 221);
NewVert = ShapeOut.Vertices.AddVertice(20, 10, 1, 21, 222);
NewVert = ShapeOut.Vertices.AddVertice(20, 1, 1, 22, 223);
NewVert = ShapeOut.Vertices.AddVertice(10, 1, 1, 23, 224);
NewVert = ShapeOut.Vertices.AddVertice(14, 4, 2, 24, 225);
NewVert = ShapeOut.Vertices.AddVertice(14, 6, 2, 25, 226);
NewVert = ShapeOut.Vertices.AddVertice(16, 6, 2, 26, 227);
NewVert = ShapeOut.Vertices.AddVertice(16, 4, 2, 27, 228);
NewVert = ShapeOut.Vertices.AddVertice(14, 4, 2, 28, 229);
ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(190);
ShapeOut.ShapeFields(2).Value = 2.34;
ShapeOut.ShapeFields(3).Value = (System.DateTime)DateAdd("d", 1, Now);
ShapeOut.CreateShape();

NewVert = ShapeOut.Vertices.AddVertice(20, 1, 0, 30, 330);


NewVert = ShapeOut.Vertices.AddVertice(20, 10, 0, , 331);
NewVert = ShapeOut.Vertices.AddVertice(30, 10, 0, 31, 332);
NewVert = ShapeOut.Vertices.AddVertice(30, 1, 0, 32, 333);
NewVert = ShapeOut.Vertices.AddVertice(20, 1, 0, 33, 334);
ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(191);
ShapeOut.ShapeFields(2).Value = 3.45;
ShapeOut.ShapeFields(3).Value = (System.DateTime)DateAdd("d", 2, Now);
ShapeOut.CreateShape();

// *******************************
// * Polygon *
// *******************************
ShapeOut.OpenShape("C:\\Shapes\\Polygon_Net_create.shp", shpCreate, shpPolygon);
NewFld = ShapeOut.ShapeFields.CreateField("TextField", shpText, 10);
NewFld = ShapeOut.ShapeFields.CreateField("NumField", shpNumeric, 5, 2);
NewFld = ShapeOut.ShapeFields.CreateField("DateField", shpDate);
ShapeOut.AppendFieldDefs();

NewVert = ShapeOut.Vertices.AddVertice(1, 1);


NewVert = ShapeOut.Vertices.AddVertice(1, 10);
NewVert = ShapeOut.Vertices.AddVertice(10, 10);
NewVert = ShapeOut.Vertices.AddVertice(10, 1);
NewVert = ShapeOut.Vertices.AddVertice(1, 1);
ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(189);
ShapeOut.ShapeFields(2).Value = 1.23;
ShapeOut.ShapeFields(3).Value = (System.DateTime)Now;
ShapeOut.CreateShape();

NewVert = ShapeOut.Vertices.AddVertice(10, 1, 1);


NewVert = ShapeOut.Vertices.AddVertice(10, 10, 1);
NewVert = ShapeOut.Vertices.AddVertice(20, 10, 1);
NewVert = ShapeOut.Vertices.AddVertice(20, 1, 1);
NewVert = ShapeOut.Vertices.AddVertice(10, 1, 1);
NewVert = ShapeOut.Vertices.AddVertice(14, 4, 2);
NewVert = ShapeOut.Vertices.AddVertice(14, 6, 2);
NewVert = ShapeOut.Vertices.AddVertice(16, 6, 2);
NewVert = ShapeOut.Vertices.AddVertice(16, 4, 2);
NewVert = ShapeOut.Vertices.AddVertice(14, 4, 2);

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 27 of 43

ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(190);


ShapeOut.ShapeFields(2).Value = 2.34;
ShapeOut.ShapeFields(3).Value = (System.DateTime)DateAdd("d", 1, Now);
ShapeOut.CreateShape();

NewVert = ShapeOut.Vertices.AddVertice(20, 1);


NewVert = ShapeOut.Vertices.AddVertice(20, 10);
NewVert = ShapeOut.Vertices.AddVertice(30, 10);
NewVert = ShapeOut.Vertices.AddVertice(30, 1);
NewVert = ShapeOut.Vertices.AddVertice(20, 1);
ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(191);
ShapeOut.ShapeFields(2).Value = 3.45;
ShapeOut.ShapeFields(3).Value = (System.DateTime)DateAdd("d", 2, Now);
ShapeOut.CreateShape();

// *******************************
// * PolygonM *
// *******************************
ShapeOut.OpenShape("C:\\Shapes\\PolygonM_Net_create.shp", shpCreate, shpPolygonM);
NewFld = ShapeOut.ShapeFields.CreateField("TextField", shpText, 10);
NewFld = ShapeOut.ShapeFields.CreateField("NumField", shpNumeric, 5, 2);
NewFld = ShapeOut.ShapeFields.CreateField("DateField", shpDate);
ShapeOut.AppendFieldDefs();

NewVert = ShapeOut.Vertices.AddVertice(1, 1, 0, 10);


NewVert = ShapeOut.Vertices.AddVertice(1, 10);
NewVert = ShapeOut.Vertices.AddVertice(10, 10, 0, 11);
NewVert = ShapeOut.Vertices.AddVertice(10, 1, 0, 12);
NewVert = ShapeOut.Vertices.AddVertice(1, 1, 0, 13);
ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(189);
ShapeOut.ShapeFields(2).Value = 1.23;
ShapeOut.ShapeFields(3).Value = (System.DateTime)Now;
ShapeOut.CreateShape();

NewVert = ShapeOut.Vertices.AddVertice(10, 1, 1, 20);


NewVert = ShapeOut.Vertices.AddVertice(10, 10, 1);
NewVert = ShapeOut.Vertices.AddVertice(20, 10, 1, 21);
NewVert = ShapeOut.Vertices.AddVertice(20, 1, 1, 22);
NewVert = ShapeOut.Vertices.AddVertice(10, 1, 1, 23);
NewVert = ShapeOut.Vertices.AddVertice(14, 4, 2, 24);
NewVert = ShapeOut.Vertices.AddVertice(14, 6, 2, 25);
NewVert = ShapeOut.Vertices.AddVertice(16, 6, 2, 26);
NewVert = ShapeOut.Vertices.AddVertice(16, 4, 2, 27);
NewVert = ShapeOut.Vertices.AddVertice(14, 4, 2, 28);
ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(190);
ShapeOut.ShapeFields(2).Value = 2.34;
ShapeOut.ShapeFields(3).Value = (System.DateTime)DateAdd("d", 1, Now);
ShapeOut.CreateShape();

NewVert = ShapeOut.Vertices.AddVertice(20, 1, 0, 30);


NewVert = ShapeOut.Vertices.AddVertice(20, 10);
NewVert = ShapeOut.Vertices.AddVertice(30, 10, 0, 31);
NewVert = ShapeOut.Vertices.AddVertice(30, 1, 0, 32);
NewVert = ShapeOut.Vertices.AddVertice(20, 1, 0, 33);
ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(191);
ShapeOut.ShapeFields(2).Value = 3.45;

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 28 of 43

ShapeOut.ShapeFields(3).Value = (System.DateTime)DateAdd("d", 2, Now);


ShapeOut.CreateShape();

// *******************************
// * PolygonZ *
// *******************************
ShapeOut.OpenShape("C:\\Shapes\\PolygonZ_Net_create.shp", shpCreate, shpPolygonZ);
NewFld = ShapeOut.ShapeFields.CreateField("TextField", shpText, 10);
NewFld = ShapeOut.ShapeFields.CreateField("NumField", shpNumeric, 5, 2);
NewFld = ShapeOut.ShapeFields.CreateField("DateField", shpDate);
ShapeOut.AppendFieldDefs();

NewVert = ShapeOut.Vertices.AddVertice(1, 1, 0, 11, 110);


NewVert = ShapeOut.Vertices.AddVertice(1, 10, 0, , 111);
NewVert = ShapeOut.Vertices.AddVertice(10, 10, 0, 12, 112);
NewVert = ShapeOut.Vertices.AddVertice(10, 1, 0, 13, 113);
NewVert = ShapeOut.Vertices.AddVertice(1, 1, 0, 14, 114);
ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(189);
ShapeOut.ShapeFields(2).Value = 1.23;
ShapeOut.ShapeFields(3).Value = (System.DateTime)Now;
ShapeOut.CreateShape();

NewVert = ShapeOut.Vertices.AddVertice(10, 1, 1, 20, 220);


NewVert = ShapeOut.Vertices.AddVertice(10, 10, 1, 0, 221);
NewVert = ShapeOut.Vertices.AddVertice(20, 10, 1, 21, 222);
NewVert = ShapeOut.Vertices.AddVertice(20, 1, 1, 22, 223);
NewVert = ShapeOut.Vertices.AddVertice(10, 1, 1, 23, 224);
NewVert = ShapeOut.Vertices.AddVertice(14, 4, 2, 24, 225);
NewVert = ShapeOut.Vertices.AddVertice(14, 6, 2, 25, 226);
NewVert = ShapeOut.Vertices.AddVertice(16, 6, 2, 26, 227);
NewVert = ShapeOut.Vertices.AddVertice(16, 4, 2, 27, 228);
NewVert = ShapeOut.Vertices.AddVertice(14, 4, 2, 28, 229);
ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(190);
ShapeOut.ShapeFields(2).Value = 2.34;
ShapeOut.ShapeFields(3).Value = (System.DateTime)DateAdd("d", 1, Now);
ShapeOut.CreateShape();

NewVert = ShapeOut.Vertices.AddVertice(20, 1, 0, 30, 330);


NewVert = ShapeOut.Vertices.AddVertice(20, 10, 0, , 331);
NewVert = ShapeOut.Vertices.AddVertice(30, 10, 0, 31, 332);
NewVert = ShapeOut.Vertices.AddVertice(30, 1, 0, 32, 333);
NewVert = ShapeOut.Vertices.AddVertice(20, 1, 0, 33, 334);
ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(191);
ShapeOut.ShapeFields(2).Value = 3.45;
ShapeOut.ShapeFields(3).Value = (System.DateTime)DateAdd("d", 2, Now);
ShapeOut.CreateShape();

// *******************************
// * MultiPatch *
// *******************************
ShapeOut.OpenShape("C:\\Shapes\\MultiPatch_Net_create.shp", shpCreate,
shpMultiPatch);
NewFld = ShapeOut.ShapeFields.CreateField("TextField", shpText, 10);
NewFld = ShapeOut.ShapeFields.CreateField("NumField", shpNumeric, 5, 2);
NewFld = ShapeOut.ShapeFields.CreateField("DateField", shpDate);
ShapeOut.AppendFieldDefs();

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 29 of 43

ShapeOut.ShapeFields(1).Value = "Ross" + Strings.Chr(189);


ShapeOut.ShapeFields(2).Value = 1.23;
ShapeOut.ShapeFields(3).Value = (System.DateTime)Now;

NewVert = ShapeOut.Vertices.AddVertice(10, 1, 1, 20, 220, shpOuterRing);


NewVert = ShapeOut.Vertices.AddVertice(10, 10, 1, 0, 221, shpOuterRing);
NewVert = ShapeOut.Vertices.AddVertice(20, 10, 1, 21, 222, shpOuterRing);
NewVert = ShapeOut.Vertices.AddVertice(20, 1, 1, 22, 223, shpOuterRing);
NewVert = ShapeOut.Vertices.AddVertice(10, 1, 1, 23, 224, shpOuterRing);
NewVert = ShapeOut.Vertices.AddVertice(14, 4, 2, 24, 225, shpInnerRing);
NewVert = ShapeOut.Vertices.AddVertice(14, 6, 2, 25, 226, shpInnerRing);
NewVert = ShapeOut.Vertices.AddVertice(16, 6, 2, 26, 227, shpInnerRing);
NewVert = ShapeOut.Vertices.AddVertice(16, 4, 2, 27, 228, shpInnerRing);
NewVert = ShapeOut.Vertices.AddVertice(14, 4, 2, 28, 229, shpInnerRing);
ShapeOut.CreateShape();
}
}

Using the OCX - Examples

How To Append To An Existing ShapeFile

In the following example it is assumed that you have dragged an instance of the ShapeFile Control
from the IDE over to your Visual Basic project and renamed the OCX instance as ShapeOut.

In this case the ShapeFile Control is used to write a series of ShapeFiles. The first shape is written,
then the file reopened to add the extra shapes. A point to note is that you have to clear the
Vertices collection before adding any new records when appending to an existing ShapeFile.

Visual Basic 6 Example:

Sub WriteShapes()

Dim NewFld As ShapeField


Dim NewVert As Vertice

With ShapeOut

' *******************************
' * Create New Point Shape *
' *******************************
.OpenShape "C:\Shapes\Point_append.shp", shpCreate, shpPoint
Set NewFld = .ShapeFields.CreateField("TextField", shpText, 10)
Set NewFld = .ShapeFields.CreateField("NumField", shpNumeric, 5, 2)
Set NewFld = .ShapeFields.CreateField("DateField", shpDate)
.AppendFieldDefs

Set NewVert = .Vertices.AddVertice(1, 1)


.ShapeFields(1).Value = "ROSS" + Chr(189)
.ShapeFields(2).Value = 1.23
.ShapeFields(3).Value = CDate(Now)
.CreateShape

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 30 of 43

End With

With ShapeOut

' *******************************
' * Append to Existing Point Shape *
' *******************************
.OpenShape "C:\Shapes\Pointappend.shp", shpOpen
' Clear the Vertice structure that is automatically populated by .OpenShape
If .ReadDataOnMove <> HeaderOnly Then
.Vertices.Clear
' You may also want to clear the records in the ShapeFields structure
.ShapeFields.Clear
End If

' Append some more records


Set NewVert = .Vertices.AddVertice(1, 10)
.ShapeFields(1).Value = "ROSS" + Chr(190)
.ShapeFields(2).Value = 2.34
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape

Set NewVert = .Vertices.AddVertice(10, 10)


.ShapeFields(1).Value = "ROSS" + Chr(191)
.ShapeFields(2).Value = 3.45
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape

End With

End Sub

VB .NET Example:

Imports crpShape = ArcViewShapeFileDLL


Imports ArcViewShapeFileDLL.ShapeFiles.eNew
Imports ArcViewShapeFileDLL.ShapeFiles.eFieldType
Imports ArcViewShapeFileDLL.ShapeFiles.eShapeType
Imports ArcViewShapeFileDLL.ShapeFiles.eReadMode
Imports ArcViewShapeFileDLL.ShapeFiles.ePartType

Module Examples

Sub AppendShapes()
Dim ShapeOut As New crpShape.ShapeFiles
Dim NewFld As crpShape.ShapeField
Dim NewVert As crpShape.Vertice

With ShapeOut

' *******************************

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 31 of 43

' * Create New Point Shape *


' *******************************
.OpenShape("C:\Shapes\Point_Net_append.shp", shpCreate, shpPoint)
NewFld = .ShapeFields.CreateField("TextField", shpText, 10)
NewFld = .ShapeFields.CreateField("NumField", shpNumeric, 5, 2)
NewFld = .ShapeFields.CreateField("DateField", shpDate)
.AppendFieldDefs()

NewVert = .Vertices.AddVertice(1, 1)
.ShapeFields(1).Value = "Ross" + Chr(189)
.ShapeFields(2).Value = 1.23
.ShapeFields(3).Value = CDate(Now)
.CreateShape()

End With

With ShapeOut

' *******************************
' * Append to Existing Point Shape *
' *******************************
.OpenShape("C:\Shapes\Point_Net_append.shp", shpOpen)
' Clear the Vertice structure that is automatically populated by .OpenShape
If .ReadDataOnMove <> HeaderOnly Then
.Vertices.Clear()
' You may also want to clear the records in the ShapeFields structure
.ShapeFields.Clear()
End If

' Append some more records


NewVert = .Vertices.AddVertice(1, 10)
.ShapeFields(1).Value = "Ross" + Chr(190)
.ShapeFields(2).Value = 2.34
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape()

NewVert = .Vertices.AddVertice(10, 10)


.ShapeFields(1).Value = "Ross" + Chr(191)
.ShapeFields(2).Value = 3.45
.ShapeFields(3).Value = CDate(DateAdd("d", 2, Now))
.CreateShape()

End With

End Sub

End Module

Using the OCX - Examples

Creating a Polygon ShapeFile from Data in MS Access

In this example a new ShapeFile is created from attribute and vertice info held in an Access
database. The Access database (Points.mdb) Contains some point data with the fields X and Y
containing the X & Y coordinates.

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 32 of 43

On the form are the ShapeFile Control and MicroSofts' Data Control. The Data Control is called
DataIn and the ShapeFile Control is called ShapeFiles1. Here is a note of warning ... the data
type definitions in ADO and DAO do differ from the data types available in the ShapeFile DBF
format so I've included a bit of code to get you started. This example may not be the most efficient
code wise ... but here we go ...

Sub EGDAOInput()
Dim NewVert As Vertices
Dim NewField As ShapeField
Dim dbAccess As DAO.Database
Dim rcAccess As DAO.Recordset
Dim fdDefn As Field
Dim i As Long

' Set up the database files


Set dbAccess = OpenDatabase("C:\Temp\Points.mdb")
Set rcAccess = dbAccess.OpenRecordset("Sheet", dbOpenDynaset)

With ShapeFiles1

' Open the output file


.OpenShape "C:\Temp\PointOut.shp", shpCreate, shpPoint
' Set up the ShapeFile Field definitions from the Access table definitions.
Dim outType As eFieldType
Dim outSize As Integer

' in ADODB you can use NumericScale to returns the number of decimal places
' allowed for numeric values otherwise you're guessing

For Each fdDefn In rcAccess.Fields


outSize = fdDefn.Size
Select Case fdDefn.Type
Case dbBoolean
outType = shpBoolean
Case dbDate
outType = shpDate
Case dbDouble
outType = shpDouble
Case dbFloat
outType = shpFloat
Case dbInteger
outType = shpInteger
Case dbLong
outType = shpLong
Case dbSingle
outType = shpSingle
Case Else
' Convert to Text
outType = shpText
End Select

Set NewField = .ShapeFields.CreateField(fdDefn.Name, outType, outSize)


Next fdDefn

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 33 of 43

' Save the ShapeField definitions


.AppendFieldDefs

Do While Not rcAccess.EOF

' For each record in the database copy the field values to the ShapeFile
For Each fdDefn In rcAccess.Fields
.ShapeFields(fdDefn.Name).Value = fdDefn.Value
Next fdDefn

' Find the database vertice record


Set NewVert = .Vertices.AddVertice(rcAccess.Fields("X"), rcAccess.Fields("Y"))

' Create the ShapeFile Record


.CreateShape

' Move to the next Access record


rcAccess.MoveNext

Loop
rcAccess.Close

End With

End Sub

Using the OCX - Examples

How To Use the ShapeFile Control in ASP or HTML pages

Both the OCX and DLL are Active X COM objects so you can use either of them in ASP and HTML
pages. The trick is that each reference to a ShapeFiles, ShapeField and Vertice object needs to be
created using the CreateObject command and any enumerations parsed have to be converted to
integers. Huh??? Here is an VBScript ASP sample that creates a polygon, maybe that will make it
clearer. Oh, and remember that the ArcViewShapeFileDLL must be properly registered using
REGSVR32 before you can use it.

<%
' Dimension the object references required
%>
Dim NewVert As Vertices
Dim MyShape
Set MyShape = Server.CreateObject("ArcViewShapeFileDLL.ShapeFiles")
Dim NewVert
Set NewVert = Server.CreateObject("ArcViewShapeFileDLL.Vertice")
Dim ShapeField
Set ShapeField = Server.CreateObject("ArcViewShapeFileDLL.ShapeField")

<%
' Create a new polygon ShapeFile. The enumeration for shpCreate = 1, and shpPolygon = 5
' Note that the ShapeFields types in the CreateField statements are also converted from the
enumeration

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 34 of 43

%>
MyShape.OpenShape "C:/Temp/PolyOut.shp",1,5
Set NewField = MyShape.ShapeFields.CreateField("Poly_id",4
Set NewField = MyShape.ShapeFields.CreateField("Name",10,20)
Set NewField = MyShape.ShapeFields.CreateField("Date_Mod",8)
MyShape.AppendFieldDefs

<%
' Add the record values and create the new shape
%>
MyShape.ShapeFields("Poly_id").Value = 1
MyShape.ShapeFields("Name").Value = "The First Polygon"
MyShape.ShapeFields("Date_Mod").Value = CDate("19/11/2004")
Set NewVert = MyShape.Vertices.AddVertice(1,1)
Set NewVert = MyShape.Vertices.AddVertice(1,10)
Set NewVert = MyShape.Vertices.AddVertice(10,10)
Set NewVert = MyShape.Vertices.AddVertice(10,1)
Set NewVert = MyShape.Vertices.AddVertice(1,1)
MyShape.CreateShape

<%
' Tidy Up
%>
Set NewField = Nothing
Set NewVert = Nothing
Set ShapeOut = Nothing

Using the OCX - Examples

Using the Find Methods

The following example shows how you can use the two different find methods. The first
searches the ShapeFile database for a match against a SQL style query. The second does a
point in polygon search.

Drag an instance of the ShapeFile Control from the IDE over to your Visual Basic project to
get the ShapeFiles1 instance or dimension a new instance of the DLL with the same name.
The example uses the polygon ShapeFile created in the Creating Shapes example.

Sub Find()
' Find Examples

With ShapeFiles1
.ReadDataOnMove = FastRead
.OpenShape "C:\Shapes\Polygons_base.shp", shpOpen

Debug.Print "Example 1: Find using SQL structured criteria"


Debug.Print "This should find records 1 & 2"

.FindFirst "NumField >= 2.34"

Do While Not .NoMatch

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 35 of 43

Debug.Print "Record Found: "; .CurrentRecord


Debug.Print "Field Value: "; .ShapeFields("NumField").Value

' Find the next record matching the condition


.FindNext

Loop
Debug.Print ""

Debug.Print "Example 2: Find using XY point in polygon"


Debug.Print "This should find records 2 & 3"

.FindbyXY 10, 5

Do While Not .NoMatch

Debug.Print "Record Found: "; .CurrentRecord


Debug.Print "Field Value: "; .ShapeFields("NumField").Value

' Find the next record matching the condition


.FindNext

Loop

End With

End Sub

Using the OCX - Examples

Display a Shapefile using .NET using the COM DLL

The following example provided by Marc Miller shows how you can use the COM DLL in
Visual Studio .NET (see ... it can be done). The DLL has been referenced under the
WindowsApplication References. On the form is a Picture box (PictureBox1), a List box
(ListBox1) and two buttons (btnReadVertices and btnReadAttributes). In this case the
application loads a ShapeFile of the USA. The first button will display the ShapeFile and
list the Vertice info and the second button lists the attribute data. The application looks
like this:

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 36 of 43

OK ... here is the source code.

Imports System
Imports System.IO
Imports System.Text
Imports System.Drawing
Imports Microsoft.VisualBasic
Imports System.Windows.Forms.PictureBox
Imports System.Math

Public Class Form1


Dim MyShape As New ArcViewShapeFileDLL.ShapeFiles
Dim MaxX As Double = 0
Dim MinX As Double = 0
Dim MaxY As Double = 0
Dim MinY As Double = 0
Dim pbMaxX As Double = 0
Dim pbMaxY As Double = 0
Dim XDegPerPixel As Double = 0
Dim YDegPerPixel As Double = 0

Dim g As Graphics ' Declare a variable to hold a Graphics object


Dim bmap As Bitmap ' Variable for Bitmap to be displayed in (PictureBox)
control

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load

End Sub

Private Sub btnReadVertices_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
Dim arLat As New ArrayList
Dim arLon As New ArrayList

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 37 of 43

Dim ThisPart As Integer


Dim VertCount As Integer
Dim Record As Integer = 0
Dim Fin As String = ""
Dim X As Double = 0
Dim Y As Double = 0
Dim pt As Integer = 0
Dim Coord As Integer
Dim Lon As Double = 0
Dim Lat As Double = 0
Dim StartPoint As New Point
Dim EndPoint As New Point
Dim LinePen As New Pen(Color.Red, 1)
Dim shpOpen As ArcViewShapeFileDLL.eNew

'init picturebox
PictureBox1.SizeMode = PictureBoxSizeMode.CenterImage
g = GetGraphics()

Fin = "..\states.shp"
MyShape.ReadDataOnMove = True
ListBox1.Items.Clear()

If File.Exists(Fin) Then
MyShape.OpenShape(Fin, shpOpen)
ListBox1.Items.Add("Number of Records: " &
MyShape.RecordCount)
ListBox1.Items.Add(MyShape.xMin & vbTab & MyShape.xMax)
ListBox1.Items.Add(MyShape.yMin & vbTab & MyShape.yMax)

'set picturebox bounds


MinX = MyShape.xMin - 10
MaxX = MyShape.xMax + 10
MinY = MyShape.yMin - 10
MaxY = MyShape.yMax + 10

pbMaxX = PictureBox1.Width
pbMaxY = PictureBox1.Height
XDegPerPixel = Math.Abs(MaxX - MinX) / pbMaxX
YDegPerPixel = Math.Abs(MaxY - MinY) / pbMaxY

With MyShape
For Record = 0 To MyShape.RecordCount - 1
For ThisPart = 1 To .Parts.Count
For VertCount = .Parts
(ThisPart).Begins To .Parts(ThisPart).Ends
arLon.Add(.Vertices
(VertCount).X_Cord)
arLat.Add(.Vertices
(VertCount).Y_Cord)
Next VertCount

'using ArrayList, integrate vertices


into picture box
pt = 0
For Coord = 0 To arLat.Count - 2

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 38 of 43

'For clarity
' Lon = CType(arLon
(pt), Double)
' Lat = CType(arLat
(pt), Double)
' X = Math.Abs(Lon -
MinX) / XDegPerPixel
' Y = Math.Abs(MaxY
- Lat) / YDegPerPixel
'For optimization
X = Math.Abs(CType(arLon
(pt), Double) - MinX) / XDegPerPixel
Y = Math.Abs(MaxY - CType
(arLat(pt), Double)) / YDegPerPixel
StartPoint = New Point
(CType(X, Integer), CType(Y, Integer))

'For clarity
' Lon = CType(arLon
(pt + 1), Double)
' Lat = CType(arLat
(pt + 1), Double)
' X = Math.Abs(Lon -
MinX) / XDegPerPixel
' Y = Math.Abs(MaxY
- Lat) / YDegPerPixel
'For optimization
X = Math.Abs(CType(arLon
(pt + 1), Double) - MinX) / XDegPerPixel
Y = Math.Abs(MaxY - CType
(arLat(pt + 1), Double)) / YDegPerPixel
EndPoint = New Point(CType
(X, Integer), CType(Y, Integer))

g.DrawLine(LinePen,
StartPoint, EndPoint)
pt += 1
Next Coord
'clear ArrayList for next record
arLat.Clear()
arLon.Clear()

Next ThisPart
MyShape.MoveNext()

Next Record

End With
'draw shape file
PictureBox1.Image = bmap
g.Dispose()
End If

End Sub

Private Sub btnReadAttributes_Click(ByVal sender As System.Object, ByVal e

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 39 of 43

As System.EventArgs) Handles btnReadAttributes.Click


Dim ThisRecord As Long, ThisData As Long
Dim ThisPart As Long, VertCount As Long
Dim Count As Integer
Dim shpOpen As ArcViewShapeFileDLL.eNew
Count = 0
ListBox1.Items.Clear()
With MyShape
If File.Exists("..\states.shp") Then

.OpenShape("..\states.shp", shpOpen)

' Read in each shape record in turn


For ThisRecord = 1 To .RecordCount

' Print out the name and values of the


ShapeFile attribute data.
For ThisData = 1 To .ShapeFields.Count

ListBox1.Items.Add(.ShapeFields
(ThisData).FieldName & vbTab & .ShapeFields(ThisData).Value.ToString)

Next ThisData

' Print out the coordinates that make up this


shape file
' Because we’re dealing with a polygon file, it
is best to output by Parts
' You can also just output from 1
To .Vertice.Count
For ThisPart = 1 To .Parts.Count

For VertCount = .Parts


(ThisPart).Begins To .Parts(ThisPart).Ends
ListBox1.Items.Add(.Vertices
(VertCount).X_Cord & vbTab & .Vertices(VertCount).Y_Cord & vbTab & .Vertices
(VertCount).PartNo)

Next VertCount

Next ThisPart
Next ThisRecord
ListBox1.Items.Add("")
ListBox1.Items.Add(ThisRecord.ToString)
End If
End With

End Sub

Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As


System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
Dim Lon As Double
Dim Lat As Double

pbMaxX = PictureBox1.Width
pbMaxY = PictureBox1.Height

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 40 of 43

XDegPerPixel = Math.Abs(MaxX - MinX) / CType(pbMaxX, Double)


YDegPerPixel = Math.Abs(MaxY - MinY) / CType(pbMaxY, Double)

Lon = MinX + (XDegPerPixel * CType(e.X, Double))


Lat = MaxY - (YDegPerPixel * CType(e.Y, Double))

Me.Text = "Lat: " & Format(Lat, "###0.00000") & Space(10) & "Lon:
" & Format(Lon, "###0.00000")
End Sub

Private Function GetGraphics() As Graphics


' Make bmap the same size and resolution as the PictureBox
bmap = New Bitmap(PictureBox1.Width, PictureBox1.Height,
PictureBox1.CreateGraphics)
' Assign the Bitmap object to the Graphics object
' and return it
Return Graphics.FromImage(bmap)
End Function
End Class

Using the OCX - Examples

Modifying the ShapeFile

This example uses the ModifyShape method to alter Vertice and ShapeField data for
an existing ShapeFile. In this case three polygons are created, the second polygon
represents an outer square with a donut. The DeleteVertice and DeleteShape
methods do exactly what they say. Note how the PartNo of the Vertice is used to
denote the donut. The ModifyShape command is used to write the data permanently
to the ShapeFile.

Sub ModifyShape()

Dim ModFld As ShapeField


Dim ModVert As Vertice

With ShapeFiles1

' First create a new ShapeFile that we can play with


.ReadDataOnMove = FullRead
.OpenShape "C:\Shapes\Modify.shp", shpCreate, shpPolygon

' Define some field definitions for the DBF file


Set ModFld = .ShapeFields.CreateField("TextField", shpText, 10)
Set ModFld = .ShapeFields.CreateField("NumField", shpNumeric, 5, 2)
Set ModFld = .ShapeFields.CreateField("DateField", shpDate)
.AppendFieldDefs

' Add a default set of vertices and data


Set ModVert = .Vertices.AddVertice(1, 1, 1)
Set ModVert = .Vertices.AddVertice(1, 10, 1)
Set ModVert = .Vertices.AddVertice(10, 10, 1)
Set ModVert = .Vertices.AddVertice(10, 1, 1)

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 41 of 43

Set ModVert = .Vertices.AddVertice(1, 1, 1)


.ShapeFields(1).Value = "ROSS" + Chr(189)
.ShapeFields(2).Value = 1.23
.ShapeFields(3).Value = CDate(Now)

.CreateShape
Set ModVert = .Vertices.AddVertice(10, 1, 1)
Set ModVert = .Vertices.AddVertice(10, 10, 1)
Set ModVert = .Vertices.AddVertice(20, 10, 1)
Set ModVert = .Vertices.AddVertice(20, 1, 1)
Set ModVert = .Vertices.AddVertice(10, 1, 1)
Set ModVert = .Vertices.AddVertice(14, 4, 2)
Set ModVert = .Vertices.AddVertice(14, 6, 2)
Set ModVert = .Vertices.AddVertice(16, 6, 2)
Set ModVert = .Vertices.AddVertice(16, 4, 2)
Set ModVert = .Vertices.AddVertice(14, 4, 2)
.ShapeFields(1).Value = "ROSS" + Chr(190)
.ShapeFields(2).Value = 2.34
.ShapeFields(3).Value = CDate(Now)
.CreateShape

Set ModVert = .Vertices.AddVertice(20, 1, 1)


Set ModVert = .Vertices.AddVertice(20, 10, 1)
Set ModVert = .Vertices.AddVertice(30, 10, 1)
Set ModVert = .Vertices.AddVertice(30, 1, 1)
Set ModVert = .Vertices.AddVertice(20, 1, 1)
.ShapeFields(1).Value = "ROSS" + Chr(191)
.ShapeFields(2).Value = 3.45
.ShapeFields(3).Value = CDate(Now)
.CreateShape

' Goto with the polygon withthe donut


.Moveto 2

' Change an existing coordinate value


.Vertices(7).Y_Cord = 8
.ModifyShape

' insert an extra vertice after the 7th


Set ModVert = .Vertices.AddVertice(16, 8, 2, , , , 7)
.ModifyShape

' Delete the extra vertice


.Vertices.DeleteVertice (8)
.ModifyShape

' Delete the 2nd polygon entirely


' Sets the database recordheader value to *
.DeleteShape
Debug.Print "Shape Deleted? "; .ShapeFields.isDeleted, "ShapeType of
Record is now:"; .ShapeType
' Change the data in the first field
.Moveto 1
.ShapeFields("NumField").Value = 10
.ModifyShape

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 42 of 43

' Perminantly remove the deleted records


.Pack

End With

End Sub

Using the OCX - Examples

Adding a Record To Another File

The following example shows how you can copy the vertice and database information
to another ShapeFile

Drag an instance of the ShapeFile Control from the IDE over to your Visual Basic
project to get the ShapeFiles1 instance or dimension a new instance of the DLL with the
same name. The example uses the polygon ShapeFile created in the Creating Shapes
example.

Sub CopyTo()
Dim i As Long

With ShapeFiles1

' Remove existing file of this name


If Dir("C:\Shapes\CopyTo.shp") <> vbNullString Then
Kill "C:\Shapes\CopyTo.shp"
Kill "C:\Shapes\CopyTo.shx"
Kill "C:\Shapes\CopyTo.dbf"
End If

.ReadDataOnMove = HeaderOnly
' First open an existing ShapeFile that we can play With it
.OpenShape "C:\Shapes\Polygons_base.shp", shpOpen
.MoveFirst
' When the First record is created the data structure is copied
For i = 1 To .RecordCount
.CopyTo "C:\Shapes\CopyTo.shp", i
.MoveNext
Next

' Lets test the output file


.ReadDataOnMove = HeaderOnly
.OpenShape "C:\Shapes\CopyTo.shp", shpOpen

.LoadShapeData
For i = 1 To .Vertices.Count
Debug.Print i, .Vertices(i).X_Cord, .Vertices(i).Y_Cord
Next

End With

End Sub

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019
Examples - Reading a ShapeFile Page 43 of 43

Using the OCX - Examples

Adding a Record from Another File

The following example shows how you can copy the vertice and database
information from one ShapeFile into another. It also shows you how to create the
database definition of a new ShapeFile for that of an existing file.

Drag an instance of the ShapeFile Control from the IDE over to your Visual Basic
project to get the ShapeFiles1 instance or dimension a new instance of the DLL
with the same name. The example uses the polygon ShapeFile created in the
Creating Shapes example.

Sub CopyFrom()
Dim i As Long

' Example 1: Creating a file entirely from another


With ShapeFiles1
.ReadDataOnMove = HeaderOnly
' First create a new ShapeFile that we can play with
.OpenShape "C:\Shapes\CopyFrom.shp", shpCreate, shpPolygon
' Create a database based on an existing file
.CreateFieldDefsFrom "C:\Shapes\Polygons_base.shp"

' Copy the records from another file


For i = 1 To 3
.CopyFrom "C:\Shapes\Polygons_base.shp", i
.MoveNext
Next
End With

' Example 2: Create a file with one data field in common


With ShapeFiles1
.ReadDataOnMove = HeaderOnly
' First create a new ShapeFile that we can play with
.OpenShape "C:\Shapes\CopyFrom2.shp", shpCreate, shpPolygon
' Create a new database structure different from the input file
' but with one field name the same
Set NewFld = .ShapeFields.CreateField("NumField", shpNumeric, 12,
3)
.AppendFieldDefs

' Copy the records from another file


For i = 1 To 3
.CopyFrom "C:\Shapes\Polygons_base.shp", i
.MoveNext
Next
End With

End Sub

file:///C:/Users/MLIGO/AppData/Local/Temp/~hh9CF.htm 4/26/2019

S-ar putea să vă placă și