gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15951
  • QQ
  • 铜币25345枚
  • 威望15368点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
阅读:1245回复:2

向图层里增加XY字段数值[函数代码]

楼主#
更多 发布于:2005-06-01 17:14
<P>Public Function AddXY(sPath As String, sName As String)<BR>  <BR>  ' Open the folder to contain the shapefile as a workspace<BR>  Dim pFWS As IFeatureWorkspace<BR>  Dim pWorkspaceFactory As IWorkspaceFactory<BR>  Set pWorkspaceFactory = New ShapefileWorkspaceFactory<BR>  Set pFWS = pWorkspaceFactory.OpenFromFile(sPath, 0)<BR>  <BR>  Dim pFeatClass As IFeatureClass<BR>  Set pFeatClass = pFWS.OpenFeatureClass(sName)<BR>  <BR>  If pFeatClass.ShapeType <> esriGeometryPoint Then Exit Function<BR>    <BR>  ' check to see if X, Y fields are on the class, if not add them<BR>  Dim pField As IField<BR>  Dim pFieldEdit As IFieldEdit<BR>  <BR>  <BR>  ' add the fields if they do not already exist<BR>  If pFeatClass.FindField("textX") = -1 Then<BR>    Set pField = New Field<BR>    Set pFieldEdit = pField<BR>    pFieldEdit.Name = "textX"<BR>    pFieldEdit.Type = esriFieldType.esriFieldTypeDouble<BR>    pFeatClass.AddField pFieldEdit<BR>  End If<BR>  <BR>  If pFeatClass.FindField("textY") = -1 Then<BR>    Set pField = New Field<BR>    Set pFieldEdit = pField<BR>    pFieldEdit.Name = "textY"<BR>    pFieldEdit.Type = esriFieldType.esriFieldTypeDouble<BR>    pFeatClass.AddField pFieldEdit<BR>  End If</P>
<P>  ' loop through the features and populate the new fields<BR>  Dim pFeatCursor As IFeatureCursor<BR>  Set pFeatCursor = pFeatClass.Update(Nothing, False)<BR>  Dim lXField As Long<BR>  Dim lYField As Long<BR>  <BR>  lXField = pFeatCursor.FindField("textX")<BR>  lYField = pFeatCursor.FindField("textY")<BR>  <BR>  Dim pFeature As IFeature<BR>  Dim pPoint As IPoint<BR>  <BR>  Set pFeature = pFeatCursor.NextFeature<BR>  While Not pFeature Is Nothing<BR>    Set pPoint = pFeature.Shape<BR>    pFeature.Value(lXField) = pPoint.X<BR>    pFeature.Value(lYField) = pPoint.Y<BR>    pFeatCursor.UpdateFeature pFeature<BR>    Set pFeature = pFeatCursor.NextFeature<BR>  Wend<BR>                                              <BR>End Function</P>


喜欢0 评分0
GIS麦田守望者,期待与您交流。
zhousky
论坛版主
论坛版主
  • 注册日期2003-08-01
  • 发帖数281
  • QQ
  • 铜币1027枚
  • 威望3点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2005-06-17 09:59
<img src="images/post/smile/dvbbs/em01.gif" />
不要看我噢
举报 回复(0) 喜欢(0)     评分
inzafay
路人甲
路人甲
  • 注册日期2004-08-24
  • 发帖数46
  • QQ
  • 铜币349枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2005-06-11 09:49
顶!太好了<img src="images/post/smile/dvbbs/em02.gif" /><img src="images/post/smile/dvbbs/em01.gif" /><img src="images/post/smile/dvbbs/em06.gif" /><img src="images/post/smile/dvbbs/em05.gif" />
举报 回复(0) 喜欢(0)     评分
游客

返回顶部