The parameter is (or has an element that is) the wrong kind of geometry

来源:互联网 发布:淘宝网打折耐克女鞋 编辑:程序博客网 时间:2024/06/05 00:33

今天开发遇到一个问题,就是将一个 IPolygon 对象添加到另外一个 IPolygon 中,代码示例如下:

IPolygon polygon1 = new PolygonClass();IPolygon polygon2 = new PolygonClass();IGeometryCollection collection = polygon1 as IGeometryCollection;object obj = Type.Missing;collection.AddGeometry(polygon2 as IGeometry, ref obj, ref obj);

结果执行 collection.AddGeometry(polygon2 as IGeometry, ref obj, ref obj); 这个语句时出现如上异常信息,提示的意思是几何对象的类型错误,心想 IGeometryCollection 不是可以添加 IGeometry 对象吗,而 IPolygon 转换为 IGeometry 也没错的啊。经过多次尝试后才知道并不是用 AddGeometry 方法,而该使用 AddGeometryCollection 方法。调整为如下代码,测试通过。

IGeometryCollection collection = polygon1 as IGeometryCollection;collection.AddGeometryCollection(polygon2 as IGeometryCollection);


原创粉丝点击