chengiskhan
路人甲
路人甲
  • 注册日期2005-06-20
  • 发帖数3
  • QQ
  • 铜币124枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1097回复:1

在AO中将数据库中数据库的表附加到SHAPE文件上?

楼主#
更多 发布于:2006-08-03 17:41
<P>小弟想在AO中将SQL SERVER中的表通过某个关键字附加到SHAPE 文件上,然后用附加的数据生成专题图,可以arcobject online上转了几天也没查到。请各位高手指点一下,谢谢了!!!</P>
喜欢0 评分0
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15951
  • QQ
  • 铜币25345枚
  • 威望15368点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
1楼#
发布于:2006-08-04 10:42
<P>利用关联功能来实现,代码如下,可以参考</P>
<P>Public Sub RelateTabletoLayer(strLayerNametoRelate As String, strTabletoRelate As String)<BR>'************************************************************************<BR>'The procedure relates the "res_" table to corresponding "loc_" table.<BR>'************************************************************************<BR>    On Error GoTo EH<BR>    Dim pDoc As IMxDocument<BR>    Dim pMap As IMap<BR>    Set pDoc = ThisDocument<BR>    Set pMap = pDoc.FocusMap<BR>    Dim pFeatLayer As IFeatureLayer<BR>    Dim pDispTable As IDisplayTable<BR>    Dim pFCLayer As IFeatureClass<BR>    Dim pTLayer As ITable<BR>    If pMap.LayerCount = 0 Then<BR>        MsgBox "Must have at least one layer"<BR>        Exit Sub<BR>    End If<BR>    <BR>    Dim pLayers As IEnumLayer<BR>    Dim pl As ILayer<BR>    Set pLayers = pMap.Layers<BR>    Set pl = pLayers.Next<BR>    While Not pl Is Nothing<BR>        If UCase(pl.Name) = UCase(strLayerNametoRelate) Then<BR>            Set pFeatLayer = pl<BR>        End If<BR>        Set pl = pLayers.Next<BR>    Wend<BR>    Set pDispTable = pFeatLayer<BR>    Set pFCLayer = pDispTable.DisplayTable<BR>    Set pTLayer = pFCLayer<BR><BR>    Dim pTabCollection As IStandaloneTableCollection<BR>    Dim pStTable As IStandaloneTable<BR>    Dim pDispTable2 As IDisplayTable<BR>    Dim pTTable As ITable<BR>    Dim i As Integer<BR>    Set pTabCollection = pMap<BR>    If pTabCollection.StandaloneTableCount = 0 Then<BR>        MsgBox "Must have atleast one table"<BR>        Exit Sub<BR>    End If<BR>    If InStr(1, strTabletoRelate, ".") Then<BR>        strTabletoRelate = Mid(strTabletoRelate, 1, InStr(1, strTabletoRelate, ".") - 1)<BR>    End If<BR>    For i = 0 To pTabCollection.StandaloneTableCount - 1<BR>        If pTabCollection.StandaloneTable(i).Name = strTabletoRelate Then<BR>            Set pStTable = pTabCollection.StandaloneTable(i)<BR>            Set pDispTable2 = pStTable<BR>            Set pTTable = pDispTable2.DisplayTable<BR>            Exit For<BR>        End If<BR>    Next<BR><BR>    Dim strJnField As String<BR>    strJnField = "LOCID"<BR><BR>'   Create virtual relate<BR><BR>    Dim pMemRelFact As IMemoryRelationshipClassFactory<BR>    Dim pRelClass As IRelationshipClass<BR>    Set pMemRelFact = New MemoryRelationshipClassFactory<BR>    Set pRelClass = pMemRelFact.Open("TabletoLayer", pTLayer, strJnField, pTTable, _<BR>    strJnField, "forward", "backward", esriRelCardinalityOneToMany)<BR>    <BR>    ' Add it to the relates for the feature layer in Map<BR>    Dim pRelClassCollEdit As IRelationshipClassCollectionEdit<BR><BR>    Set pRelClassCollEdit = pFeatLayer<BR>    pRelClassCollEdit.AddRelationshipClass pRelClass<BR>    '*************************************************<BR>    '* To Show the related records uncomment this line<BR>    '*************************************************<BR>    ' showRelation pRelClass, pDispTable2, strQuery<BR>    '*************************************************<BR>    pDoc.UpdateContents<BR>    pDoc.ActiveView.Refresh<BR>Exit Sub<BR>EH:<BR>  MsgBox Err.Number ; "  " ; Err.Description<BR>End Sub<BR><BR>Public Sub showRelation(pRelClass As IRelationshipClass, pTTable As IDisplayTable, <BR><BR>strWhereClause As String)<BR>'*******************************************************************************************<BR>'The procedure show the related records in the relation table depending on the selected <BR><BR>'record<BR>'*******************************************************************************************<BR>    Dim pQFilter As IQueryFilter<BR>    Set pQFilter = New QueryFilter<BR>    'pQFilter.WhereClause = "locid ='015GGR34'"<BR>    pQFilter.WhereClause = strWhereClause<BR>    Dim pFeatureClass As IFeatureClass<BR>    Dim pFCursor As IFeatureCursor<BR>    Dim pfeature As IFeature<BR>    Dim pActiveView As IActiveView<BR>    Dim pFeatcls As IFeatureClass<BR>    Dim pFeatLayer As IFeatureLayer<BR>    Dim pDoc As IMxDocument<BR>    Dim pMap As IMap<BR>    Set pDoc = ThisDocument<BR>    Set pMap = pDoc.FocusMap<BR>    Set pFeatLayer = pMap.Layer(0)<BR>    Set pFeatureClass = pFeatLayer.FeatureClass<BR>    Set pActiveView = pMap<BR>    Set pFCursor = pFeatureClass.Search(pQFilter, True)<BR>    Set pfeature = pFCursor.NextFeature<BR>    Dim pFeatureSelection As IFeatureSelection<BR>    Set pFeatureSelection = pFeatLayer<BR>    pActiveView.PartialRefresh esriViewGeoSelection, Nothing, Nothing<BR>    pFeatureSelection.SelectFeatures pQFilter, esriSelectionResultNew, False<BR>    pActiveView.PartialRefresh esriViewGeoSelection, Nothing, Nothing<BR>    Dim pDisTable As IDisplayTable<BR>    Dim pTabSelection As ITableSelection<BR>    Set pTabSelection = pTTable<BR>    pTabSelection.SelectRows pQFilter, esriSelectionResultNew, False<BR>End Sub<BR></P>
GIS麦田守望者,期待与您交流。
举报 回复(0) 喜欢(0)     评分
游客

返回顶部