lilleo
路人甲
路人甲
  • 注册日期2004-05-10
  • 发帖数60
  • QQ
  • 铜币302枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:2359回复:6

如何保存一个Feature到一个FeatureLayer?

楼主#
更多 发布于:2004-05-11 09:42
<P>我想这么一个功能,如下函数</P>
<P>Public Function StoreFeature(ByVal CLayer As ILayer, ByVal CFeature As Feature) As Boolean
    '传入一个Layer 和 Feature,把Feature保存在Layer中,成功返回True,否则返回False

End Function
该如何写?</P>
喜欢0 评分0
destnity
路人甲
路人甲
  • 注册日期2004-03-25
  • 发帖数341
  • QQ
  • 铜币272枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2004-05-11 10:09
<P>Dim pBuffer As IFeatureBuffer
Dim pCursor As IFeatureCursor</P><P>DIm pFC as IFeatureCLass</P><P>set PFC = Clayer.FeatureClass</P><P>Set pBuffer = pFC.CreateFeatureBuffer
Set pCursor = pFC.Insert(True)</P><P>Set pBuffer.Shape = CFeature.Shape</P><P>Dim lLoop as long</P><P>‘下面的语句可以增加相关的字段数据。</P><P>For lLoop = 0 to pBuffer.Fields.FieldCount - 1
        pBuffer.Value(lLoop) = XXXXX</P><P>Next lLoop
 pCursor.InsertFeature pBuffer</P><P>pCursor.Flush</P><P>大体思路就是这样的。具体代码要做下修改。</P>
签 名: 不能超过 250 个字符 文字将出现在您发表的文章的结尾处。
举报 回复(0) 喜欢(0)     评分
destnity
路人甲
路人甲
  • 注册日期2004-03-25
  • 发帖数341
  • QQ
  • 铜币272枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2004-05-11 10:17
<P>dim pFC as IFeatureCLass</P><P>Dim pFeature As IFeature</P><P>set pFC = Clayer.FeatureClass</P><P>Set pFeature = pFC.CreateFeature</P><P>Set pFeature.Shape = CFeature.Shape</P><P>...</P><P>方法有很多种了。</P>
签 名: 不能超过 250 个字符 文字将出现在您发表的文章的结尾处。
举报 回复(0) 喜欢(0)     评分
lilleo
路人甲
路人甲
  • 注册日期2004-05-10
  • 发帖数60
  • QQ
  • 铜币302枚
  • 威望0点
  • 贡献值0点
  • 银元0个
3楼#
发布于:2004-05-11 11:06
<P>我已经实现了,但还是要谢谢你,拓宽了思路。</P>
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15945
  • QQ554730525
  • 铜币25337枚
  • 威望15352点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
4楼#
发布于:2004-05-11 14:52
实现了,也可以给大家分享下了
举报 回复(0) 喜欢(0)     评分
lilleo
路人甲
路人甲
  • 注册日期2004-05-10
  • 发帖数60
  • QQ
  • 铜币302枚
  • 威望0点
  • 贡献值0点
  • 银元0个
5楼#
发布于:2004-05-11 16:34
<P>好的。</P><P>
Public Function StoreFeature(ByVal CLayer As ILayer, ByVal CFeature As Feature) As Boolean
    '传入一个Layer 和 Feature,把Feature保存在Layer中,成功返回True,否则返回False
    On Error GoTo ErrHandle
    Dim pGeom As IGeometry
    '添加保存Feature的代码</P><P>  If (Not CFeature Is Nothing) Then</P><P>    Dim pFeatureLayer As esriCore.IFeatureLayer
    Dim pDataset As esriCore.IDataset
    Dim pWorkspaceEdit As esriCore.IWorkspaceEdit
    Dim pLayer As esriCore.ILayer
    
    Set pGeom = CFeature</P><P>    Set pLayer = CLayer</P><P>    If (pLayer Is Nothing) Then
      Beep
      Exit Function
    End If</P><P>    If (Not TypeOf pLayer Is esriCore.IGeoFeatureLayer) Then
      Beep
      Exit Function
    End If</P><P>    Set pFeatureLayer = CLayer
    Set pDataset = pFeatureLayer.FeatureClass
    Set pWorkspaceEdit = pDataset.Workspace</P><P>    pWorkspaceEdit.StartEditOperation</P><P>    Dim pFeature As esriCore.IFeature
    Set pFeature = pFeatureLayer.FeatureClass.CreateFeature</P><P>    Dim prowSubTypes As esriCore.IRowSubtypes
    Set prowSubTypes = pFeature</P><P>    On Error GoTo ErrHandle</P><P>    Set pFeature.Shape = pGeom
    pFeature.Store
    pWorkspaceEdit.StopEditOperation</P><P>    Dim pActiveView As esriCore.IActiveView
    Set pActiveView = mapMain.ActiveView
    mapMain.Map.SelectFeature CLayer, pFeature
    If (pGeom.GeometryType = esriGeometryPoint) Then
      Dim length As Double
      length = ConvertPixelsToMapUnits(mapMain.Map, 30)</P><P>      Dim pTopo As ITopologicalOperator
      Set pTopo = pGeom</P><P>      Dim pBuffer As IGeometry
      Set pBuffer = pTopo.Buffer(length)</P><P>      pActiveView.PartialRefresh esriDPGeography, pLayer, pBuffer.Envelope
    Else
      pActiveView.PartialRefresh esriDPGeography, pLayer, pGeom.Envelope
    End If
  End If</P><P>    StoreFeature = True
    Exit Function</P><P>ErrHandle:
    StoreFeature = False
    MsgBox "错误:" ; Err.Description, vbInformation, "错误"
End Function
</P>
举报 回复(0) 喜欢(0)     评分
Renon
路人甲
路人甲
  • 注册日期2003-08-01
  • 发帖数169
  • QQ6625162
  • 铜币66枚
  • 威望0点
  • 贡献值0点
  • 银元0个
6楼#
发布于:2004-05-14 13:42
<img src="images/post/smile/dvbbs/em06.gif" />
举报 回复(0) 喜欢(0)     评分
游客

返回顶部