예제 #1
0
        /// <summary>
        /// 是否存在面shp
        /// </summary>
        /// <param name="lyr"></param>
        /// <returns></returns>
        private bool ShpPolygonLyrExits(ShpPolygonLayer lyr)
        {
            ShpPolygonLayerList lst = ShpPolygonConfig.ReadConfigFile();

            if (lst == null || lst.Count == 0)
            {
                return(false);
            }
            foreach (var item in lst.LayerList)
            {
                if (item.LayerName == lyr.LayerName)
                {
                    return(true);
                }
            }
            return(false);
        }
예제 #2
0
        /// <summary>
        /// 导入Shp
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void ctxImportShp_Click(object sender, EventArgs e)
        { //第一个为图层节点
            Node pnode = advTreeMain.Nodes[0];
            //List<string> existlyrs = this.GetExistLayerNames();
            frmLoadVector frm = new frmLoadVector(new List <string>());

            if (frm.ShowDialog() == DialogResult.OK)
            {
                string name = string.Empty;
                string path = string.Empty;
                switch (frm.Reader.GeoBigType)
                {
                case GeometryBigType.Point:
                    name = frm.PntLayer.LayerName;
                    //图层去重
                    NodeModel checkModel = _projectModel.Nodes.Where(t => t.PNode == Guids.TCGL && t.NodeName == name).FirstOrDefault();
                    if (checkModel != null)
                    {
                        MsgBox.ShowInfo("当前名称的图层已经存在,请重命名或者导入其他数据");
                        return;
                    }
                    path = frm.PntLayer.ShpLayerPath;
                    ShpPointLayer pntLyr = frm.PntLayer;
                    //保存图层信息到配置文件
                    if (this.ShpPointLyrExits(pntLyr))
                    {
                        ShpPointConfig.DeleteLayer(pntLyr.LayerName);
                        _shpLoader.PntLyrList.Remove(pntLyr.LayerName);
                        this.DeleteLayerByName(pntLyr.LayerName);
                    }
                    ShpPointConfig.AppendLayer(pntLyr);
                    _shpLoader.LoadShpPointLayer(pntLyr);
                    break;

                case GeometryBigType.Line:
                    this.AddShpLineLayer(frm.LineLayer);
                    name = frm.LineLayer.LayerName;
                    path = frm.LineLayer.ShpLayerPath;
                    break;

                case GeometryBigType.Polygon:
                    name = frm.PolyLayer.LayerName;
                    //图层去重
                    checkModel = _projectModel.Nodes.Where(t => t.PNode == Guids.TCGL && t.NodeName == name).FirstOrDefault();
                    if (checkModel != null)
                    {
                        MsgBox.ShowInfo("当前名称的图层已经存在,请重命名或者导入其他数据");
                        return;
                    }
                    path = frm.PolyLayer.ShpLayerPath;
                    ShpPolygonLayer polyLyr = frm.PolyLayer;
                    if (this.ShpPolygonLyrExits(polyLyr))
                    {
                        ShpPolygonConfig.DeleteLayer(polyLyr.LayerName);
                        _shpLoader.PolyLyrList.Remove(polyLyr.LayerName);
                        this.DeleteLayerByName(polyLyr.LayerName);
                    }
                    ShpPolygonConfig.AppendLayer(polyLyr);
                    _shpLoader.LoadShpPolygonLayer(polyLyr);
                    break;

                default:
                    break;
                }


                NodeModel model = new NodeModel();
                model.PNode      = pnode.Name;
                model.NodeName   = name;
                model.ShowCheck  = true;
                model.ImageIndex = 2;
                model.NodeId     = Guid.NewGuid().ToString();
                model.CanRemove  = true;
                model.Path       = path;
                model.BigType    = frm.Reader.GeoBigType;
                pnode.Nodes.Add(CreateNode(model));
            }
        }
예제 #3
0
        /// <summary>
        /// 保存矢量数据(有BUG!)
        /// </summary>
        private void SaveLayerConfig()
        {
            //保存矢量图层信息
            foreach (Node node in advTreeMain.Nodes[0].Nodes)
            {
                NodeModel model = node.Tag as NodeModel;
                if (model != null)
                {
                    //矢量文件
                    if (model.ImageIndex == 2)
                    {
                        switch (model.BigType)
                        {
                        case GeometryBigType.Line:
                            ShpLineLayerList lineList = ShpLineConfig.ReadConfigFile();
                            if (lineList != null)
                            {
                                for (int i = 0; i < lineList.Count; i++)
                                {
                                    ShpLineLayer lyr = lineList[i];
                                    if (lyr.LayerName == model.NodeName)
                                    {
                                        lyr.Visible = node.Checked;
                                        ShpLineConfig.UpdateLayer(model.NodeName, lyr);
                                        break;
                                    }
                                }
                            }
                            break;

                        case GeometryBigType.None:
                            break;

                        case GeometryBigType.Point:
                            if (_shpLoader.PntLyrList != null)
                            {
                                for (int i = 0; i < _shpLoader.PntLyrList.Count; i++)
                                {
                                    ShpPointLayer lyr = _shpLoader.PntLyrList[i];
                                    if (lyr.LayerName == model.NodeName)
                                    {
                                        lyr.Visible = node.Checked;
                                        ShpPointConfig.UpdateLayer(model.NodeName, lyr);
                                        break;
                                    }
                                }
                            }
                            break;

                        case GeometryBigType.Polygon:
                            if (_shpLoader.PolyLyrList != null)
                            {
                                for (int i = 0; i < _shpLoader.PolyLyrList.Count; i++)
                                {
                                    ShpPolygonLayer lyr = _shpLoader.PolyLyrList[i];
                                    if (lyr.LayerName == model.NodeName)
                                    {
                                        lyr.Visible = node.Checked;
                                        ShpPolygonConfig.UpdateLayer(model.NodeName, lyr);
                                        break;
                                    }
                                }
                            }
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
        }