SDE中圖層管理學習

來源:互聯網
上載者:User

原貼地址:http://www.cnblogs.com/columbus2/archive/2007/09/14/892679.html

 

Private Sub CommandButton1_Click() '向SDE伺服器添加本地shape檔案

    If TextBox1.Text = "" Then
        MsgBox "缺少上傳檔案。", vbCritical, "警告"
        Exit Sub
    End If
     
    Dim fWor As IFeatureWorkspace
    Dim wFac As IWorkspaceFactory
    Dim fCla1 As IFeatureClass, fCla2 As IFeatureClass
    Dim proSet As IPropertySet
    Dim fCount As Integer
    Dim fea As IFeatureBuffer
    Dim geo As IGeometry
   
    Dim sFile, sName, sPath As String
    sFile = TextBox1.Text
    sPath = sFile
    sName = Right(sPath, 1)
    Do While Not (sName = "/")
        sPath = Left(sPath, Len(sPath) - 1)
        sName = Right(sPath, 1)
    Loop
    sName = Right(sFile, Len(sFile) - Len(sPath))
    sPath = Left(sPath, Len(sPath) - 1)
    Set wFac = New ShapefileWorkspaceFactory
    Set fWor = wFac.OpenFromFile(sPath, None)
    Set fCla1 = fWor.OpenFeatureClass(sName)
    fCount = fCla1.FeatureCount(Nothing)
   
    Set wFac = New SdeWorkspaceFactory
    Set proSet = New PropertySet
    proSet.SetProperty "server", "yj-gis2"
    proSet.SetProperty "instance", "5151"
    proSet.SetProperty "user", "sde"
    proSet.SetProperty "password", "sde"
    proSet.SetProperty "version", "DEFAULT"
    Set fWor = wFac.Open(proSet, 0)
    Set fCla2 = fWor.CreateFeatureClass(fCla1.AliasName, fCla1.Fields, fCla1.CLSID, fCla1.EXTCLSID, fCla1.FeatureType, fCla1.ShapeFieldName, None)
   
    Dim wEdit As IWorkspaceEdit
    Set wEdit = fWor
    wEdit.StartEditing True
    wEdit.StartEditOperation
   
    For i = 0 To fCount - 1
        Set fea = fCla2.CreateFeatureBuffer
        Set geo = fCla1.GetFeature(i).ShapeCopy
        Set fea.Shape = geo
        Dim fdCount As Integer
        fdCount = fCla1.Fields.FieldCount
        For j = 0 To fdCount - 1
            fea.Value(j) = fCla1.GetFeature(i).Value(j)
        Next j
        fCla2.Insert(True).InsertFeature (fea)
    Next i
   
    wEdit.StopEditOperation
    wEdit.StopEditing True
       
   
    MsgBox "添加成功。", vbInformation, "提示"

End Sub

Private Sub CommandButton2_Click() '將SDE伺服器上的圖層刪除

    Dim fName As String
    fName = ComboBox1.Text
   
    Dim fWor As IFeatureWorkspace
    Dim wFac As IWorkspaceFactory
    Dim proSet As IPropertySet
    Dim fSet As IDataset
   
    Set wFac = New SdeWorkspaceFactory
    Set proSet = New PropertySet
    proSet.SetProperty "server", "yj-gis2"
    proSet.SetProperty "instance", "5151"
    proSet.SetProperty "user", "sde"
    proSet.SetProperty "password", "sde"
    proSet.SetProperty "version", "DEFAULT"
    Set fWor = wFac.Open(proSet, None)
    Dim wor As IWorkspace
    Set wor = fWor
   
    Set fSet = fWor.OpenFeatureClass(fName)
    fSet.Delete
   
    MsgBox "刪除成功。", vbInformation, "提示"

End Sub

Private Sub CommandButton3_Click() '瀏覽本地shape檔案
    
    CommonDialog1.Filter = "Shape File|*.shp"
    CommonDialog1.FileName = ""
    CommonDialog1.ShowOpen
    If CommonDialog1.FileName <> "" Then
        TextBox1.Text = CommonDialog1.FileName
    End If
  
End Sub

Private Sub CommandButton4_Click() '在下拉式功能表中列出SDE伺服器上的圖層

    ComboBox1.Text = ""
    ComboBox1.Clear
   
    Dim fWor As IFeatureWorkspace
    Dim wFac As IWorkspaceFactory
    Dim proSet As IPropertySet
   
    Set wFac = New SdeWorkspaceFactory
    Set proSet = New PropertySet
    proSet.SetProperty "server", "yj-gis2"
    proSet.SetProperty "instance", "5151"
    proSet.SetProperty "user", "sde"
    proSet.SetProperty "password", "sde"
    proSet.SetProperty "version", "DEFAULT"
    Set fWor = wFac.Open(proSet, None)
    Dim wor As IWorkspace
    Set wor = fWor
    Dim eSet As IEnumDataset
    Set eSet = wor.Datasets(esriDTFeatureClass)
    Dim fCla As IFeatureClass
    Set fCla = eSet.Next
    While Not fCla Is Nothing
        ComboBox1.AddItem fCla.AliasName
        Set fCla = eSet.Next
    Wend
   
    MsgBox "更新成功。", vbInformation, "提示"

End Sub

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.