本人将shp文件导入到空间数据库,发生错误,一直没解决,请各位帮助。
private void IFeatureDataConverter_ConvertFeatureClass_Example(IWorkspace sourceWorkspace, IWorkspace targetWorkspace, String nameOfSourceFeatureClass, String nameOfTargetFeatureClass){
try{
//create source workspace name
IFeatureDataset pFeatureDataset=((IFeatureWorkspace) targetWorkspace).openFeatureDataset("TestArcGisFile"); //存在数据库的要素数据集;
IFeatureDatasetName pOutFeatureDSName = (IFeatureDatasetName)new FeatureDatasetName();
pOutFeatureDSName = (IFeatureDatasetName)pFeatureDataset.getFullName();
IDataset sourceWorkspaceDataset = (IDataset)sourceWorkspace;
IDataset targetWorkspaceDataset = (IDataset)targetWorkspace;
IName sourceWorkspaceDatasetName = sourceWorkspaceDataset.getFullName();
IName targetWorkspaceDatasetName = targetWorkspaceDataset.getFullName();
IWorkspaceName sourceWorkspaceName = (IWorkspaceName)sourceWorkspaceDatasetName;
sourceWorkspaceName.setWorkspaceFactoryProgID("esriDataSourcesFile.ShapefileWorkspaceFactory");
sourceWorkspaceName.setPathName(shapeFileFolder);
IWorkspaceName targetWorkspaceName = (IWorkspaceName)targetWorkspaceDatasetName;
//create source dataset name
IFeatureClassName sourceFeatureClassName = new FeatureClassName();
IDatasetName sourceDatasetName = (IDatasetName)sourceFeatureClassName;
sourceDatasetName.setWorkspaceNameByRef(sourceWorkspaceName);
sourceDatasetName.setName(nameOfSourceFeatureClass);
//create target dataset name
IFeatureClassName targetFeatureClassName = new FeatureClassName();
IDatasetName targetDatasetName = (IDatasetName)targetFeatureClassName;
targetDatasetName.setWorkspaceNameByRef(targetWorkspaceName);
targetDatasetName.setName(nameOfTargetFeatureClass);
//Open input Featureclass to get field definitions.
IName sourceName = (IName)sourceWorkspaceName;
System.out.println("sourceName.open()==="+sourceName.open());
IFeatureClass sourceFeatureClass =(IFeatureClass)sourceName.open(); ///出现异常
//Validate the field names because you are converting between different workspace types.
IFieldChecker fieldChecker = new FieldChecker();
IFields targetFeatureClassFields[] = new IFields[1];
IFields sourceFeatureClassFields = sourceFeatureClass.getFields();
IEnumFieldError[] enumFieldError = new IEnumFieldError[1];
// Most importantly set the input and validate workspaces!
fieldChecker.setInputWorkspace(sourceWorkspace);
fieldChecker.setValidateWorkspaceByRef(targetWorkspace);
fieldChecker.validate(sourceFeatureClassFields,enumFieldError,targetFeatureClassFields);
if (enumFieldError != null){
System.out.println("Errors were encountered during field validation.");
}
String shapeFieldName = sourceFeatureClass.getShapeFieldName();
int shapeFieldIndex = sourceFeatureClass.findField(shapeFieldName);
IField shapeField = sourceFeatureClassFields.getField(shapeFieldIndex);
// Get the geometry definition from the shape field and clone it.
IGeometryDef geometryDef = shapeField.getGeometryDef();
IClone geometryDefClone = (IClone)geometryDef;
IClone targetGeometryDefClone = geometryDefClone.esri_clone();
IGeometryDef targetGeometryDef = (IGeometryDef)targetGeometryDefClone;
// Cast the IGeometryDef to the IGeometryDefEdit interface.
IGeometryDefEdit targetGeometryDefEdit = (IGeometryDefEdit)
targetGeometryDef;
// Set the IGeometryDefEdit properties.
targetGeometryDefEdit.setGridCount(1);
targetGeometryDefEdit.setGridSize(0, 0.75);
IQueryFilter queryFilter = new QueryFilter();
queryFilter.setWhereClause("");
IFeatureDataConverter featureDataConverter = new FeatureDataConverter();
IEnumInvalidObject enumInvalidObject=featureDataConverter.convertFeatureClass(sourceFeatureClassName,
queryFilter, pOutFeatureDSName, targetFeatureClassName, targetGeometryDef,targetFeatureClassFields[0], "", 1000, 0);
// Check for errors.
IInvalidObjectInfo invalidObjectInfo = null;
enumInvalidObject.reset();
while ((invalidObjectInfo = enumInvalidObject.next()) != null){
System.out.println("Errors occurred for the following feature: " +invalidObjectInfo.getInvalidObjectID());
}
System.out.println("导入成功");
} catch (Exception e) {
e.printStackTrace();
System.out.println("导入失败");
}
}
错误异常为:
java.lang.ClassCastException: com.esri.arcgis.interop.NativeObjRef cannot be cast to com.esri.arcgis.geodatabase.IFeatureClass
at com.trendcom.shapeFile.ShapeFileOpration.IFeatureDataConverter_ConvertFeatureClass_Example(ShapeFileOpration.java:123)
at com.trendcom.shapeFile.ShapeFileOpration.ConvertShapeFile2GDB(ShapeFileOpration.java:51)
at com.trendcom.shapeFile.ShapeFileOpration.main(ShapeFileOpration.java:45)
分享到:
- 2009-03-30 11:08
- 浏览 1778
- 评论(0)
- 论坛回复 / 浏览 (0 / 1719)
- 查看更多
相关推荐
- 使用`IName`接口的`Open`方法打开指定的服务,并将其转换为`IMapServer`类型。 6. **获取服务信息**: - 通过`GetServerInfo`方法获取服务的信息,包括默认的地图名称等。 7. **操作图层信息**: - 通过`...
其中,`find`命令用于定位所有.mp3文件,而`mid3iconv`则是用于编码转换的工具。通过这种方式,可以确保所有音乐文件的元数据编码一致,从而避免乱码问题。 #### 步骤3:清理并重新导入媒体库 在完成编码转换后,...
IFeatureWorkspace workspace = fact.Open(propset, 0) as IFeatureWorkspace; ``` 4. **操作数据:** 打开特定的地物类,并将其添加到地图中。 - **示例代码:** ```csharp IFeatureClass fcls = workspace....
Iworkspace workspace = workspaceFactory.Open(proset, 0); ``` 如果你想要创建一个新的Shapefile工作空间,即创建一个新的文件夹来存储Shapefiles,可以按照以下流程操作: 1. 确定新工作空间的保存目录和名称。...
5. **IName.java** - 这看起来像是一个接口(Interface)的定义,名为"IName"。在Java中,接口是用来定义行为规范的,它规定了实现该接口的类必须提供哪些方法。`IName`可能表示某种命名规则或对象标识的抽象概念。 ...
例如,-type选项可以指定要查找的文件类型,-iname选项可以忽略文件名的大小写。 find命令是Linux和Unix系统中最强大和灵活的命令之一,能够根据不同的选项和参数来实现各种文件搜索和管理任务。
- **打开电话设备**: `User::LeaveIfError(phone.Open(server,info.iName));` ##### 6. **获取线路信息** - **获取第一个线路的信息**: `RPhone::TLineInfolineInfo; User::LeaveIfError(phone.GetLineInfo(0,...
**数据库索引创建**:在FoxPro中,创建名为iname的IDX索引文件,以字段name为索引关键字,需要打开数据库student,选择File菜单,新建Index,选择字段name,将其移至Index框,设置Output为IDX类型,保存为iname.idx...
- **测试转换结果**:转换完成后,应仔细检查文件内容是否正确无误,并在开发环境中运行代码验证其功能。 - **IDE设置调整**:除了手动转换文件外,还可以考虑调整开发环境(如Eclipse)的编码设置,使其在不同平台...
创建名为iname的索引文件,以字段name为索引关键字,需要打开数据库,选择"新建",在"新"对话框中选择"索引",将name字段移至索引框,设置输出格式为IDX,并保存为iname.idx。 4. **白盒测试**:白盒测试,又称结构...
Icons in Clipboard, favorites directories, uses open dialog box with preview. Hint property editor enables multi-line hint entry. Project Resource Expert for Delphi 3.0 or higher and C++Builder 3.0 ...
iObj.document.open(); iObj.document.writeln('<html><head>'); iObj.document.writeln('<style>body'); ``` 这种方式允许开发者直接修改`iframe`中的HTML结构,适用于需要动态生成复杂内容的场景。 #### 六、总结...
ESRI.ArcGIS.Geodatabase.IWorkspace inMemWork = (IWorkspace)name.Open(); // 初始化字段结构 IFields fields = new FieldsClass(); IFieldsEdit fieldsEdit = fields as IFieldsEdit; // 添加字段 for ...
mt.Open; end; ``` 在这个例子中,我们创建了一个包含 ID(整数类型)、Name(字符串类型)和 Address(字符串类型)字段的内存表,并定义了两个索引:一个基于 ID 的主键索引(iID)和一个不区分大小写的 Name ...
Set GetRasterFromSDE = pName.Open End Function ``` 这个函数创建了一个SDE工作空间名称,设置了连接信息,然后通过工作空间名称创建一个属性集,用于指定SDE栅格数据集的名称。最后,通过工作空间名称创建并打开...
IWorkspace inmemWor = (IWorkspace)name.Open(); ``` ##### 4. 在内存工作空间中创建特征类 基于定义好的属性字段和几何类型,在内存工作空间中创建特征类。 ```csharp IFeatureClass oFeatureClass = (inmemWor ...
SELECT teacher_item.ino, item.iname, teacher.tname, teacher.tsex, teacher.tage FROM teacher, item, teacher_item WHERE ... 本实验报告介绍了如何使用数据库设计方法和 Access 关系数据库管理系统设计教师...
OpenCV(Open Source Computer Vision Library)是一个开源的计算机视觉库,包含了众多图像处理和计算机视觉的算法,广泛应用于图像分析、识别、机器学习等领域。在本文中,我们将详细讲解如何基于`opencvnew.zip`...
find /var/cache/yum/x86_64/7/ -iname "*.rpm" -exec cp 6.创建依赖关系 yum provides createrepo createrepo /var/ftp/mysql57/ 7.ftp 启动 systemctl start vsftpd 1.自建yum仓库 vim /etc/yum.repos.d/mysql57....