from:http://dufan20086.blog.163.com/blog/static/6616452320145269343675/
我们在创建要素时,简单的IFeatureClass.CreateFeature之后,然后把IGeometry对象赋给Feature.shape,会引发“The Geometry has no Z values”的错误提示。类似的错误在做地图标注过程中也会出现。
本文所采用的解决办法参考了网上的一些资料:
http://blog.sina.com.cn/s/blog_6faf711d010138vq.html
http://hi.baidu.com/luoyuonline/item/2994bafc08e10f0dd99e7256
基本思路就是在CreateFeature之后,设置Z值(顺带将M值也一并设置)。
/// <summary>
/// 设置Z值和M值,解决The Geometry has no Z values错误
/// </summary>
/// <param name="pF">要素</param>
/// <param name="pGeo">几何</param>
public static void SetZValue(IFeature pF, IGeometry pGeo)
{
int index;
index = pF.Fields.FindField("Shape");
IGeometryDef pGeometryDef;
pGeometryDef = pF.Fields.get_Field(index).GeometryDef as IGeometryDef;
if (pGeometryDef.HasZ)
{
IZAware pZAware = (IZAware)pGeo;
pZAware.ZAware = true;
//IZ iz1 = (IZ)pGeo;
//iz1.SetConstantZ(0); //将Z值设置为0
//在ArcEngine10.2中用下面的两行代码来设置
IPoint point = (IPoint)pGeo;
point.Z = 0;
}
else
{
IZAware pZAware = (IZAware)pGeo;
pZAware.ZAware = false;
}
//M值
if (pGeometryDef.HasM)
{
IMAware pMAware = (IMAware)pGeo;
pMAware.MAware = true;
}
else
{
IMAware pMAware = (IMAware)pGeo;
pMAware.MAware = false;
}
}//function