This example uses ArcObjects to connect directly to ArcSDE and get data sets rather than using the MapServer object to get the ArcSDE layers in a Map.
Create a WorkspaceFactory object within the Server's context.
IWorkspaceFactory pWorkspaceFactory = new IWorkspaceFactoryProxy(context.createObject("esriDataSourcesGDB.SdeWorkspaceFactory"));
Create an instance of a PropertySet for an Oracle ArcSDE connection. The PropertySet acts as an array of keyed values that ArcSDE will use to collect the connection values from:
PropertySet propSet = new PropertySet(context.createObject("esrisystem.PropertySet"));
propSet.setProperty("SERVER", "tel");
propSet.setProperty("INSTANCE", "5051");
propSet.setProperty("DATABASE", "");
propSet.setProperty("USER", "map");
propSet.setProperty("PASSWORD", "map");
propSet.setProperty("VERSION", "SDE.DEFAULT");
Open the ArcSDE workspace and get a handle to it through the WorkspaceFactory, passing in the PropertySet:
IWorkspace ws = pWorkspaceFactory.open(propSet,0);
You now have a connection to the database through a Workspace object (“ws”). In this example, the feature datasets are listed out:
IEnumDataset dsenum = ws.getDatasets(esriDatasetType.esriDTFeatureDataset);
IDataset ds = dsenum.next();
while(ds != null){
System.out.println(ds.getName());
ds = dsenum.next();
}
No comments:
Post a Comment