AvisMap - Mapping Software Provider

Affordable GIS / Mapping Software Products and Solutions.

  • You are here: 
  • Mapping Software
  • Creating/Editing Datasource and Dataset (Visual Basic 6)

Creating/Editing Datasource and Dataset (Visual Basic 6)

Introduction:

This sample code mainly describes how to create datasource and dataset , edit/delete dataset and show the powerful snapping functionality of AvisMap Engine. There are two ways to create datasource in AvisWorkspace. The datasource type is decided upon what kind of data engine has been used when the datasource was created. soDataSource has three methods to create a dataset such as CreateDataset,CreateDatasetFrom and CreatECWDataset; and there are approximately 20 kinds of datasets can be managed. Here we only use six of them as a demonstration. AvisMap controls have their own simple editing modes of dataset .

Installation location:

You can find full code for this sample project in C:Program FilesAvisMapAvismap GIS Engine 5.0Sample ProjectsSample VBCreateDeleteModify

Data: the data created by users ( recommended saving it in current directory).

The main properties and methods of AvisMap GIS Engine control/object in this sample code are:

Control/Object Property Method
AvisWorkspace DataSources CreateDataSource
AvisMap Action,Layers AddDataset,ShowSnapSettingDialog
soDataSource Datasets CreateDataset,CreateMrSIDDataset,CreateECWDataset
soLayers Snapable SetEditableLayer,GetEditableLayer

Functions:

Create Datasource

According to the different types of data engines, the datasource types are different. You should check and make the datasource name is valid before creating; otherwise it will return a null object of datasource.

Dim objDS As soDataSource ‘ set datasource
Dim strDsName As String ‘ set variable for datasource name (including the full path )
strDsName = App.path & “Text.sdb”
Set objDS = Me.AvisWorkspace1.CreateDataSource(strDsName, “Text”, sceSDB, False, False, False, “”)

Create Dataset:

You should open a datasource before you create a dataset. The New Dataset dialog box below shows which datasourse the new dataset will be saved in. And you can specify a name for the new dataset and assign a type. There are six types of dataset you can choose to create.

Note: Make sure the dataset name is valid.

Dim objDt As soDataset
If objDS.IsAvailableDatasetName(txtDatasetName.Text) = False Then
MsgBox “The dataset name is invalid”, vbInformation
Exit Sub
End If
Set objDS = Form1.AvisWorkspace1.Datasources.Item(cmbDatasource.Text)
Set objDt = objDS.CreateDataset(strDatasetName, scdPoint, scoDefault)
Lines below show the other two methods to create a dataset.
Dim bResult as Boolean
bResult = objDS.CreateECWDataset(strDatasetName, cdlFile.FileName) ‘ ECW dataset
bResult = objDS.CreateMrSIDDataset(strDatasetName, cdlFile.FileName) ‘ MrSID dataset
‘ if creation succeeded, bResult = True ; failed, bResult = False .

Delete Dataset:

You should close and remove the dataset from the AvisMap control before you delete it from the datasource.
If Not (AvisMap1.Layers(strLayerName) Is Nothing) Then
AvisMap1.Layers.RemoveAt (strLayerName)
AvisMap1.Refresh
End If
Set objDS = AvisWorkspace1.Datasources(1)
objDS.DeleteDataset(strDtName)
‘ strDtName is specified as the dataset name

Snap Setting:

There are many snapping methods in AvisMap. Select the methods you need in the dialog box and accept the others as defaults.
snap setting.jpg

AvisMap1.ShowSnapSettingDialog ‘ display Snap Setting dialogue when you want to change its methods.


Dim objLayer as soLayer ‘ define a layer variable
Set objLayer = AvisMap1.Layers(cmbEditbleLayer.Text) ‘ get map layer
AvisMap1.Layers.SetEditableLayer(objLayer.Name) = True ‘ set the layer editable
AvisMap1.Layers(objLayer.Name).Snapable = True ‘ start snapping in the editable layer

Objects Editing

To set the edit mode, You only need to set the property of AvisMap.Action. After you having set the property, AvisMap will be in editing status. In this status, AvisMap will not respond to standard mouse event and you can do editing on AvisMap controls; if the datasource is opened conventionally or in encryption, the changes will be saved automatically, otherwise the datasource is opened in transaction, you need to commit the changes manually.

AvisMap1.Action = scaEditCreatePoint ‘ draw point
AvisMap1.Action = scaEditCreatePolyline ‘ draw polyline
AvisMap1.Action = scaEditCreateLinesect ‘ draw line