[Visual Basic 6.0]
Public Sub AutomateGeocodedFeatureClass(pWorkspace As esriGeoDatabase.IWorkspace, strFeatureClassName As String, strTableName As String)
'+++ This example demonstrates how to automate a geocoded feature class so that edits to the address table are
'+++ automatically reflected in the geocoded feature class. This code presented here makes the following assumptions:
'+++ (1) A reference to the workspace containing the address table and geocoded feature class has
'+++ already been obtained.
'+++ (2) The feature class was created by geocoding the address table, and that the locator is attached
'+++ to the geocoded feature class. Use the LocatorManager object to determine if the feature class
'+++ has an attached locator.
'+++ (3) The fields containing the address information in the address table are named "Address" and "ZIP".
'+++ This example assumes that the locator used to create the geocoded feature class was a US Streets
'+++ with Zone (GDB) locator. Use the IAddressInputs interface on the locator to determine the address
'+++ field names in the address table.
'+++ (4) The geocoded feature class contains a field named "Join_OID" which is a foreign key to the ObjectID
'+++ field on the address table.
Dim pESRILicenseInfo As esriSystem.IESRILicenseInfo
Dim pFeatureWorkspace As esriGeoDatabase.IFeatureWorkspace
Dim pFeatureClass As esriGeoDatabase.IFeatureClass
Dim pTable As esriGeoDatabase.ITable
Dim strAddressFieldNames() As String
Dim pPropertySet As esriSystem.IPropertySet
Dim pSchemaLock As esriGeoDatabase.ISchemaLock
Dim pClassSchemaEdit As esriGeoDatabase.IClassSchemaEdit3
Dim pUID As New esriSystem.UID
Dim pRelationshipClass As esriGeoDatabase.IRelationshipClass2
'+++ the user must have either an ArcEditor or ArcInfo license to automate the geocoded feature class
Set pESRILicenseInfo = New esriSystem.ESRILicenseInfo
If pESRILicenseInfo.DefaultProduct = esriProductCodeViewer Then Exit Sub
'+++ only geocoded feature classes in geodatabases can be automated
If pWorkspace.Type = esriFileSystemWorkspace Then Exit Sub
'+++ get references to the geocoded feature class and address table
Set pFeatureWorkspace = pWorkspace
Set pFeatureClass = pFeatureWorkspace.OpenFeatureClass(strFeatureClassName)
Set pTable = pFeatureWorkspace.OpenTable(strTableName)
'+++ register the feature class as a GeocodedFeature custom feature class
Set pSchemaLock = pFeatureClass
pSchemaLock.ChangeSchemaLock esriExclusiveSchemaLock
Set pClassSchemaEdit = pFeatureClass
pUID.Value = "esriLocation.GeocodedFeature"
pClassSchemaEdit.AlterInstanceCLSID pUID
'+++ create the property set for the Geocoded Feature Class extension
ReDim strAddressFieldNames(0 To 1)
strAddressFieldNames(0) = "ADDRESS"
strAddressFieldNames(1) = "ZIP"
Set pPropertySet = New esriSystem.PropertySet
With pPropertySet
.SetProperty "OriginalAddressFieldNames", strAddressFieldNames
.SetProperty "UpdateOnEdit", True
.SetProperty "UnmatchOnly", False
End With
'+++ register the GeocodedFeatureClassExtension on the feature class
pUID.Value = "esriLocation.GeocodedFeatureClassExtension"
pClassSchemaEdit.AlterClassExtensionCLSID pUID, pPropertySet
'+++ create a relationship class between the address table and the geocoded feature class
Set pRelationshipClass = pFeatureWorkspace.CreateRelationshipClass("Geocoding", pTable, pFeatureClass, _
"is geocoded to", "is geocoded from", esriRelCardinalityOneToOne, esriRelNotificationForward, True, _
False, Nothing, pFeatureClass.OIDFieldName, "", "Join_OID", "")
'+++ release the schema lock on the feature class
pSchemaLock.ChangeSchemaLock esriSharedSchemaLock
End Sub