CreateFeatureClass COM异常
2014-02-26 10:17
211 查看
private static IFeatureClass CreatStnShp(string shp) { //打开工作空间 IWorkspaceFactory wsfactory = new ShapefileWorkspaceFactoryClass(); string ssss = System.IO.Path.GetDirectoryName(shp); IWorkspace workspace = wsfactory.OpenFromFile(ssss, 0); IFeatureWorkspace pFeatWsp = workspace as IFeatureWorkspace; if (File.Exists(shp)) { DialogResult dr = MessageBox.Show("文件已经存在,是否使用该文件?", "提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if ( dr== DialogResult.Yes) { return pFeatWsp.OpenFeatureClass(System.IO.Path.GetFileNameWithoutExtension(shp)); } else if(dr==DialogResult.No) { //删除已有 DialogResult ddr = MessageBox.Show("是否删除并替换已有文件", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (ddr == DialogResult.Yes) { string dbffile = System.IO.Path.ChangeExtension(shp, ".dbf"); string shxfile = System.IO.Path.ChangeExtension(shp, ".shx"); string prjfile = System.IO.Path.ChangeExtension(shp, ".prj"); File.Delete(shp); if (File.Exists(dbffile)) File.Delete(dbffile); if (File.Exists(shxfile)) File.Delete(shxfile); if (File.Exists(prjfile)) File.Delete(prjfile); } else { MessageBox.Show("请重新选择shapfile文件的路径"); } } else { return null; } } IGeometryDefEdit pGeoDef = new GeometryDefClass(); pGeoDef.GeometryType_2 = esriGeometryType.esriGeometryPoint; //设置空间参考 ISpatialReferenceFactory3 spatialReferenceFactory = new SpatialReferenceEnvironmentClass(); ISpatialReference pSr = spatialReferenceFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984); //设置字段 IFieldEdit pField; IFieldsEdit pFieldsEdit = new FieldsClass(); //设置几何字段 pField = new FieldClass(); pField.Type_2 = esriFieldType.esriFieldTypeGeometry; pField.GeometryDef_2 = pGeoDef; pField.Name_2 = "Shape"; pFieldsEdit.AddField(pField); //产生唯一索引字段 pField = new FieldClass(); pField.Name_2 = "OBJECTID"; pField.Type_2 = esriFieldType.esriFieldTypeOID; pFieldsEdit.AddField(pField); //添加station相关字段 //string[] str = new string[]{"NCDCID","WBAN","NAME","COOPID","COUNTRY","STNTYPE"}; string[] str = new string[] { "WBAN", "NAME", "LOCATION", "LAT", "LON"}; foreach (string stt in str) { pField = new FieldClass(); pField.Name_2 = stt; pField.AliasName_2 = stt; pField.Type_2 = esriFieldType.esriFieldTypeString; if (stt == "LOCATION") pField.Length_2 = 60; else pField.Length_2 = 30; pFieldsEdit.AddField(pField); } pField = new FieldClass(); pField.Name_2 = "StnHeight"; pField.Type_2 = esriFieldType.esriFieldTypeDouble; pFieldsEdit.AddField(pField); pField = new FieldClass(); pField.Name_2 = "GndHeight"; pField.Type_2 = esriFieldType.esriFieldTypeDouble; pFieldsEdit.AddField(pField); IFeatureClass pfeatcls =pFeatWsp.CreateFeatureClass(System.IO.Path.GetFileNameWithoutExtension(shp), pFieldsEdit as IFields, null, null, esriFeatureType.esriFTSimple, "Shape", ""); IGeoDataset pGeoDs = pfeatcls as IGeoDataset; IGeoDatasetSchemaEdit pGeoDSe = pGeoDs as IGeoDatasetSchemaEdit; if (pGeoDSe.CanAlterSpatialReference) { pGeoDSe.AlterSpatialReference(pSr); } return pfeatcls; }
上面是可正常运行的代码。自己写的时候凭着自己的理解做了部分修改,在字段声明的时候略有不同,如下
IFields pfs = new FieldsClass(); IFieldsEdit pFieldsEdit = pfs as IFieldsEdit; IField pFieldd = new FieldClass(); IFieldEdit pField = pFieldd as IFieldEdit;
结果在运行的时候出现COM异常,仔细核查了CreateFeatureClass的每个参数,多次检查都没有查到结果。后来修改为文中第一段代码声明方式,再运行成功了。
为了找出错误,我又把声明换回第二段代码,令人郁闷的是,又没异常了。
本文只描述现象,不解释原因
相关文章推荐
- CreateFeatureClass 异常,尝试读取或写入受保护的内存 Access
- java从0单排(3)-经验(java.lang.ClassNotFoundException: com.mysql.jdbc.Driver异常处理办法)
- 异常 java.lang.ClassNotFoundException com.mysql.jdbc.Driver 解决方法
- IFeatureWorkspace.CreateFeatureClass on ArcServer
- Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver异常
- 关于Use of @OneToMany or @ManyToMany targeting an unmapped class: com.xxx.domain异常
- 一个异常:Caused by: java.lang.UnsupportedClassVersionError: Bad version number in .class file (unable to load class com.rssReader.st
- 检索 COM 类工厂中 CLSID 为 {10021F00-E260-11CF-AE68-00AA004A34D5} 的组件失败,原因是出现以下错误: 80040154 没有注册类 (异常来自 HRESULT:0x80040154 (REGDB_E_CLASSNOTREG))。
- 异常信息:Exception in thread "main" java.lang.UnsupportedClassVersionError: com/mysql/jdbc/Driver
- Cannot create JDBC driver of class 'com.mysql.jdbc
- CreateMemoryFeatureClass
- 检索 COM 类工厂中 CLSID 为 {820280E0-8ADA-4582-A1D9-960A83CE8BB5} 的组件失败,原因是出现以下错误: 80040154 没有注册类 (异常来自 HRESULT:0x80040154 (REGDB_E_CLASSNOTREG))。
- 关于 Cannot create JDBC driver of class '' for connect URL 'null' 的异常
- dubbo调用服务出现如下异常Serialized class com.taotao.manager.pojo.TaoResult must implement java.io.Serializabl
- 关于AE中IFeatureWorkspace接口的CreateFeatureClass方法
- Java Web项目异常问题——java.lang.ClassNotFoundException: com.mysql.jdbc:Driver
- AE CreateFeatureClass 创建shp. 删除shp. 向shp中添加要素
- Insert Features using Ifeatureclass.createFeaturebuffer method
- Error: Failed to create feature class. Table already registered
- JavaWeb-JSP-异常:解决bug,exception message:useBean class attribute com.niit.model.Users is invalid.