向图层中添加线段
向图层中添加线段和向图层中添加点是一样的,其本质都是向图层中添加一个图元,只是属于不同类型的图元。并且点和线段是可以在一个图存上共存的。代码示例如下: 复制内容到剪贴板 代码: /// /// 向图层中添加线段 /// 2008年8月6日 /// 表名 /// 图层名 /// 线段起点坐标 /// 线段终点坐标 /// public static void AddPointToLayer(string tempLayerTableName, string tempLayerName, DPoint startPoint, DPoint endPoint) { MapInfo.Mapping.Map myMap = MapInfo.Engine.Session.Current.MapFactory[MapControl1.MapAlias]; //获取图层和表 FeatureLayer workLayer = (MapInfo.Mapping.FeatureLayer)myMap.Layers[tempLayerName]; MapInfo.Data.Table tblTemp = MapInfo.Engine.Session.Current.Catalog.GetTable(tempLayerTableName); //创建线图元及其样式 FeatureGeometry pgLine = MultiCurve.CreateLine(workLayer.CoordSys, startPoint, endPoint); MapInfo.Styles.SimpleLineStyle slsLine = new MapInfo.Styles.SimpleLineStyle(new LineWidth(3, LineWidthUnit.Pixel), 2, System.Drawing.Color.OrangeRed); MapInfo.Styles.CompositeStyle csLine = new MapInfo.Styles.CompositeStyle(slsLine); MapInfo.Data.Feature ptLine = new MapInfo.Data.Feature(tblTemp.TableInfo.Columns); ptPoint.Geometry = pgLine; ptPoint.Style = csLine; //将线图元加入图层 workLayer.Table.InsertFeature(ptLine);