ryx32
路人甲
路人甲
  • 注册日期2003-08-05
  • 发帖数457
  • QQ
  • 铜币4046枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:4166回复:11

一个合并图层的例子

楼主#
更多 发布于:2004-08-20 12:18
<P> 要合并的图层类型必须相同
最好字段也都相同 ,不能把同一层合并到同一层
对字段名相同的保持原来的值
 Dim frec As MapObjects2.Recordset
  Dim srec As MapObjects2.Recordset
  Dim fFld As Object
  Dim sFld As Object
  Dim mstr As New MapObjects2.Strings
  Dim mobj As Object
  If map1(0)shapeType <> map1(1).shapeType  Then
    MsgBox "图层类型不匹配!请重新选择"
    Exit Sub
  End If
  On Error GoTo errhandle</P>
<P>  Set flyr = map1(0)
  Set slyr = map1(1)
  Set frec = flyr.Records
  Set srec = slyr.Records
  If srec.Updatable = True Then '判断该层是否可编辑
     For Each fFld In frec.Fields
       For Each sFld In srec.Fields
         If fFld.Name = sFld.Name Then
           If fFld.Name <> "FeatureId" And fFld.Name <> "Shape" Then
             mstr.Add fFld.Name
           End If
         End If
       Next
     Next
     frec.MoveFirst
     Do While Not frec.EOF
       With srec
         .AddNew
         .AutoFlush = False
        Set mobj = frec.Fields("Shape").value
         Set .Fields("Shape").value = mobj
         If mstr.Count > 0 Then
          For Each sFld In srec.Fields
            If mstr.Find(sFld.Name) > -1 Then
             .Fields(sFld.Name).value = frec(sFld.Name).value
            End If
          Next
         End If
         .Update
       End With
       frec.MoveNext
    Loop
    srec.AutoFlush = True
    srec.StopEditing
    map1.Refresh
 Else
   MsgBox cmbslyr.text ; "层是只读的,请修改属性", vbOKOnly \ vbCritical
 End If</P>
喜欢0 评分0
游客

返回顶部