/// <summary> /// 绘制小柱状 /// </summary> /// <param name="datasources">各地质层厚度(0.83,0.3,1.2,200)最后一个值为底板标高</param> /// <param name="pt">小柱状中心点</param> /// <param name="Angle">旋转角度</param> /// <param name="bili">比例</param> /// <param name="bid">BID</param> /// <param name="edit">函数外控制编辑状态为false,函数内自动控制编辑状态为true,当批量绘图时建议函数外控制编辑状态</param> public static bool drawXZZ(List <KeyValuePair <int, double> > datasources, IPoint pt, double Angle, string bid, double bili = 1, bool edit = true) { double angle = -Angle; Angle = -Angle * Math.PI / 180; DrawXZZMap draw = new DrawXZZMap(bili); var AnnoLayer = DataEditCommon.GetLayerByName(DataEditCommon.g_pMap, LayerNames.LAYER_ALIAS_MR_AnnotationXZZ) as IFeatureLayer; //注记图层 var lineLayer = DataEditCommon.GetLayerByName(DataEditCommon.g_pMap, LayerNames.LAYER_ALIAS_MR_PolylineXZZ) as IFeatureLayer; //线源图层 var topLayer = DataEditCommon.GetLayerByName(DataEditCommon.g_pMap, LayerNames.LAYER_ALIAS_MR_PolygonXZZ) as IFeatureLayer; //外部图形图层 if (AnnoLayer == null || lineLayer == null || topLayer == null) { System.Windows.Forms.MessageBox.Show("小柱状图层缺失!"); return(false); } IWorkspaceEdit workspaceEdit = null; if (edit) { var dataset = lineLayer.FeatureClass as IDataset; workspaceEdit = dataset.Workspace as IWorkspaceEdit; workspaceEdit.StartEditing(true); workspaceEdit.StartEditOperation(); } try { // 准备添加数据 var polygonTopCursor = topLayer.FeatureClass.Insert(true); var polylineCursor = lineLayer.FeatureClass.Insert(true); var AnnoCursor = AnnoLayer.FeatureClass.Insert(true); // 从数据源图层获得数据 var num1 = datasources[datasources.Count - 1].Value; // 最后一条横线数值 datasources.RemoveAt(datasources.Count - 1); if (datasources.Count > 1) { List <IPoint> txtPoints; List <IPoint> lineStartPoints; var polygons = new List <KeyValuePair <string, IPolygon> >(); // 构造图形 draw.ContructGeometry(pt, datasources, out polygons, out lineStartPoints, out txtPoints); ITransform2D pTrans2D; // 生成方框图形 foreach (var polygon in polygons) { var feature2 = topLayer.FeatureClass.CreateFeatureBuffer(); feature2.set_Value(feature2.Fields.FindField("BID"), bid); if (polygon.Key == "top") { feature2.set_Value(feature2.Fields.FindField("type"), 0); } else if (polygon.Key == "white") { feature2.set_Value(feature2.Fields.FindField("type"), 1); } else if (polygon.Key == "black") { feature2.set_Value(feature2.Fields.FindField("type"), 2); } pTrans2D = polygon.Value as ITransform2D; //旋转要素 pTrans2D.Rotate(pt, Angle); IPolygon ppp = pTrans2D as IPolygon; GIS.Common.DataEditCommon.ZMValue(feature2, ppp); feature2.Shape = ppp; polygonTopCursor.InsertFeature(feature2); } // 生成注记 var enveloplist = new List <IEnvelope>(); for (int i = 0; i < txtPoints.Count; i++) { var featureAnno = AnnoLayer.FeatureClass.CreateFeatureBuffer(); IAnnotationFeature AnnoFeature = (IAnnotationFeature)featureAnno; pTrans2D = txtPoints[i] as ITransform2D; //旋转要素 pTrans2D.Rotate(pt, Angle); ITextSymbol pTextSymbol = new TextSymbolClass(); pTextSymbol.Angle = angle; var elementTxt = new TextElementClass { Geometry = pTrans2D as IGeometry, FontName = "微软雅黑", Size = 12 * bili, SymbolID = 0, Symbol = pTextSymbol }; if (i == txtPoints.Count - 1) { elementTxt.Text = num1.ToString(); // 最后一条横线的数值 elementTxt.VerticalAlignment = esriTextVerticalAlignment.esriTVATop; // 显示在线下边 featureAnno.set_Value(featureAnno.Fields.FindField("strType"), 2); } else { elementTxt.Text = datasources[i].Value.ToString(); elementTxt.VerticalAlignment = esriTextVerticalAlignment.esriTVABottom; featureAnno.set_Value(featureAnno.Fields.FindField("strType"), datasources[i].Key); } AnnoFeature.Annotation = elementTxt; featureAnno.set_Value(featureAnno.Fields.FindField("strAngle"), -angle); featureAnno.set_Value(featureAnno.Fields.FindField("strX"), pt.X); featureAnno.set_Value(featureAnno.Fields.FindField("strY"), pt.Y); featureAnno.set_Value(featureAnno.Fields.FindField("strScale"), bili); featureAnno.set_Value(featureAnno.Fields.FindField("strIndex"), i + 1); featureAnno.set_Value(featureAnno.Fields.FindField("BID"), bid); pTrans2D = featureAnno.Shape as ITransform2D; pTrans2D.Rotate(pt, -Angle); enveloplist.Add(((IGeometry)pTrans2D).Envelope); AnnoCursor.InsertFeature(featureAnno); } // 生成线 var polyline = new PolylineClass(); for (int i = 0; i < enveloplist.Count; i++) { // 计算注记的终点 IPoint toPoint = new PointClass(); if (i % 2 == 0) { toPoint.X = enveloplist[i].XMax; } else { toPoint.X = enveloplist[i].XMin; } toPoint.Y = lineStartPoints[i].Y; var line = new PathClass { FromPoint = lineStartPoints[i], ToPoint = toPoint }; polyline.AddGeometry(line); } var featureLine = lineLayer.FeatureClass.CreateFeatureBuffer(); pTrans2D = polyline as ITransform2D; pTrans2D.Rotate(pt, Angle); IPolyline mline = pTrans2D as IPolyline; GIS.Common.DataEditCommon.ZMValue(featureLine, mline); featureLine.Shape = mline; featureLine.set_Value(featureLine.Fields.FindField("BID"), bid); polylineCursor.InsertFeature(featureLine); } AnnoCursor.Flush(); polygonTopCursor.Flush(); polylineCursor.Flush(); if (edit) { workspaceEdit.StopEditOperation(); workspaceEdit.StopEditing(true); DataEditCommon.g_pMyMapCtrl.ActiveView.Refresh(); } return(true); } catch (Exception ex) { if (edit) { workspaceEdit.AbortEditOperation(); workspaceEdit.StopEditing(false); } System.Windows.Forms.MessageBox.Show(ex.Message); return(false); } }
/// <summary> /// 绘制小柱状 /// </summary> /// <params name="datasources">各地质层厚度(0.83,0.3,1.2,200)最后一个值为底板标高</params> /// <param name="pt">小柱状中心点</params> /// <params name="Angle">旋转角度</params> /// <params name="bili">比例</params> /// <params name="bid">BID</params> /// <params name="edit">函数外控制编辑状态为false,函数内自动控制编辑状态为true,当批量绘图时建议函数外控制编辑状态</params> public static bool drawXZZ(List<KeyValuePair<int, double>> datasources, IPoint pt,double Angle, string bid, double bili = 1, bool edit = true) { double angle = -Angle; Angle = -Angle * Math.PI / 180; DrawXZZMap draw = new DrawXZZMap(bili); var AnnoLayer = DataEditCommon.GetLayerByName(DataEditCommon.g_pMap, LayerNames.LAYER_ALIAS_MR_AnnotationXZZ) as IFeatureLayer;//注记图层 var lineLayer = DataEditCommon.GetLayerByName(DataEditCommon.g_pMap, LayerNames.LAYER_ALIAS_MR_PolylineXZZ) as IFeatureLayer;//线源图层 var topLayer = DataEditCommon.GetLayerByName(DataEditCommon.g_pMap, LayerNames.LAYER_ALIAS_MR_PolygonXZZ) as IFeatureLayer; //外部图形图层 if (AnnoLayer == null || lineLayer == null || topLayer == null) { System.Windows.Forms.MessageBox.Show("小柱状图层缺失!"); return false; } IWorkspaceEdit workspaceEdit=null; if (edit) { var dataset = lineLayer.FeatureClass as IDataset; workspaceEdit = dataset.Workspace as IWorkspaceEdit; workspaceEdit.StartEditing(true); workspaceEdit.StartEditOperation(); } try { // 准备添加数据 var polygonTopCursor = topLayer.FeatureClass.Insert(true); var polylineCursor = lineLayer.FeatureClass.Insert(true); var AnnoCursor = AnnoLayer.FeatureClass.Insert(true); // 从数据源图层获得数据 var num1 = datasources[datasources.Count - 1].Value; // 最后一条横线数值 datasources.RemoveAt(datasources.Count - 1); if (datasources.Count > 1) { List<IPoint> txtPoints; List<IPoint> lineStartPoints; var polygons = new List<KeyValuePair<string, IPolygon>>(); // 构造图形 draw.ContructGeometry(pt, datasources, out polygons, out lineStartPoints, out txtPoints); ITransform2D pTrans2D; // 生成方框图形 foreach (var polygon in polygons) { var feature2 = topLayer.FeatureClass.CreateFeatureBuffer(); feature2.set_Value(feature2.Fields.FindField("BID"), bid); if (polygon.Key == "top") { feature2.set_Value(feature2.Fields.FindField("type"), 0); } else if (polygon.Key == "white") { feature2.set_Value(feature2.Fields.FindField("type"), 1); } else if (polygon.Key == "black") { feature2.set_Value(feature2.Fields.FindField("type"), 2); } pTrans2D = polygon.Value as ITransform2D; //旋转要素 pTrans2D.Rotate(pt, Angle); IPolygon ppp = pTrans2D as IPolygon; GIS.Common.DataEditCommon.ZMValue(feature2, ppp); feature2.Shape = ppp; polygonTopCursor.InsertFeature(feature2); } // 生成注记 var enveloplist = new List<IEnvelope>(); for (int i = 0; i < txtPoints.Count; i++) { var featureAnno = AnnoLayer.FeatureClass.CreateFeatureBuffer(); IAnnotationFeature AnnoFeature = (IAnnotationFeature)featureAnno; pTrans2D = txtPoints[i] as ITransform2D; //旋转要素 pTrans2D.Rotate(pt, Angle); ITextSymbol pTextSymbol = new TextSymbolClass(); pTextSymbol.Angle = angle; var elementTxt = new TextElementClass { Geometry = pTrans2D as IGeometry, FontName = "微软雅黑", Size = 12 * bili, SymbolID = 0, Symbol=pTextSymbol }; if (i == txtPoints.Count - 1) { elementTxt.Text = num1.ToString(); // 最后一条横线的数值 elementTxt.VerticalAlignment = esriTextVerticalAlignment.esriTVATop; // 显示在线下边 featureAnno.set_Value(featureAnno.Fields.FindField("strType"), 2); } else { elementTxt.Text = datasources[i].Value.ToString(); elementTxt.VerticalAlignment = esriTextVerticalAlignment.esriTVABottom; featureAnno.set_Value(featureAnno.Fields.FindField("strType"), datasources[i].Key); } AnnoFeature.Annotation = elementTxt; featureAnno.set_Value(featureAnno.Fields.FindField("strAngle"), -angle); featureAnno.set_Value(featureAnno.Fields.FindField("strX"), pt.X); featureAnno.set_Value(featureAnno.Fields.FindField("strY"), pt.Y); featureAnno.set_Value(featureAnno.Fields.FindField("strScale"), bili); featureAnno.set_Value(featureAnno.Fields.FindField("strIndex"), i+1); featureAnno.set_Value(featureAnno.Fields.FindField("BID"), bid); pTrans2D = featureAnno.Shape as ITransform2D; pTrans2D.Rotate(pt, -Angle); enveloplist.Add(((IGeometry)pTrans2D).Envelope); AnnoCursor.InsertFeature(featureAnno); } // 生成线 var polyline = new PolylineClass(); for (int i = 0; i < enveloplist.Count; i++) { // 计算注记的终点 IPoint toPoint = new PointClass(); if (i % 2 == 0) { toPoint.X = enveloplist[i].XMax; } else { toPoint.X = enveloplist[i].XMin; } toPoint.Y = lineStartPoints[i].Y; var line = new PathClass { FromPoint = lineStartPoints[i], ToPoint = toPoint }; polyline.AddGeometry(line); } var featureLine = lineLayer.FeatureClass.CreateFeatureBuffer(); pTrans2D = polyline as ITransform2D; pTrans2D.Rotate(pt, Angle); IPolyline mline = pTrans2D as IPolyline; GIS.Common.DataEditCommon.ZMValue(featureLine,mline); featureLine.Shape = mline; featureLine.set_Value(featureLine.Fields.FindField("BID"), bid); polylineCursor.InsertFeature(featureLine); } AnnoCursor.Flush(); polygonTopCursor.Flush(); polylineCursor.Flush(); if (edit) { workspaceEdit.StopEditOperation(); workspaceEdit.StopEditing(true); DataEditCommon.g_pMyMapCtrl.ActiveView.Refresh(); } return true; } catch (Exception ex) { if (edit) { workspaceEdit.AbortEditOperation(); workspaceEdit.StopEditing(false); } System.Windows.Forms.MessageBox.Show(ex.Message); return false; } }