How to open locator workspaces


Opening locator workspaces

To open various types of locator workspaces, use LocatorManager. The following are the three main types of workspaces for locators (each type corresponds to the storage mechanism used for its locators):
The LocatorManager object retrieves LocatorWorkspace objects from the file system, a geodatabase, or from ArcGIS for Server.
  1. Open a default LocalLocatorWorkspace to get the locator styles. See the following code example:
[C#]
public void OpenDefaultLocalLocatorWorkspace()
{

    System.Object obj = Activator.CreateInstance(Type.GetTypeFromProgID(
        "esriLocation.LocatorManager"));
    ILocatorManager locatorManager = obj as ILocatorManager2;

    // Use "" as the path to direct the LocalLocatorWorkspace to the system locator.
    // style folder; i.e., ArcGIS\locators.
    ILocatorWorkspace locatorWorkspace = locatorManager.GetLocatorWorkspaceFromPath(
        "");
    ILocalLocatorWorkspace localLocatorWorkspace = (ILocalLocatorWorkspace)
        locatorWorkspace;

    //TODO: Add your code here...

}
[VB.NET]
Public Sub OpenDefaultLocalLocatorWorkspace()
    
    Dim obj As System.Object = Activator.CreateInstance(Type.GetTypeFromProgID("esriLocation.LocatorManager"))
    Dim locatorManager As ILocatorManager2 = CType(obj, ILocatorManager2)
    
    ' Use "" as the path to direct the LocalLocatorWorkspace to the system locator.
    ' style folder; i.e., ArcGIS\locators.
    Dim locatorWorkspace As ILocatorWorkspace = locatorManager.GetLocatorWorkspaceFromPath("")
    Dim localLocatorWorkspace As ILocalLocatorWorkspace = CType(locatorWorkspace, ILocalLocatorWorkspace)
    
    'TODO: Add your code here...
    
End Sub
  1. Open a LocalLocatorWorkspace. See the following code example:
[C#]
public void OpenLocatorWorkspace()
{
    System.Object obj = Activator.CreateInstance(Type.GetTypeFromProgID(
        "esriLocation.LocatorManager"));
    ILocatorManager locatorManager = obj as ILocatorManager2;
    ILocatorWorkspace locatorWorkspace = locatorManager.GetLocatorWorkspaceFromPath(
        "d:\\workspace\\arcobjects\\location");
    ILocalLocatorWorkspace localLocatorWorkspace = (ILocalLocatorWorkspace)
        locatorWorkspace;

    //TODO: Add your code here...

}
[VB.NET]
Public Sub OpenLocatorWorkspace()
    
    Dim obj As System.Object = Activator.CreateInstance(Type.GetTypeFromProgID("esriLocation.LocatorManager"))
    Dim locatorManager As ILocatorManager2 = CType(obj, ILocatorManager2)
    Dim locatorWorkspace As ILocatorWorkspace = locatorManager.GetLocatorWorkspaceFromPath("d:\workspace\arcobjects\location")
    Dim localLocatorWorkspace As ILocalLocatorWorkspace = CType(locatorWorkspace, ILocalLocatorWorkspace)
    
    'TODO: Add your code here...
    
End Sub
  1. Open a FileGDB DatabaseLocatorWorkspace. See the following code example:
[C#]
public void OpenFileGDBDatabaseLocatorWorkspace()
{
    System.Object obj = Activator.CreateInstance(Type.GetTypeFromProgID(
        "esriLocation.LocatorManager"));
    ILocatorManager locatorManager = obj as ILocatorManager2;

    obj = Activator.CreateInstance(Type.GetTypeFromProgID(
        "esriDataSourcesGDB.FileGDBWorkspaceFactory"));
    IWorkspaceFactory workspaceFactory = obj as IWorkspaceFactory;
    IWorkspace workspace = workspaceFactory.OpenFromFile(
        "D:\\workspace\\arcobjects\\location\\redlands.gdb", 0);
    ILocatorWorkspace locatorWorkspace = locatorManager.GetLocatorWorkspace
        (workspace);
    IDatabaseLocatorWorkspace databaseLocatorWorkspace = (IDatabaseLocatorWorkspace)
        locatorWorkspace;

    //TODO: Add your code here...

}
[VB.NET]
Public Sub OpenFileGDBDatabaseLocatorWorkspace()
    Dim obj As System.Object = Activator.CreateInstance(Type.GetTypeFromProgID("esriLocation.LocatorManager"))
    Dim locatorManager As ILocatorManager2 = CType(obj, ILocatorManager2)
    
    obj = Activator.CreateInstance(Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory"))
    Dim workspaceFactory As IWorkspaceFactory = CType(obj, IWorkspaceFactory)
    Dim workspace As IWorkspace = workspaceFactory.OpenFromFile("D:\workspace\arcobjects\location\redlands.gdb", 0)
    Dim locatorWorkspace As ILocatorWorkspace = locatorManager.GetLocatorWorkspace(workspace)
    Dim databaseLocatorWorkspace As IDatabaseLocatorWorkspace = CType(locatorWorkspace, IDatabaseLocatorWorkspace)
    
    'TODO: Add your code here...
    
End Sub
  1. Open a PersonalGDB DatabaseLocatorWorkspace. See the following code example:
[C#]
public void OpenPersonalGDBDatabaseLocatorWorkspace()
{
    System.Object obj = Activator.CreateInstance(Type.GetTypeFromProgID(
        "esriDataSourcesGDB.AccessWorkspaceFactory"));
    IWorkspaceFactory workspaceFactory = obj as IWorkspaceFactory;
    IWorkspace workspace = workspaceFactory.OpenFromFile(
        "D:\\workspace\\arcobjects\\location\\redlands.mdb", 0);

    obj = Activator.CreateInstance(Type.GetTypeFromProgID(
        "esriLocation.LocatorManager"));
    ILocatorManager locatorManager = obj as ILocatorManager;
    ILocatorWorkspace locatorWorkspace = locatorManager.GetLocatorWorkspace
        (workspace);
    IDatabaseLocatorWorkspace databaseLocatorWorkspace = (IDatabaseLocatorWorkspace)
        locatorWorkspace;

    //TODO: Add your code here...

}
[VB.NET]
Public Sub OpenPersonalGDBDatabaseLocatorWorkspace()
    Dim obj As System.Object = Activator.CreateInstance(Type.GetTypeFromProgID("esriDataSourcesGDB.AccessWorkspaceFactory"))
    Dim workspaceFactory As IWorkspaceFactory = CType(obj, IWorkspaceFactory)
    Dim workspace As IWorkspace = workspaceFactory.OpenFromFile("D:\workspace\arcobjects\location\redlands.mdb", 0)
    
    obj = Activator.CreateInstance(Type.GetTypeFromProgID("esriLocation.LocatorManager"))
    Dim locatorManager As ILocatorManager2 = CType(obj, ILocatorManager2)
    Dim locatorWorkspace As ILocatorWorkspace = locatorManager.GetLocatorWorkspace(workspace)
    Dim databaseLocatorWorkspace As IDatabaseLocatorWorkspace = CType(locatorWorkspace, IDatabaseLocatorWorkspace)
    
    'TODO: Add your code here...
    
End Sub
  1. Open an ArcSDE DatabaseLocatorWorkspace. See the following code example:
[C#]
public void OpenArcSDEDatabaseLocatorWorkspace()
{

    // Open an ArcSDE workspace.
    IPropertySet propertySet = new PropertySetClass();
    propertySet.SetProperty("server", "mendota");
    propertySet.SetProperty("instance", "esri_sde");
    propertySet.SetProperty("database", "arcobjects");
    propertySet.SetProperty("user", "sde");
    propertySet.SetProperty("password", "sde");
    propertySet.SetProperty("version", "SDE.Default");

    // Get the workspace.
    System.Object obj = Activator.CreateInstance(Type.GetTypeFromProgID(
        "esriDataSourcesGDB.SdeWorkspaceFactory"));
    IWorkspaceFactory2 workspaceFactory = obj as IWorkspaceFactory2;
    IWorkspace workspace = workspaceFactory.Open(connectionProperties, 0);

    // Open the database locator workspace.

    obj = Activator.CreateInstance(Type.GetTypeFromProgID(
        "esriLocation.LocatorManager"));
    ILocatorManager2 locatorManager = obj as ILocatorManager2;
    ILocatorWorkspace locatorWorkspace = locatorManager.GetLocatorWorkspace
        (workspace);
    IDatabaseLocatorWorkspace databaseLocatorWorkspace = (IDatabaseLocatorWorkspace)
        locatorWorkspace;

    //TODO: Add your code here...

}
[VB.NET]
Public Sub OpenArcSDEDatabaseLocatorWorkspace()
    
    ' Open an ArcSDE workspace.
    Dim propertySet As IPropertySet = New PropertySetClass
    
    With PropertySet
        .SetProperty("server", "mendota")
        .SetProperty("instance", "esri_sde")
        .SetProperty("database", "arcobjects")
        .SetProperty("user", "sde")
        .SetProperty("password", "sde")
        .SetProperty("version", "SDE.Default")
    End With
    
    Dim obj As System.Object = Activator.CreateInstance(Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory"))
    Dim workspaceFactory As IWorkspaceFactory2 = CType(obj, IWorkspaceFactory2)
    Dim workspace As IWorkspace = workspaceFactory.Open(connectionProperties, 0)
    
    ' Open the database locator workspace.
    obj = Activator.CreateInstance(Type.GetTypeFromProgID("esriLocation.LocatorManager"))
    Dim locatorManager As ILocatorManager2 = CType(obj, ILocatorManager2)
    Dim locatorWorkspace As ILocatorWorkspace = locatorManager.GetLocatorWorkspace(workspace)
    Dim databaseLocatorWorkspace As IDatabaseLocatorWorkspace = CType(locatorWorkspace, IDatabaseLocatorWorkspace)
    
    'TODO: Add your code here...
    
End Sub
  1. Open an AGSLocatorWorkspace. See the following code example:
[C#]
public void OpenAGSLocatorWorkspace()
{

    // Open an ArcGIS Server connection.
    IPropertySet propertySet = new PropertySetClass();
    propertySet.SetProperty("machine", "mendota");

    System.Object obj = Activator.CreateInstance(Type.GetTypeFromProgID(
        "esriGISClient.AGSServerConnectionFactory"));
    IAGSServerConnectionFactory agsServerConnectionFactory = obj as
        AGSServerConnectionFactory;
    IAGSServerConnection agsServerConnection = agsServerConnectionFactory.Open
        (propertySet, 0);

    // Get the locator workspace from the open workspace.
    obj = Activator.CreateInstance(Type.GetTypeFromProgID(
        "esriLocation.LocatorManager"));
    ILocatorManager2 locatorManager2 = obj as ILocatorManager2;
    IName name = agsServerConnection.FullName;

    IAGSServerConnectionName agsServerConnectionName = (IAGSServerConnectionName)
        name;
    ILocatorWorkspace locatorWorkspace = locatorManager2.GetAGSLocatorWorkspace
        (agsServerConnectionName);

    // Open the AGSLocatorWorkspace.
    IAGSLocatorWorkspace agsLocatorWorkspace = (IAGSLocatorWorkspace)
        locatorWorkspace;

    //TODO: Your code here...

}
[VB.NET]
Public Sub OpenAGSLocatorWorkspace()
    
    ' Open an ArcGIS Server connection.
    Dim propertySet As IPropertySet = New PropertySetClass

    propertySet.SetProperty("machine", "mendota")
        
        Dim obj As System.Object = Activator.CreateInstance(Type.GetTypeFromProgID("esriGISClient.AGSServerConnectionFactory"))
        Dim agsServerConnectionFactory As IAGSServerConnectionFactory = CType(obj, IAGSServerConnectionFactory)
        Dim agsServerConnection As IAGSServerConnection = agsServerConnectionFactory.Open(propertySet, 0)
        
        obj = Activator.CreateInstance(Type.GetTypeFromProgID("esriLocation.LocatorManager"))
        Dim locatorManager2 As ILocatorManager2 = CType(obj, ILocatorManager2)
        Dim Name As IName = agsServerConnection.FullName
        
        Dim agsServerConnectionName As IAGSServerConnectionName = CType(Name, IAGSServerConnectionName)
        Dim locatorWorkspace As ILocatorWorkspace = locatorManager2.GetAGSLocatorWorkspace(agsServerConnectionName)
        
        ' Open the AGSLocatorWorkspace
        Dim agsLocatorWorkspace As IAGSLocatorWorkspace = CType(locatorWorkspace, IAGSLocatorWorkspace)
        
        'TODO: Your code here...
        
    End Sub


See Also:

Location library overview




To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing Deployment licensing
Engine Developer Kit Engine
ArcGIS for Desktop Basic ArcGIS for Desktop Basic
ArcGIS for Desktop Standard ArcGIS for Desktop Standard
ArcGIS for Desktop Advanced ArcGIS for Desktop Advanced