|  Home  |  Map Suite  |  Cygnus Track
    LivePerson Chat

ThinkGeo Blog

Providing GIS and GPS tracking insight.

 Monday, February 25, 2008

Map Suite has the ability to edit existing shapefiles, but what if you want to create your own?

The code below should get you started, but if you want to explore more shapefile editing check out our EditShapeFile sample application included with the evaluation download.


Below is a very simple example of creating a point based shapefile from scratch. It adds three records and fills the value for the field “Name”.

 

C# 

Private DatabaseColumns Columns = new DatabaseColumns();

private DatabaseColumn Column1;

Column1.FieldType = FieldDataType.fdtString;
Column1.Length = 15;

Column1.DecimalLength = 0;

Column1.Name = "Name";

Columns.Add(Column1);

Map1.CreateNewShapefile(ShapeTypeEnum.Point, "C:\\thinkgeo\\temp", "Test", Columns);

Layer Layer = new Layer("C:\\thinkgeo\\temp\\test.shp", false);

Layer.BeginEdit();

int Shape1 = Layer.AddShape(new PointShape(-98, 19));

Layer.UpdateTableData(1, "Name", "Record1");

int Shape2 = Layer.AddShape(new PointShape(-97, 15));

Layer.UpdateTableData(2, "Name", "Record2");

int Shape3 = Layer.AddShape(new PointShape(-98, 20));

Layer.UpdateTableData(3, "Name", "Record3");

Layer.CommitEdit();

 

 

 

VB.NET

Dim Columns As New DatabaseColumns

Dim Column1 As DatabaseColumn

Column1.FieldType = FieldDataType.fdtString

Column1.Length = 10

Column1.DecimalLength = 0

Column1.Name = "Name"

Columns.Add(Column1)

 

Dim Column2 As DatabaseColumn

Column2.FieldType = FieldDataType.fdtDouble

Column2.Length = 5

Column2.DecimalLength = 2

Column2.Name = "Acres"

Columns.Add(Column2)

Dim strPath As String = "C:\Projects\ThinkGeo\"

Dim strName As String = "Steve"

Map1.CreateNewShapefile(ShapeTypeEnum.Polygon, strPath, strName, Columns)

 

Map1.MapUnit = MapSuite.Geometry.MapLengthUnits.DecimalDegrees

 

Dim Layer As New Layer(strPath & strName, False)

Layer.BeginEdit()

Dim Shape As New Polygon()

Dim dblacres As Double = 90.31

Dim shape1 As Integer = Layer.AddShape(Shape)

 

Layer.UpdateTableData(shape1, "Acres", dblacres.ToString)

Layer.UpdateTableData(shape1, "Name", "Record1")

Layer.CommitEdit()

Layer.BuildIndex()
Layer.BuildRecID("Recid", True)

 

Comments [0] - Trackback Posted February 25, 2008 at 5:34 PM by Ryan Desemo   #   
Topics: Map Suite Desktop | Map Suite Engine | Map Suite Web
Comments are closed.
Archive
<July 2008>
SunMonTueWedThuFriSat
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789
Statistics
Total Posts: 11
This Year: 11
This Month: 0
This Week: 0
Comments: 4
Administration
Sign In