ThinkGeo.com    |     Documentation    |     Premium Support

DatabaseColumns in edition 3

According to the example on: gis.thinkgeo.com/Support/Dis...fault.aspx , Dim Columns As New DatabaseColumns

Dim Column1 As DatabaseColumn

Is "DatabaseColumns" still in edition 3?  If so, under which class, otherwise what is the replacement and can you give us a full example of how to create a shape file with polygons from scratch please.



Alta,


Here it is:


 



    Private Sub CreateAPolygonShapeFile(ByVal filePath As String)

        ' Create a dbf columns
        Dim dbfColumns As New Collection(Of DbfColumn)
        dbfColumns.Add(New DbfColumn("POLYID", DbfColumnType.String, 10, 0))
        dbfColumns.Add(New DbfColumn("NAME", DbfColumnType.String, 10, 0))
        ' Create a shape file
        ShapeFileFeatureLayer.CreateShapeFile(ShapeFileType.Polygon, filePath, dbfColumns)

        'Create a feature
        Dim columnData As New Dictionary(Of String, String)
        columnData.Add("POLYID", "1")
        columnData.Add("Name", "My Poly")
        Dim feature As New Feature("POLYGON((0 0, 10 10, 10 0, 0 0))", "Feature1", columnData)

        'Add the feature to layer
        Dim layer As New ShapeFileFeatureLayer(filePath, ShapeFileReadWriteMode.ReadWrite)
        layer.Open()
        layer.FeatureSource.BeginTransaction()
        layer.FeatureSource.AddFeature(feature)
        layer.FeatureSource.CommitTransaction()
        layer.close

    End Sub

The Result shape file:




Ben

Excellent, thanks

Always my pleasure, let us know if we could make your coding easier.

Is this written in VB2008 and is it a pre-requisite for MapSuite edition 3? 
 I get an error on Dim dbfColumns As New Collection(Of DbfColumn): ‘Microsoft.VisualBasic.Collection’ has no type parameters and so cannot have type arguments. 
 My work around: 
 Dim column2 As New MapSuite.Core.DbfColumn(“X1”, DbfColumnType.String, 16, 0) 
 Dim column3 As New MapSuite.Core.DbfColumn(“Y1”, DbfColumnType.String, 16, 0) 
 MapSuite.Core.ShapeFileFeatureSource.CreateShapeFile(ShapeFileType.Polygon, _ 
                                                                  DATA_DIR & ZONE_SHP_FILE, _ 
                                                                  New DbfColumn() {column1, column2}) 
  
 What is the difference between: ShapeFileFeatureSource and ShapeFileFeatureLayer 
  



 Alta, 
  
 Please add the following imports to your code. 
   
 Imports System.Collections.ObjectModel 
  
 The generic Collection (of Type) we are using is within this namespace, there is another one (not Generic) in Microsoft.VisualBasic namespace. That’s why you got that error. 
  
 To draw a map on the screen, 2 things are vital. One is the data, means what to draw; the other is the style, means how to draw. FeatureSource represents the data and FeatureLayer includes both data and style. So you can say featureSource is the data part of FeatureLayer. 
  
 You might see some data related methods also in FeatureLayer. That’s to make users easier to use, instead of calling layer.FeatureSource every time, people can call the method directly from a layer level.  
  
 Ben