C# Mapxtream---创建面

本文介绍了一种在地图信息系统中创建和自定义区域的方法。通过使用特定的API,可以实现区域的绘制,并设置不同的样式属性,如颜色和透明度。此外,还提供了一个用于管理这些区域信息的类。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/// 

        /// 创建区域
        /// 
        ///区域信息
        ///点集
        private void CreateRect(RectInfo rectinfo,List points)
        {
            try
            {
                //RectInfo 的定义请看下面
                Catalog Cat = MapInfo.Engine.Session.Current.Catalog;
                Table tblTemp = Cat.GetTable(m_RectLayerName);
                if (tblTemp == null) return;

                FeatureGeometry geometry = new MultiPolygon(this.MapCoordSys, CurveSegmentType.Linear, points.ToArray());
                CompositeStyle style = GetOpaqueStyle(OpaqueType.NoNe, Color.Red); //GetOpaqueStyle在下面也有

                Feature ftr = new Feature(tblTemp.TableInfo.Columns);
                ftr.Geometry = geometry;
                ftr.Style = style;
                ftr["Name"] = rectinfo.FeatureName; //字段一的内容
                ftr["Remark"] = rectinfo.Remark; //字段二的内容
                ftr["Type"] = rectinfo.Type; //字段二的内容

                rectinfo.FeatureKey = tblTemp.InsertFeature(ftr).ToString();
                tblTemp.TableInfo.WriteTabFile();//保存到文件

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

 

    /// 

    /// 自定义区域信息
    /// 
    public class RectInfo 
    {
        private string _FeatureKey = string.Empty;
        /// 

        /// 图元的KEY值
        /// 
        public string FeatureKey
        {
            get { return _FeatureKey; }
            set
            {
                if (_FeatureKey != value)
                {
                    _FeatureKey = value;
                }
            }
        }


        private string _FeatureName;
        /// 

        /// 图元名称
        /// 
        public string FeatureName
        {
            get { return _FeatureName; }
            set 
            {
                if (_FeatureName != value)
                {
                    _FeatureName = value;
                }
            }
        }


        private string _Type;
        /// 

        /// 类型
        /// 
        public string Type
        {
            get { return _Type; }
            set 
            {
                if (_Type != value)
                {
                    _Type = value;
                }
            }
        }

        private string _Remark;
        /// 

        /// 备注
        /// 
        public string Remark
        {
            get { return _Remark; }
            set 
            {
                if (_Remark != value)
                {
                    _Remark = value;
                }
            }
        }

        /// 

        /// 构造函数
        /// 
        public RectInfo()
        { }

        /// 

        /// 构造函数
        /// 
        /// 名称
        /// 类型
        /// 备注
        public RectInfo(string _FeatureName, string _Type, string _Remark)
        {
            FeatureName = _FeatureName;
            Type = _Type;
            Remark = _Remark;
        }
  }

 

/// 

        /// 创建style
        /// 
        /// 不透明类型:ALL全部不透明(白色实心);BORDER边界不透明(填充部分透明);NONE全透明
        /// 如果opaqueType=BORDER,此处设定边界颜色
        /// 组合style
        private CompositeStyle GetOpaqueStyle(OpaqueType opaqueType, System.Drawing.Color borderColor)
        {
            MapInfo.Styles.SimpleInterior simpleInterior;
            if (opaqueType == OpaqueType.ALL)
                simpleInterior = new MapInfo.Styles.SimpleInterior(); //缺省构造函数是白色实心
            else
                simpleInterior = new MapInfo.Styles.SimpleInterior(1); //0是线透明,1是面透明

            MapInfo.Styles.LineWidth lineWidth = new MapInfo.Styles.LineWidth(1, MapInfo.Styles.LineWidthUnit.Point);

            MapInfo.Styles.SimpleLineStyle simpleLineStyle;
            if (opaqueType == OpaqueType.ALL)
                simpleLineStyle = new MapInfo.Styles.SimpleLineStyle(lineWidth, 1, borderColor);
            else if (opaqueType == OpaqueType.BORDER)
                simpleLineStyle = new MapInfo.Styles.SimpleLineStyle(lineWidth, 2, borderColor); //2表示填充透明,即能够显示轮廓
            else
                simpleLineStyle = new MapInfo.Styles.SimpleLineStyle(lineWidth, 0); //0表示全部透明,即连轮廓都看不到

            MapInfo.Styles.AreaStyle areaStyle = new MapInfo.Styles.AreaStyle(simpleLineStyle, simpleInterior);

            MapInfo.Styles.CompositeStyle compositeStyle = new MapInfo.Styles.CompositeStyle(areaStyle, null, null, null);

            return compositeStyle;
        }

 

    /// 

    /// 区域,线路样式类型
    /// 
    public enum OpaqueType
    {
        /// 

        /// 全部不透明
        /// 
        ALL,
        /// 

        /// 边界不透明
        /// 
        BORDER,
        /// 

        /// 全透明
        /// 
        NoNe
    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值