コード例 #1
0
        private void btnGO_Click(object sender, EventArgs e)
        {
            string fileName;
            string shpFile;
            int    startX, endX;
            string shpDir;

            try
            {
                if (bDataPath == true)
                {
                    fileName = txtOutPath.Text;
                    shpDir   = fileName.Substring(0, fileName.LastIndexOf("\\"));
                    startX   = fileName.LastIndexOf("\\");
                    endX     = fileName.Length;
                    shpFile  = fileName.Substring(startX + 1, endX - startX - 1);
                }
                else
                {
                    shpDir  = txtOutPath.Text;
                    shpFile = "·ÖÅäÕ¤¸ñ";
                }
                if (m_pInFeatLyr != null)
                {
                    double      dCellSize   = Convert.ToDouble(txtCellSize.Text);
                    double      dMaxDis     = Convert.ToDouble(txtMaxValue.Text);
                    object      objMaxDis   = dMaxDis;
                    object      Missing     = Type.Missing;
                    IDistanceOp pDistanceOp = Utility.SetRasterDisAnalysisEnv(shpDir, dCellSize, m_pInFeatLyr);

                    IFeatureClass pInFeatCls   = m_pInFeatLyr.FeatureClass;
                    IRaster       pOutRaster   = null;
                    IRasterLayer  pRasterLayer = new RasterLayerClass();

                    pOutRaster = pDistanceOp.EucAllocation(pInFeatCls as IGeoDataset, ref objMaxDis, ref Missing) as IRaster;

                    pRasterLayer.Name = shpFile;
                    Utility.ConvertRasterToRsDataset(shpDir, pOutRaster, shpFile);
                    pRasterLayer = Utility.SetRsLayerClassifiedColor(pOutRaster);
                    pMainFrm.getMapControl().AddLayer(pRasterLayer, 0);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #2
0
        private void BtnGO_Click(object sender, System.EventArgs e)
        {
            IFeatureClass pFClass = null;
            IWorkspace    pWorkspace;
            object        Missing = Type.Missing;
            string        fileName;
            string        rasterPath;
            string        shpFile;
            int           startX, endX;

            if (bDataPath == true)
            {
                fileName = cboDisRaster.Text;

                string shpDir = fileName.Substring(0, fileName.LastIndexOf("\\"));
                startX  = fileName.LastIndexOf("\\");
                endX    = fileName.Length;
                shpFile = fileName.Substring(startX + 1, endX - startX - 1);

                pFClass = Utility.OpenFeatureClassFromShapefile(shpDir, shpFile);
            }
            else
            {
                AxMapControl  axMap = pMainFrm.getMapControl();
                IRasterLayer  pRLyr;
                IFeatureLayer pFLyr;
                for (int i = 0; i <= axMap.LayerCount - 1; i++)
                {
                    ILayer pLyr = axMap.get_Layer(i);
                    if (pLyr != null)
                    {
                        if (pLyr.Name == cboDisRaster.Text)
                        {
                            if (pLyr is IFeatureLayer)
                            {
                                pFLyr   = pLyr as IFeatureLayer;
                                pFClass = pFLyr.FeatureClass as IFeatureClass;
                            }
                            else
                            {
                                if (pLyr is IRasterLayer)
                                {
                                    pRLyr = pLyr as IRasterLayer;
                                }
                            }
                        }
                    }
                }
            }
            double cellsize = Convert.ToDouble(txtCellSize.Text);

            rasterPath = txtRasterPath.Text;
            IFeatureLayer pfeatLyr = new FeatureLayerClass();

            pfeatLyr.FeatureClass = pFClass;
            IDistanceOp pDistranceOp = Utility.SetRasterDisAnalysisEnv(rasterPath, cellsize, pfeatLyr);

            double maxDis    = Convert.ToDouble(txtMaxDis.Text);
            object objMaxDis = maxDis;

            try
            {
                if (chkDirection.Checked == true)
                {
                    rasterPath   = txtDirectionPath.Text;
                    pDistranceOp = Utility.SetRasterDisAnalysisEnv(rasterPath, cellsize, pfeatLyr);
                    IRasterLayer pRasterLayer1        = new RasterLayerClass();
                    IRaster      pOutDirectiontRaster = pDistranceOp.EucDirection(pFClass as IGeoDataset, ref objMaxDis, ref Missing) as IRaster;
                    //pRasterLayer1.CreateFromRaster(pOutDirectiontRaster);
                    pRasterLayer1.Name = "方向栅格";
                    Utility.ConvertRasterToRsDataset(rasterPath, pOutDirectiontRaster, "方向栅格");
                    pRasterLayer1 = Utility.GetRLayerClassifyColor(pOutDirectiontRaster, maxDis);
                    pMainFrm.getMapControl().AddLayer(pRasterLayer1, 0);
                }
                if (chkAllocation.Checked == true)
                {
                    rasterPath   = txtAllocationPath.Text;
                    pDistranceOp = Utility.SetRasterDisAnalysisEnv(rasterPath, cellsize, pfeatLyr);
                    IRasterLayer pRasterLayer2        = new RasterLayerClass();
                    IRaster      pOutAllocationRaster = pDistranceOp.EucDirection(pFClass as IGeoDataset, ref objMaxDis, ref Missing) as IRaster;
                    //pRasterLayer2.CreateFromRaster(pOutAllocationRaster);
                    pRasterLayer2.Name = "分配栅格";
                    Utility.ConvertRasterToRsDataset(rasterPath, pOutAllocationRaster, "方向栅格");
                    pRasterLayer2 = Utility.GetRLayerClassifyColor(pOutAllocationRaster, maxDis);
                    pMainFrm.getMapControl().AddLayer(pRasterLayer2, 0);
                }
                IRasterLayer pRasterLayer3 = new RasterLayerClass();
                IRaster      pOutRaster    = pDistranceOp.EucDistance(pFClass as IGeoDataset, ref objMaxDis, ref Missing) as IRaster;
                //pRasterLayer3.CreateFromRaster(pOutRaster);
                //着色

                pRasterLayer3.Name = "距离栅格";
                Utility.ConvertRasterToRsDataset(rasterPath, pOutRaster, "距离栅格");
                pRasterLayer3 = Utility.GetRLayerClassifyColor(pOutRaster, maxDis);
                pMainFrm.getMapControl().AddLayer(pRasterLayer3, 0);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }