Exemplo n.º 1
0
        IFeatureLayer pFeatureLayer;//点图层
        private void menuOpenShp_Click(object sender, EventArgs e)
        {
            IWorkspaceFactory pWorkspaceFactory;
            IFeatureWorkspace pFeatureWorkspace;

            //获取当前路径和文件名
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter = "shpfile|*.shp";
            String ThiessenPolygoPath = @"C:\MyVoronoi\ThiessenPolygo.Shp";

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                strFullPath = dlg.FileName;
                if (strFullPath == "")
                {
                    return;
                }
                int Index = strFullPath.LastIndexOf("\\");
                filePath = strFullPath.Substring(0, Index);
                fileName = strFullPath.Substring(Index + 1);
                //打开工作空间并添加shp文件
                pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
                //注意此处的路径是不能带文件名的
                pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(filePath, 0);
                pFeatureLayer     = new FeatureLayerClass();
                //注意这里的文件名是不能带路径的
                pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass(fileName);
                if (pFeatureLayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPolyline)
                {
                    MessageBox.Show("shp文件不是线要素图层");
                    return;
                }
                pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName;
                axMapControl1.Map.AddLayer(pFeatureLayer);
                axMapControl1.ActiveView.Refresh();
                menuOpenShp.Enabled = false;


                InitList();

                PublicDim.ReverseMouseWheel();

                //初始化图层
                CreateDrawnLayer();
            }
        }
Exemplo n.º 2
0
        private void Drawn(int Distance)
        {
            pGra = axMapControl1.Map as IGraphicsContainer;
            pGra.DeleteAllElements();
            pAcitveView = pGra as IActiveView;
            //清空绘图
            clear();

            //分析矩形关系
            //List<IPolyline> lstAllFeature = new List<IPolyline>();
            foreach (IFeature f in lstFeature)
            {
                if (f.Shape is IPointCollection)
                {
                    IPointCollection p       = f.Shape as IPointCollection;
                    List <IPoint>    listPPP = new List <IPoint>();
                    for (int i = 0; i < p.PointCount; i++)
                    {
                        listPPP.Add(p.get_Point(i));
                    }

                    List <TuLine> listTuline = PublicDim.DrawDog(listPPP, Distance);
                    foreach (TuLine t in listTuline)
                    {
                        //g.DrawLine(pen, ((Line)linelist[i]).Begin, ((Line)linelist[i]).End);
                        ILineElement pLineEle = new LineElementClass();
                        pEle = pLineEle as IElement;
                        ILineSymbol pLineSym = new SimpleLineSymbolClass();
                        //pLineSym.Color = this.getRGBColor(0, 0, 255);
                        pLineSym.Width  = 2;
                        pLineEle.Symbol = pLineSym;
                        //pFeat = new LineClass();
                        //pFeat.Shape
                        pEle.Geometry = CreatePolyline(t);
                        pGra.AddElement(pEle, 0);
                        pAcitveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
                    }
                }
            }
            //axMapControl1.Refresh();
        }