In this topic
- Initializing a GeoDataServer object for a local geodatabase
- Initializing a GeoDataServer object for an ArcSDE geodatabase
- Initializing a GeoDataServer object for an IWorkspace
- Initializing a GeoDataServer object for an ArcGIS Server GeoData Service
- To initialize a GeoDataServer object from a personal or file geodatabase, the GeoDataServer object should first be cast to the IGeoDataServerInit interface. IGeoDataServerInit.InitFromFile can then be called, with the path of the personal or file geodatabase as a parameter, to initialize the object.
- The following code can be used to create GeoDataServer objects for a personal geodatabase, a file geodatabase, or an ArcSDE geodatabase with a local connection file:
// For example, path = "C:\arcgis\ArcTutor\DatabaseServers\buildings.mdb"
// Or, path = "C:\arcgis\ArcTutor\DatabaseServers\hazards.gdb"
static IGeoDataServer initGeoDataServerFromFile(String path)throws Exception{
// Create the GeoDataServer and cast to the the IGeoDataServerInit interface.
IGeoDataServer geoDataServer = new GeoDataServer();
IGeoDataServerInit geoDataServerInit = (IGeoDataServerInit)geoDataServer;
// Initialize the GeoDataServer and return it.
geoDataServerInit.initFromFile(path);
return geoDataServer;
}
- A GeoDataServer for an ArcSDE geodatabase can be initialized using a connection string, much in the same way a workspace can be opened using a connection string.
- If a connection file (one with a .SDE extension) exists for the geodatabase, a GeoDataServer object can be created by using the IGeoDataServerInit.InitFromFile method, as shown in the previous example.
- The following code example shows how to initialize an object using a connection string:
// For example, connectionString = "SERVER=bobmk;INSTANCE=5151;VERSION=sde.DEFAULT;USER=gdb;PASSWORD=gdb"
static IGeoDataServer initGeoDataServerFromConnectionString(String connectionString)
throws Exception{
// Create the GeoDataServer and cast to the the IGeoDataServerInit interface.
IGeoDataServer geoDataServer = new GeoDataServer();
IGeoDataServerInit geoDataServerInit = (IGeoDataServerInit)geoDataServer;
// Initialize the GeoDataServer and return it.
geoDataServerInit.initFromConnectionString(connectionString);
return geoDataServer;
}
- If an application has a reference to a workspace (through the IWorkspace interface), a GeoDataServer can be created from it, using the IGeoDataServerInit.InitWithWorkspace method.
static IGeoDataServer initGeoDataServerFromWorkspace(IWorkspace workspace)throws
Exception{
// Create the GeoDataServer and cast to the the IGeoDataServerInit interface.
IGeoDataServer geoDataServer = new GeoDataServer();
IGeoDataServerInit geoDataServerInit = (IGeoDataServerInit)geoDataServer;
// Initialize the GeoDataServer and return it.
geoDataServerInit.initWithWorkspace(workspace);
return geoDataServer;
}
- A GeoDataServer can be initialized using an ArcGIS Server GeoData Service exposed on the Internet. See the following code:
// For example, url = @"http://jerome/arcgis/services"
// serviceName = "FileGDB_GDS"
static IGeoDataServer initGeoDataServerFromInternetServer(String url, String
serviceName)throws Exception{
// Create a property set for connection properties.
IPropertySet propertySet = new PropertySet();
propertySet.setProperty("URL", url);
// Connect to the server and get an enumerator for its objects.
IAGSServerConnectionFactory agsServerConnectionFactory = new
AGSServerConnectionFactory();
IAGSServerConnection agsServerConnection = agsServerConnectionFactory.open
(propertySet, 0);
IAGSEnumServerObjectName enumServerObjectName =
agsServerConnection.getServerObjectNames();
enumServerObjectName.reset();
// Iterate through the objects to locate the geodata service.
IAGSServerObjectName serverObjectName = null;
IGeoDataServer geoDataServer = null;
while ((serverObjectName = enumServerObjectName.next()) != null){
if (serverObjectName.getName().equals(serviceName)){
IName name = (IName)serverObjectName;
geoDataServer = (IGeoDataServer)name.open();
break;
}
}
return geoDataServer;
}
- Initializing GeoDataServer objects for GeoData services exposed through a local network is similar to those exposed through the Internet, with only the connection properties changing slightly. See the following code example:
// For example, machineName = "jerome"
// serviceName = "FileGDB_GDS"
static IGeoDataServer initGeoDataServerFromNetworkServer(String machineName, String
serviceName)throws Exception{
// Create a property set for connection properties.
IPropertySet propertySet = new PropertySet();
propertySet.setProperty("Machine", machineName);
// Connect to the server and get an enumerator for its objects.
IAGSServerConnectionFactory agsServerConnectionFactory = new
AGSServerConnectionFactory();
IAGSServerConnection agsServerConnection = agsServerConnectionFactory.open
(propertySet, 0);
IAGSEnumServerObjectName enumServerObjectName =
agsServerConnection.getServerObjectNames();
enumServerObjectName.reset();
// Iterate through the objects to locate the geodata service.
IAGSServerObjectName serverObjectName = null;
IGeoDataServer geoDataServer = null;
while ((serverObjectName = enumServerObjectName.next()) != null){
if (serverObjectName.getName().equals(serviceName)){
IName name = (IName)serverObjectName;
geoDataServer = (IGeoDataServer)name.open();
break;
}
}
return geoDataServer;
}
Development licensing | Deployment licensing |
---|---|
ArcView | ArcView |
ArcEditor | ArcEditor |
ArcInfo | ArcInfo |