在workspace中新建了一个场景,成功。然后使用
currentScene.getLayers().add(dataset, layer3DSettingVector, true);
添加数据到里面,保存之后,场景是新建出来了,但是场景中没有数据
Workspace m_workspace = new Workspace();
DatasourceConnectionInfo info = new DatasourceConnectionInfo();
info.setEngineType(EngineType.UDBX);
info.setServer(path);
Datasource ds = m_workspace.getDatasources().open(info);
Datasets datasets = ds.getDatasets();
// 另存工作空间
String file_saveAs = "D:\\work\\项目\\天府智慧管廊\\workSpace_test.sxwu";
Scene sceneObject1 = new Scene(m_workspace);
m_workspace.save();
Scene currentScene = new Scene();
currentScene.setWorkspace(m_workspace);
//返回三维图层集合对象
Layer3Ds layer3Ds = currentScene.getLayers();
//构造三维矢量图层设置对象并进行设置
//向三维图层集合中添加数据集类型的三维图层
// layer3Ds.clear();
for (int i = 0; i < datasets.getCount(); i++) {
String name = datasets.get(i).getName();
Dataset dataset = ds.getDatasets().get(name);
Layer3DSettingVector layer3DSettingVector = new Layer3DSettingVector();
GeoStyle3D style = new GeoStyle3D();
style.setFillForeColor(Color.PINK);
layer3DSettingVector.setStyle(style);
currentScene.getLayers().add(dataset, layer3DSettingVector, true);
layer3Ds.add(dataset, layer3DSettingVector, true);
Layer3DDataset layer3DDataset = layer3Ds.insert(i, dataset,
layer3DSettingVector,name);
layer3DDataset.updateData();
}
currentScene.refresh();
//
// // 返回三维场景的XML形式的描述
String descriptionScene = currentScene.toXML();
// m_workspace.getScenes().add("test",descriptionScene);
// 保存工作空间
m_workspace.getScenes().add("tet",descriptionScene);
m_workspace.save();
// 另存工作空间
WorkspaceConnectionInfo workspaceConnectionInfo_saveAs = new
WorkspaceConnectionInfo(file_saveAs);
if (m_workspace.saveAs(workspaceConnectionInfo_saveAs)) {
System.out.println("另存工作空间成功!");
}
// 释放资源
m_workspace.save();
currentScene.dispose();
info.dispose();
workspaceConnectionInfo_saveAs.dispose();
m_workspace.close();
m_workspace.dispose();