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 COM异常的更多相关文章

  1. CreateFeatureClass 异常,尝试读取或写入受保护的内存 Access

    在创建要素时出现如下异常,百思不得其解. 后经过多次试验,发现文件名改为其他的就可以了.自出的文件名为"第3条",后将文件名改为"A3"等,则可正常创建. 后再 ...

  2. ArcEngine开发异常:无当前记录

    使用 IFeatureWorkspace.CreateFeatureClass() 方法,出现异常:无当前记录 百度/谷歌没有找到合适的解决之道. 而是用IFeatureWorkspace.Creat ...

  3. alias导致virtualenv异常的分析和解法

    title: alias导致virtualenv异常的分析和解法 toc: true comments: true date: 2016-06-27 23:40:56 tags: [OS X, ZSH ...

  4. ASP.NET Core应用的错误处理[2]:DeveloperExceptionPageMiddleware中间件如何呈现“开发者异常页面”

    在<ASP.NET Core应用的错误处理[1]:三种呈现错误页面的方式>中,我们通过几个简单的实例演示了如何呈现一个错误页面,这些错误页面的呈现分别由三个对应的中间件来完成,接下来我们将 ...

  5. 记一次tomcat线程创建异常调优:unable to create new native thread

    测试在进行一次性能测试的时候发现并发300个请求时出现了下面的异常: HTTP Status 500 - Handler processing failed; nested exception is ...

  6. 使用JSONObject.fromObject的时候出现“There is a cycle in the hierarchy”异常 的解决办法

    在使用JSONObject.fromObject的时候,出现“There is a cycle in the hierarchy”异常.   意思是出现了死循环,也就是Model之间有循环包含关系: ...

  7. SignalR代理对象异常:Uncaught TypeError: Cannot read property 'client' of undefined 推出的结论

    异常汇总:http://www.cnblogs.com/dunitian/p/4523006.html#signalR 后台创建了一个DntHub的集线器 前台在调用的时候出现了问题(经检查是代理对象 ...

  8. [C#] C# 知识回顾 - 你真的懂异常(Exception)吗?

    你真的懂异常(Exception)吗? 目录 异常介绍 异常的特点 怎样使用异常 处理异常的 try-catch-finally 捕获异常的 Catch 块 释放资源的 Finally 块 一.异常介 ...

  9. [C#] C# 知识回顾 - 学会处理异常

    学会处理异常 你可以使用 try 块来对你觉得可能会出现异常的代码进行分区. 其中,与之关联的 catch 块可用于处理任何异常情况. 一个包含代码的 finally 块,无论 try 块中是否在运行 ...

随机推荐

  1. Python学习之字典详解

    在元组和列表中,都是通过编号进行元素的访问,但有的时候我们按名字进行数据甚至数据结构的访问,在c++中有map的概念,也就是映射,在python中也提供了内置的映射类型--字典.映射其实就是一组key ...

  2. 1.1 让CPU占用率曲线听你指挥[cpu manager]

    [本文链接] http://www.cnblogs.com/hellogiser/p/cpu-manager.html [题目] 写一个程序,让用户来决定Windows任务管理器(Task Manag ...

  3. gpart 使用笔记

    需求 将260G 的/home 分区拆成/home与/data,原/home分区上的数据不用保留,新/home为100G,剩余空间给/data gpart过程 1.df 结果: # Device   ...

  4. iOS 获得指定文件夹下的指定格式文件

    这个容易忘记,然后只能用些自己写的长代码代替了....这里做个备忘 主要用到NSFileManager的 contentsOfDirectoryAtPath:error: 和 NSArray的 pat ...

  5. 在一个JSP页面中包含另一个JSP页面的三种方式

    转载自://http://blog.163.com/neu_lxb/blog/static/179417010201121343132918/ (1)include指令          includ ...

  6. 【python】any()和all()

    any(iterable) 版本:该函数适用于2.5以上版本,兼容python3版本. 说明:如果iterable的任一元素不为0.''.False,返回True. all(iterable) 说明: ...

  7. 【wireshark】打开后显示There are no interfaces on which a capture can be done

    解决方式:用管理员方式打开wireshark即可

  8. Win10手动添加开始磁铁

    1.移动到C:\Users\spring\AppData\Roaming\Microsoft\Windows\Start Menu\Programs 2.拖拽

  9. mysql 超级管理员

    mysql> grant all privileges on *.* to 'master'@'%' identified by '3306' with grant option; Query ...

  10. 【ASP.NET MVC】个人复习整理

    1.为 Action 标注 Attribute 限制访问 public class HomeController : Controller { [HttpPost] public ActionResu ...