使用产品:iserver 11i 810
操作系统:win10 x64
数据类型: postgres
问题详细描述:iobject java导入shp文件到数据集不成功,没有提示报错,导入dwg文件就可成功
问题重现步骤: 1、导入dwg就成功
2、导入shp就失败,数据没有进入到iDesktop
package com.example.demo.test;
import com.supermap.data.*;
import com.supermap.data.conversion.*;
public class ImportShp3 {
public static void main(String[] args) {
String path = "D:\\software\\ArcGIS\\Desktop10.7\\Reference Systems\\World Time Zones.shp";
Workspace workspace = new Workspace();
DatasourceConnectionInfo info = new DatasourceConnectionInfo();
info.setEngineType(EngineType.POSTGRESQL);
info.setServer("10.1.6.160");
info.setDatabase("postgres");
info.setUser("postgres");
info.setPassword("postgres");
info.setAlias("10.1.6.160_postgres");
// 打开数据源
Datasource datasource = workspace.getDatasources().open(info);
if (datasource == null) {
System.out.println("打开数据源失败");
} else {
System.out.println("数据源打开成功!");
// Dataset datasets = datasource.open(info, "temp_shape");
// String name = datasets.getName();
//创建临时数据集
Datasets datasets = datasource.getDatasets();
boolean flag = datasets.delete("temp_shape3");
String name = datasets.getAvailableDatasetName("temp_shape3");
// 设置矢量数据集的信息
DatasetVectorInfo datasetVectorInfo = new DatasetVectorInfo();
datasetVectorInfo.setType(DatasetType.REGION);
datasetVectorInfo.setEncodeType(EncodeType.NONE);
datasetVectorInfo.setFileCache(true);
datasetVectorInfo.setName(name);
System.out.println("临时数据集的信息为:" + datasetVectorInfo.toString());
DatasetVector dv_temp = datasets.create(datasetVectorInfo);
//dv_temp.close();
//导入到指定数据源的数据集中
ImportSettingSHP importSettingSHP = new ImportSettingSHP();
importSettingSHP.setAttributeIgnored(false);
//设置当同名数据集存在时导入的模式,如果存在名字冲突,则覆盖
importSettingSHP.setImportMode(ImportMode.OVERWRITE);
//设置需要导入的数据路径信息
importSettingSHP.setSourceFilePath(path);
importSettingSHP.setImporttingAs3D(false);
importSettingSHP.setImportMode(ImportMode.NONE);
importSettingSHP.setTargetEncodeType(EncodeType.NONE);
//设置需要导入的数据编码类型,因为有中文字段,所以用ASCII编码
importSettingSHP.setSourceFileCharset(Charset.ANSI);
//设置要导入的目标数据源
importSettingSHP.setTargetDatasource(datasource);
//设置目标数据集名称
importSettingSHP.setTargetDatasetName(name);
boolean importEmptyDataset = importSettingSHP.isImportEmptyDataset();
DataImport importer = new DataImport();
importer.getImportSettings().add(importSettingSHP);
ImportResult result = importer.run();
if (result.getFailedSettings().length == 0)
{
System.out.println("导入成功!");
}
ImportSetting[] failSettings= result.getFailedSettings();
for (ImportSetting setting : failSettings) {
System.out.println(setting.getImportMode());
System.out.println(setting.getSourceFilePath());
System.out.println(setting.getTargetDatasourceConnectionInfo());
System.out.println(setting.getTargetDatasource().getDatasets());
}
// 释放资源
// datasetVectorInfo.dispose();
}
// 释放工作空间资源
info.dispose();
workspace.dispose();
}
}