ArcGis添加地图标注,爆出错误:The Geometry has no Z values
解决方法如下:
public bool AddFeature( ESRI.ArcGIS.Geometry.IGeometry geometry,System.Collections.Generic.Dictionary<string ,object> properties) { try { ESRI.ArcGIS.Geodatabase.IFeature feature = _featureLayer.FeatureClass.CreateFeature(); int index; index = feature.Fields.FindField("Shape"); IGeometryDef pGeometryDef; pGeometryDef = feature.Fields.get_Field(index).GeometryDef as IGeometryDef; if (pGeometryDef.HasZ) { IZAware pZAware = (IZAware)geometry; pZAware.ZAware = true; //IZ iz1 = (IZ)geometry; //iz1.SetConstantZ(0); //将Z值设置为0 IPoint point = (IPoint)geometry; point.Z = 0; } else { IZAware pZAware = (IZAware)geometry; pZAware.ZAware = false; } if (pGeometryDef.HasM) { IMAware pMAware = (IMAware)geometry; pMAware.MAware = true; } else { IMAware pMAware = (IMAware)geometry; pMAware.MAware = false; } feature.Shape = geometry; foreach (string key in properties.Keys) { SetFeatueProperty(feature, key, properties[key]); } feature.Store(); return true; } catch (Exception ee) { return false; } }