
- help-on-ArcGIS-Macro-processing
- 01-05-2006
If you were Registered and logged in, you could reply and use other advanced thread options
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
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
The ArcObjects Developer Help has great samples.
Note: During install of software, you must install "Complete" version,
rather than "Typical" to install developer help.
Hope this helps
-Mike
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
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
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
- 2010-09-25 new ESRI ArcGis 10 Desktop, ESRI ArcPad 8.0 with SP2, ESRI MapObjects 2.2, and other new software [A-Z]
- Global Positioning System
- 2010-09-25
- 2010-09-25 new ESRI ArcGis 10 Desktop, ESRI ArcPad 8.0 with SP2, ESRI MapObjects 2.2, and other new software [A-Z]
- Satellite Navigation
- 2010-09-25
- Novice help please
- Garmin GPS
- 2011-12-15
- Help Mapsource
- Garmin GPS
- 2011-10-30



