示例#1
0
 private void textBoxXTIN_TextChanged(object sender, EventArgs e)
 {
     m_TINPath = textBoxXTIN.Text;
     try
     {
         DirectoryInfo     dir     = Directory.CreateDirectory(m_TINPath);
         IWorkspaceFactory pWSFact = new TinWorkspaceFactoryClass();
         IWorkspace        pWS     = pWSFact.OpenFromFile(dir.Parent.FullName + @"\", 0);
         ITinWorkspace     pTinWS  = pWS as ITinWorkspace;
         ITin pTin = pTinWS.OpenTin(dir.Name);
         m_pTin = pTin;
         IEnvelope pExtent    = pTin.Extent;
         double    dmaxextent = pExtent.Height;
         if (pExtent.Width > pExtent.Height)
         {
             dmaxextent = pExtent.Width;
         }
         double cellsize = dmaxextent / 250;
         doubleInputCellSize.Value = cellsize;
     }
     catch (SystemException ee)
     {
         //MessageBox.Show(ee.Message);
     }
 }
        private void 生成等高线ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //获取TIN图层
            ITinLayer pTinLayer           = axSceneControl1.Scene.get_Layer(0) as ITinLayer;
            ITin      pTin                = pTinLayer.Dataset as ITin;
            string    contourFileName     = pTinLayer.Name + "_Contour";
            string    contourFileName_shp = WorkSpaceName + @"/" + contourFileName + ".shp";

            if (System.IO.File.Exists(contourFileName_shp))
            {
                System.IO.File.Delete(contourFileName_shp);
                System.IO.File.Delete(System.IO.Path.ChangeExtension(contourFileName_shp, ".dbf"));
                System.IO.File.Delete(System.IO.Path.ChangeExtension(contourFileName_shp, ".shx"));
            }
            IFeatureClass contourFeatureClass = Create_ContourLine(pTin, WorkSpaceName, contourFileName);
            //添加等高线图层
            IFeatureLayer pFeatureLayer = new FeatureLayerClass();

            pFeatureLayer.FeatureClass = contourFeatureClass;
            IGeoFeatureLayer pGeoFeatureLayer = pFeatureLayer as IGeoFeatureLayer;

            pGeoFeatureLayer.DisplayAnnotation = true;
            pGeoFeatureLayer.DisplayField      = "Contour";
            pGeoFeatureLayer.Name = contourFileName + "_Contour";
            //设置线样式
            ILineSymbol pLineSymbol = new SimpleLineSymbolClass();

            pLineSymbol.Color = Get_RGBColor(100, 50, 30);
            pLineSymbol.Width = 2;
            ISimpleRenderer pRender = pGeoFeatureLayer.Renderer as ISimpleRenderer;

            pRender.Symbol = pLineSymbol as ISymbol;
            axMapControl1.AddLayer(pFeatureLayer as ILayer);
        }
示例#3
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add CmdAddTinLayer.OnClick implementation
            FolderBrowserDialog fdlg = new FolderBrowserDialog();

            //fdlg.SelectedPath = @"C:\Users\Administrator\Desktop\sampleAnalysis\TIN\";
            try
            {
                if (fdlg.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                //FrmFolderDialog dlg = new FrmFolderDialog();
                //dlg.DisplayDialog();
                if (fdlg.SelectedPath != "")
                {
                    // DirectoryInfo dir = Directory.CreateDirectory(dlg.Path);
                    DirectoryInfo     dir     = Directory.CreateDirectory(fdlg.SelectedPath);
                    IWorkspaceFactory pWSFact = new TinWorkspaceFactoryClass();
                    IWorkspace        pWS     = pWSFact.OpenFromFile(dir.Parent.FullName + @"\", 0);
                    ITinWorkspace     pTinWS  = pWS as ITinWorkspace;
                    ITin pTin = pTinWS.OpenTin(dir.Name);
                    //½«TIN±äΪTINͼ²ã
                    ITinLayer pTinLayer = new TinLayerClass();
                    pTinLayer.Dataset = pTin;
                    pTinLayer.Name    = dir.Name;
                    IMapControl2 pMapCtr = (((IToolbarControl)m_hookHelper.Hook).Buddy) as IMapControl2;
                    pMapCtr.Map.AddLayer((ILayer)pTinLayer);
                }
            }
            catch (SystemException ee)
            {
                MessageBox.Show(ee.Message);
            }
        }
示例#4
0
 private void comboBoxToraster_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (comboBoxToraster.Items.Count > 0)
     {
         toraster_Name = comboBoxToraster.SelectedItem.ToString();
         ;
         ILayer     pLayer = GetLayerByName(ref fortraster_Name);
         IWorkspace pSourceWorkspace;
         if (pLayer is IRasterLayer)//读取RasterLayer的路径名和像元大小值
         {
             IRasterLayer pRasterLayer = pLayer as IRasterLayer;
             IDataset     pDataset     = pRasterLayer as IDataset;
             pSourceWorkspace = pDataset.Workspace;
             toraster_Path    = pSourceWorkspace.PathName;
             toraster_Path    = toraster_Path + toraster_Name;
         }
         else if (pLayer is ITinLayer)
         {
             ITinLayer pTinLayer = pLayer as ITinLayer;
             ITin      pTin      = pTinLayer.Dataset;
             IDataset  pDataset  = pTin as IDataset;
             pSourceWorkspace = pDataset.Workspace;
             toraster_Path    = pSourceWorkspace.PathName;
             toraster_Path    = toraster_Path + "\\" + toraster_Name;
         }
         btnSure.Enabled = true;
     }
     else
     {
         btnSure.Enabled = false;
     }
 }
        private void 建立TINToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ILayer        player    = axMapControl1.get_Layer(0);
            IFeatureLayer pFlayer   = player as IFeatureLayer;
            IFeatureClass pFClass   = pFlayer.FeatureClass;
            IField        pField    = pFClass.Fields.get_Field(pFClass.FindField("Z"));
            ITin          shp2TIN   = Create_TIN(pFClass, pField);
            ITinLayer     pTinLayer = new TinLayerClass();

            pTinLayer.Name    = player.Name;
            pTinLayer.Dataset = shp2TIN;
            axSceneControl1.Scene.AddLayer(pTinLayer as ILayer, true);
            axSceneControl1.Refresh();
        }
        private IFeatureClass Create_ContourLine(ITin pTin, string WorkSpaceName, string FileName)
        {
            int pInterval = 1;
            IWorkspaceFactory contourWSF = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace contourFWS = (IFeatureWorkspace)contourWSF.OpenFromFile(WorkSpaceName, 0);
            IFields           pFields    = CreateShapeFields(esriGeometryType.esriGeometryPolyline);

            contourFWS.CreateFeatureClass(FileName, pFields, null, null, esriFeatureType.esriFTSimple, "Shape", null);
            IFeatureClass pContourFeatureClass = contourFWS.OpenFeatureClass(FileName);
            //生成等高线
            ITinSurface pTinSurface = pTin as ITinSurface;

            pTinSurface.Contour(0, pInterval, pContourFeatureClass, "Contour", 0);
            return(pContourFeatureClass);
        }
示例#7
0
        /// <summary>
        /// TIN转DEM
        /// </summary>
        /// <param name="tin">TIN数据</param>
        /// <param name="path">DEM数据</param>
        /// <param name="pixelSize">像元大小</param>
        public static void TIN2DEM(ITin tin, string path, double pixelSize)
        {
            Geoprocessor gp = new Geoprocessor();

            gp.OverwriteOutput = true;
            TinRaster tinRaster = new TinRaster();

            tinRaster.in_tin          = tin;
            tinRaster.out_raster      = path;
            tinRaster.data_type       = "FLOAT";
            tinRaster.method          = "NATURAL_NEIGHBORS";
            tinRaster.sample_distance = "CELLSIZE " + pixelSize;
            tinRaster.z_factor        = 1;
            gp.Execute(tinRaster, null);
        }
示例#8
0
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            // TODO:  Add ToolModefyTINNode.OnMouseDown implementation
            ITin     pTin     = pTinLayer.Dataset;
            ITinEdit pTinEdit = pTin as ITinEdit;

            frmModifyNode.m_pTinEdit = pTinEdit;
            frmModifyNode.m_pTinNode = pNode;
            frmModifyNode.setDoubleInputValue(pNode.Z);
            frmModifyNode.setBttonEnable(true);
            IMapControl2 pMapCtr = (((IToolbarControl)m_hookHelper.Hook).Buddy) as IMapControl2;

            frmModifyNode.m_pMapCtr = pMapCtr;
            pMovePtFeedBack.Stop();
            //IPoint pt = new PointClass();
            //pMovePtFeedBack.Start(pt, pt);
        }
示例#9
0
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            // TODO:  Add ToolDeleteTINNode.OnMouseDown implementation
            ITin     pTin     = pTinLayer.Dataset;
            ITinEdit pTinEdit = pTin as ITinEdit;

            pTinEdit.DeleteNode(pNode.Index);
            IMapControl2 pMapCtr = (((IToolbarControl)m_hookHelper.Hook).Buddy) as IMapControl2;

            if (pMapCtr != null)
            {
                pMapCtr.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
            }
            pMovePtFeedBack.Stop();
            IPoint pt = new PointClass();

            pMovePtFeedBack.Start(pt, pt);
        }
示例#10
0
        public override void OnDblClick()
        {
            base.OnDblClick();
            ITin     pTin     = pTinLayer.Dataset;
            ITinEdit pTinEdit = pTin as ITinEdit;

            frmAddTINPlane.pTinEdit = pTinEdit;
            if (mNewPolygonFeedback != null)
            {
                IPolygon polygon = mNewPolygonFeedback.Stop();
                frmAddTINPlane.pGeometry = polygon;
                frmAddTINPlane.setButtonOkEnable(true);
                frmAddTINPlane.CalPlaneHeight();
                IMapControl2 pMapCtr = (((IToolbarControl)m_hookHelper.Hook).Buddy) as IMapControl2;
                frmAddTINPlane.pMapCtr = pMapCtr;
                mNewPolygonFeedback    = null;
            }
        }
示例#11
0
        private void comboBoxOpen_SelectedIndexChanged(object sender, EventArgs e)//选择图层并自动设置默认输出像元大小及图层路径
        {
            if (comboBoxOpen.Items.Count > 0)
            {
                txtSave.Text     = "";
                txtCellSize.Text = "0.02";
                fileName         = comboBoxOpen.SelectedItem.ToString();

                ILayer pLayer = GetLayerByName(ref fileName);
                //去除不可用的数据    ZQ  20110907
                if (pLayer.Valid)
                {
                    return;
                }
                IWorkspace pSourceWorkspace;
                if (pLayer is IRasterLayer)//读取RasterLayer的路径名和像元大小值
                {
                    IRasterLayer         pRasterLayer         = pLayer as IRasterLayer;
                    IRaster              pRaster              = pRasterLayer.Raster;
                    IRasterAnalysisProps pRasterAnalysisProps = (IRasterAnalysisProps)pRaster;
                    double pixH = pRasterAnalysisProps.PixelHeight;
                    txtCellSize.Text = Convert.ToString(pixH);
                    IDataset pDataset = pRasterLayer as IDataset;
                    pSourceWorkspace = pDataset.Workspace;
                    filePath         = pSourceWorkspace.PathName;
                    filePath         = filePath + fileName;
                }
                else if (pLayer is ITinLayer)//读取TIN数据的路径信息
                {
                    ITinLayer pTinLayer = pLayer as ITinLayer;
                    ITin      pTin      = pTinLayer.Dataset;
                    IDataset  pDataset  = pTin as IDataset;
                    pSourceWorkspace = pDataset.Workspace;
                    filePath         = pSourceWorkspace.PathName;
                    filePath         = filePath + "\\" + fileName;
                }

                btnSure.Enabled = true;
            }
            else
            {
                btnSure.Enabled = false;
            }
        }
示例#12
0
        /// <summary>
        /// 加载栅格图层
        /// </summary>
        private void AddTinFile()
        {
            this.Cursor = Cursors.WaitCursor;
            IWorkspaceFactory pWorkspaceFactory = new TinWorkspaceFactoryClass();

            IWorkspace    pWorkspace    = pWorkspaceFactory.OpenFromFile(m_Path, 0);
            ITinWorkspace pTinWorkspace = pWorkspace as ITinWorkspace;
            //声明一个pTin变量, 存储所打开的"tin"
            ITin pTin = pTinWorkspace.OpenTin("tin");
            //将TIN变为TIN图层
            ITinLayer pTinLayer = new TinLayerClass();

            pTinLayer.Dataset = pTin;
            pTinLayer.Name    = "TIN";
            //也可以用三维空间AxSceneControl加载
            axSceneControl1.Scene.AddLayer(pTinLayer, true);
            //this.axMapControl1.AddLayer(pTinLayer);
            this.Cursor = Cursors.Default;
        }
示例#13
0
        public override void OnDblClick()
        {
            ITin     pTin     = pTinLayer.Dataset;
            ITinEdit pTinEdit = pTin as ITinEdit;

            if (mNewPolygonFeedback != null)
            {
                IPolygon      polygon      = mNewPolygonFeedback.Stop();
                ITinSelection tinselection = pTinEdit as ITinSelection;
                tinselection.SelectByArea(esriTinElementType.esriTinNode, polygon, true, true, esriTinSelectionType.esriTinSelectionAdd);
                pTinEdit.DeleteSelectedNodes();
                mNewPolygonFeedback = null;
                IMapControl2 pMapCtr = (((IToolbarControl)m_hookHelper.Hook).Buddy) as IMapControl2;
                if (pMapCtr != null)
                {
                    pMapCtr.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
                }
            }
            base.OnDblClick();
        }
示例#14
0
        public override void OnMouseMove(int Button, int Shift, int X, int Y)
        {
            // TODO:  Add ToolModefyTINNode.OnMouseMove implementation
            ITin         pTin         = pTinLayer.Dataset;
            ITinEdit     pTinEdit     = pTin as ITinEdit;
            ITinAdvanced pTinAdvanced = (ITinAdvanced)pTin;
            IMapControl2 pMapCtr      = (((IToolbarControl)m_hookHelper.Hook).Buddy) as IMapControl2;

            if (pMapCtr != null)
            {
                IPoint   mapPoint = pMapCtr.ToMapPoint(X, Y);
                ITinNode pTINNode = new TinNodeClass();
                double   distance = 0;
                pTinAdvanced.QueryNearestNode(mapPoint, pTINNode, ref distance);
                pNode = pTINNode;
                IPoint pt = new PointClass();
                pt.PutCoords(pNode.X, pNode.Y);
                pMovePtFeedBack.MoveTo(pt);
            }
        }
示例#15
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add CmdTinSaveAs.OnClick implementation
            SaveFileDialog dlg = new SaveFileDialog();

            dlg.Filter = "";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                ITin     pTin     = pTinLayer.Dataset;
                ITinEdit pTinEdit = pTin as ITinEdit;
                try
                {
                    object ob = true;
                    pTin.SaveAs(dlg.FileName, ref ob);
                    MessageBox.Show("±£´æ" + dlg.FileName + "³É¹¦£¡");
                }
                catch (SystemException ee)
                {
                    MessageBox.Show(ee.Message);
                }
            }
        }
示例#16
0
        private void comboBoxOpenraster_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBoxOpenraster.Items.Count > 0)
            {
                fileName_raster = comboBoxOpenraster.SelectedItem.ToString();

                ILayer     pLayer = GetLayerByName(ref fileName_raster);
                IWorkspace pSourceWorkspace;
                if (pLayer is IRasterLayer)//读取RasterLayer的路径名和像元大小值
                {
                    IRasterLayer         pRasterLayer         = pLayer as IRasterLayer;
                    IRaster              pRaster              = pRasterLayer.Raster;
                    IRasterAnalysisProps pRasterAnalysisProps = (IRasterAnalysisProps)pRaster;
                    double pixH = pRasterAnalysisProps.PixelHeight;
                    txtCellSize.Text = Convert.ToString(pixH);
                    IDataset pDataset = pRasterLayer as IDataset;
                    pSourceWorkspace = pDataset.Workspace;
                    filePath_raster  = pSourceWorkspace.PathName;
                    filePath_raster  = filePath_raster + fileName_raster;
                }
                else if (pLayer is ITinLayer)
                {
                    ITinLayer pTinLayer = pLayer as ITinLayer;
                    ITin      pTin      = pTinLayer.Dataset;
                    IDataset  pDataset  = pTin as IDataset;
                    pSourceWorkspace = pDataset.Workspace;
                    filePath_raster  = pSourceWorkspace.PathName;
                    filePath_raster  = filePath_raster + "\\" + fileName_raster;
                }

                btnSure.Enabled = true;
            }
            else
            {
                btnSure.Enabled = false;

                btnSure.ForeColor = Color.Black;
            }
        }
示例#17
0
 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (this.comboBox1.SelectedItem.ToString() != "")
     {
         for (int i = 0; i < m_mapControl.LayerCount; i++)
         {
             if (m_mapControl.get_Layer(i).Name == this.comboBox1.SelectedItem.ToString())
             {
                 m_tin            = ((ITinLayer)m_mapControl.get_Layer(i)).Dataset;
                 this.label6.Text = m_tin.Extent.ZMin.ToString() + "——" + m_tin.Extent.ZMax.ToString() + "米";
             }
         }
     }
     else
     {
         m_tin            = null;
         this.label6.Text = "";
     }
     this.label7.Text   = "";
     this.label8.Text   = "";
     this.textBox1.Text = "0";
     this.textBox2.Text = "";
 }
示例#18
0
        private void mapCtlMain_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
        {
            if (m_bEditNode)
            {
                m_editor.EditFeatureMouseMove(e.x, e.y);
            }

            ILayer lyr;
            for (int i = 0; i < this.mapCtlMain.LayerCount; i++)
            {
                lyr = this.mapCtlMain.get_Layer(i);
                if (lyr is ITinLayer)
                {
                    this.m_tin = ((ITinLayer)lyr).Dataset;
                }
            }
            if (m_tin != null)
            {
                IPoint point = new PointClass();
                point.X = e.mapX;
                point.Y = e.mapY;
                ISurface sur = m_tin as ISurface;
                double z = sur.GetElevation(point);
                string zStr = ",Z=" + z.ToString("#######.##");
                this.StatusBar.Panels[2].Text = string.Format("{0}, {1}  {2}  {3}", "X=" + e.mapX.ToString("#######.##"), "Y=" + e.mapY.ToString("#######.##"), zStr, this.mapCtlMain.MapUnits.ToString().Substring(4));

            }
            else
            {
                this.StatusBar.Panels[2].Text = string.Format("{0}, {1}  {2}", "X=" + e.mapX.ToString("#######.##"), "Y=" + e.mapY.ToString("#######.##"), this.mapCtlMain.MapUnits.ToString().Substring(4));
            }
            string XN = e.mapX.ToString();
            string YE = e.mapY.ToString();
            this.PlanarToGeoCoor(ref XN, ref YE);
            this.StatusBar.Panels[3].Text = YE + " N   " + XN + " E";
        }
        private void Tin2Contour(ITin pTin,IFeatureClass pFeatureClass)
        {
            ITinSurface pTinSurface = pTin as ITinSurface;

             //不要启动编辑,因为这个接口会在要素类中添加字段
             pTinSurface.Contour(0, 2, pFeatureClass, "Height", 0);
        }
示例#20
0
 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (this.comboBox1.SelectedItem.ToString() != "")
     {
         for (int i = 0; i < m_mapControl.LayerCount; i++)
         {
             if (m_mapControl.get_Layer(i).Name == this.comboBox1.SelectedItem.ToString())
             {
                 m_tin = ((ITinLayer)m_mapControl.get_Layer(i)).Dataset;
                 this.label6.Text = m_tin.Extent.ZMin.ToString() + "——" + m_tin.Extent.ZMax.ToString()+"米";
             }
         }
     }
     else
     {
         m_tin = null;
         this.label6.Text = "";
     }
     this.label7.Text = "";
     this.label8.Text = "";
     this.textBox1.Text = "0";
     this.textBox2.Text = "";
 }
示例#21
0
 /// <summary>
 /// 整体边长标准差(全局)
 /// </summary>
 /// <param name="tin"></param>
 /// <param name="globalMean"></param>
 /// <returns></returns>
 private double GlobalStDev(ITin tin, double globalMean)
 {
     double a = 0;
     ITinAdvanced tinAdvanced = tin as ITinAdvanced;
     int edgeCount = tinAdvanced.EdgeCount;
     //            int edgeCount = tinAdvanced.DataEdgeCount;
     for (int i = 1; i <= edgeCount; i++)
     {
         if (tinAdvanced.GetEdge(i).IsInsideDataArea)
         {
             ITinEdge tinEdge = tinAdvanced.GetEdge(i);
             a = a + (globalMean - tinEdge.Length) * (globalMean - tinEdge.Length);
         }
     }
     return System.Math.Sqrt(a / (double)tinAdvanced.DataEdgeCount);
 }
示例#22
0
 /// <summary>
 /// Delaunay三角网整体边长平均值(全局)
 /// </summary>
 /// <param name="tin"></param>
 /// <returns></returns>
 private double GlobalMean(ITin tin)
 {
     double length = 0;
     ITinAdvanced tinAdvanced = tin as ITinAdvanced;
     int edgeCount = tinAdvanced.EdgeCount;
     for (int i = 1; i <= edgeCount; i++)
     {
         if (tinAdvanced.GetEdge(i).IsInsideDataArea)
             length = length + tinAdvanced.GetEdge(i).Length;
     }
     return length / (double)tinAdvanced.DataEdgeCount;
 }
示例#23
0
        /// <summary>
        /// 创建TIN
        /// </summary>
        private void CreateDelaunay()
        {
            //创建TIN
            IFeatureLayer featureLayer = m_dataInfo.GetInputLayer() as IFeatureLayer;
            IFeatureClass featureClass = featureLayer.FeatureClass;
            IField pField = featureClass.Fields.get_Field(0);

            if (pField == null)
            {
                MessageBox.Show("创建Delaunay三角网失败");
                return;
            }

            IGeoDataset pGeoDataset = featureClass as IGeoDataset;
            IEnvelope pEnvelope = pGeoDataset.Extent;
            pEnvelope.SpatialReference = pGeoDataset.SpatialReference;

            ITinEdit pTinEdit = new TinClass();
            pTinEdit.InitNew(pEnvelope);
            object obj = Type.Missing;
            pTinEdit.AddFromFeatureClass(featureClass, null, pField, null, esriTinSurfaceType.esriTinMassPoint, ref obj);
            m_DT = pTinEdit as ITin;

            //将所有点标识为噪声点
            ITinAdvanced tinAdvanced = m_DT as ITinAdvanced;
            for (int i = 0; i < tinAdvanced.NodeCount; i++)
            {
                m_nodeFlag.Add(-1);
            }
        }
        /// <summary>
        /// 创建泰森多边形
        /// </summary>
        /// <param name="pFeatureClass"></param>
        /// <param name="pTin"></param>
        void CreateVr(IFeatureClass pFeatureClass ,ITin pTin)
        {
            ITinNodeCollection pTinColl = pTin as ITinNodeCollection;

               pTinColl.ConvertToVoronoiRegions(pFeatureClass, null, null, "", "");
        }