Bookmark this page: Add help on ArcGIS Macro processing to Yahoo MyWeb Add help on ArcGIS Macro processing to Google Bookmarks Add help on ArcGIS Macro processing to Windows Live Add help on ArcGIS Macro processing to Del.icio.us Digg help on ArcGIS Macro processing! Add help on ArcGIS Macro processing to Netscape
  •  
  • Subject
  • Author
  • Date
If you were  Registered and logged in, you could reply and use other advanced thread options
Posted by Jianhua Guo on January 5, 2006, 12:54 pm
Hello all,

Thanks in advance on the following problem in ArcGIS macro processing.
I have several shape files added and displayed in ArcMap. I want to process
(read, query, join, etc.) the attributes tables for these shape files
(layers) in macro VBA. I just wonder how to do that?

Any advice and/or information on macro programming is deeply appreciated.

Thanks.
Jianhua Guo



Posted by mgilligan on January 5, 2006, 3:44 pm
The ArcObjects Developer Help has great samples.

Start > Programs > ArcGIS > ArcObjects Developer Help

Note: During install of software, you must install "Complete" version,
rather than "Typical" to install developer help.

Hope this helps
-Mike


Posted by Raistlin on January 9, 2006, 11:21 am
In the help files lookup the following interfaces:

IFeatureCursor - read
IQueryFilter/ISpatialFilter - query
IMemoryRelationshipClassFactory - join


below is code for joining a table to a feature class

Private Sub ICommand_OnClick()
On Error GoTo EH

Dim pDoc As IMxDocument
Dim pMap As IMap
Set pDoc = m_pApp.Document
Set pMap = pDoc.FocusMap

' Get the first layer in the table on contents
Dim pFeatLayer As IFeatureLayer
Dim pDispTable As IDisplayTable
Dim pFCLayer As IFeatureClass
Dim pTLayer As ITable
If pMap.LayerCount = 0 Then
MsgBox "Must have at least one layer"
Exit Sub
End If
Set pFeatLayer = pMap.Layer(0)
Set pDispTable = pFeatLayer
Set pFCLayer = pDispTable.DisplayTable
Set pTLayer = pFCLayer

' Get the first table in the table on contents
Dim pTabCollection As IStandaloneTableCollection
Dim pStTable As IStandaloneTable
Dim pDispTable2 As IDisplayTable
Dim pTTable As ITable
Set pTabCollection = pMap
If pTabCollection.StandaloneTableCount = 0 Then
MsgBox "Must have atleast one table"
Exit Sub
End If
Set pStTable = pTabCollection.StandaloneTable(0)
Set pDispTable2 = pStTable
Set pTTable = pDispTable2.DisplayTable

' Prompt for the join field, in this example both joined
' fields must be named the same.
Dim strJnField As String
strJnField = InputBox("Provide the name of the join field:", "Joining
a table to a layer", _
"FIPS_CODE")

' Create virtual relate
Dim pMemRelFact As IMemoryRelationshipClassFactory
Dim pRelClass As IRelationshipClass
Set pMemRelFact = New MemoryRelationshipClassFactory
Set pRelClass = pMemRelFact.Open("TabletoLayer", pTTable, strJnField,
pTLayer, _
strJnField, "forward", "backward", esriRelCardinalityOneToMany)

' use Relate to perform a join
Dim pDispRC As IDisplayRelationshipClass
Set pDispRC = pFeatLayer
pDispRC.DisplayRelationshipClass pRelClass, esriLeftOuterJoin

Exit Sub

below is some code to do a spatial search and count the objects

Dim pSpatialFilter As ISpatialFilter
Set pSpatialFilter = New SpatialFilter


With pSpatialFilter
Set .Geometry = pResultGeometry
Set
.OutputSpatialReference(pFeatureLayer.FeatureClass.ShapeFieldName) =
pResultGeometry.SpatialReference
.GeometryField = pFeatureLayer.FeatureClass.ShapeFieldName
.SpatialRel = esriSpatialRelContains

End With

Set pFeatureCursor = pFeatureLayer.Search(pSpatialFilter, False)


Dim pFeature As IFeature

Set pFeature = pFeatureCursor.NextFeature
Do While Not pFeature Is Nothing
lCount = lCount + 1
Set pFeature = pFeatureCursor.NextFeature
Loop


Hope this helps!!!

Raistlin