Beispiel #1
0
        /// <summary>
        /// 图层切割栅格数据
        /// </summary>
        /// <param name="rasterLayer">栅格数据图层</param>
        /// <param name="clipLayer">切割适量图层</param>
        /// <param name="outputFullPath">切割栅格完整路径</param>
        public void ClipRasterByLayer(ILayer rasterLayer, ILayer clipLayer, string outputFullPath)
        {
            string rasterPath = GetLayerPath(rasterLayer);
            string clipPath   = GetLayerPath(clipLayer);

            ExtractByMask clipTool = new ExtractByMask();

            clipTool.in_raster    = rasterPath;
            clipTool.in_mask_data = clipPath;
            clipTool.out_raster   = outputFullPath;

            Geoprocessor processor = new Geoprocessor();
            IGPProcess   process   = null;

            processor.OverwriteOutput = true;
            process = clipTool;
            processor.Validate(process, true);
            processor.Execute(process, null);

            DirectoryInfo     di        = new DirectoryInfo(outputFullPath);
            string            rasterDir = di.Parent.FullName;
            string            name      = di.Name;
            IWorkspaceFactory rasterWorkspaceFactory = new RasterWorkspaceFactoryClass();
            IRasterWorkspace  rasterWorkspace        = rasterWorkspaceFactory.OpenFromFile(rasterDir, 0) as IRasterWorkspace;
            IRasterDataset    rasterDataset          = rasterWorkspace.OpenRasterDataset(name);
            IRasterLayer      rasterLyr = new RasterLayerClass();

            rasterLyr.CreateFromDataset(rasterDataset);
            m_mapControl.Map.AddLayer(rasterLyr as ILayer);
        }
Beispiel #2
0
        /// <summary>
        /// 两图层进行裁剪运算
        /// </summary>
        /// <param name="inputLayer">被裁剪图层</param>
        /// <param name="clipLayer">裁剪图层</param>
        /// <param name="outputFullPath">输出图层完整路径</param>
        public void ClipByLayer(ILayer inputLayer, ILayer clipLayer, string outputFullPath)
        {
            string inputPath = GetLayerPath(inputLayer);
            string clipPath  = GetLayerPath(clipLayer);

            Clip clipTool = new Clip();

            clipTool.in_features       = inputPath;
            clipTool.clip_features     = clipPath;
            clipTool.out_feature_class = outputFullPath;

            Geoprocessor processor = new Geoprocessor();
            IGPProcess   process   = null;

            processor.OverwriteOutput = true;
            process = clipTool;
            processor.Validate(process, true);
            processor.Execute(process, null);

            FileInfo          fi      = new FileInfo(outputFullPath);
            string            pathDir = fi.Directory.FullName;
            string            name    = fi.Name;
            IWorkspaceFactory wsf     = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace fws     = wsf.OpenFromFile(pathDir, 0) as IFeatureWorkspace;
            IFeatureClass     featCls = fws.OpenFeatureClass(name);
            IFeatureLayer     layer   = new FeatureLayerClass();

            layer.FeatureClass = featCls;
            layer.Name         = featCls.AliasName;
            m_mapControl.Map.AddLayer(layer as ILayer);
        }
Beispiel #3
0
        /// <summary>
        /// 两图层进行裁剪运算
        /// </summary>
        /// <param name="inputLayer">被裁剪图层</param>
        /// <param name="clipLayer">裁剪图层</param>
        /// <param name="outputFullPath">输出图层完整路径</param>
        public void ClipByLayer(ILayer inputLayer, ILayer clipLayer, string outputFullPath)
        {
            string inputPath = GetLayerPath(inputLayer);
            string clipPath = GetLayerPath(clipLayer);

            Clip clipTool = new Clip();
            clipTool.in_features = inputPath;
            clipTool.clip_features = clipPath;
            clipTool.out_feature_class = outputFullPath;

            Geoprocessor processor = new Geoprocessor();
            IGPProcess process = null;
            processor.OverwriteOutput = true;
            process = clipTool;
            processor.Validate(process, true);
            processor.Execute(process, null);

            FileInfo fi = new FileInfo(outputFullPath);
            string pathDir = fi.Directory.FullName;
            string name = fi.Name;
            IWorkspaceFactory wsf = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace fws = wsf.OpenFromFile(pathDir, 0) as IFeatureWorkspace;
            IFeatureClass featCls = fws.OpenFeatureClass(name);
            IFeatureLayer layer = new FeatureLayerClass();
            layer.FeatureClass = featCls;
            layer.Name = featCls.AliasName;
            m_mapControl.Map.AddLayer(layer as ILayer);
        }
Beispiel #4
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            /*FileInfo openpath = new FileInfo(textBox1.Text);
            string ss = openpath.Directory.ToString();//·���ĸ�Ŀ¼

            ILayer pLayer;
            pLayer = m_mapControl.Map.get_Layer(comboBox1.SelectedIndex);
            IFeatureLayer pInputFeatureLayer;
            pInputFeatureLayer = pLayer as IFeatureLayer;
            IFeatureClass pInputFeatureClass = pInputFeatureLayer.FeatureClass;

            ITable pInputTable;
            pInputTable = pInputFeatureClass as ITable;

            pInputFeatureClass = pInputFeatureLayer.FeatureClass;

            pLayer = m_mapControl.Map.get_Layer(comboBox2.SelectedIndex);
            IFeatureLayer pOverlayFeatureLayer;
            pOverlayFeatureLayer = pLayer as IFeatureLayer;
            IFeatureClass pOverlayFeatureClass;
            pOverlayFeatureClass = pOverlayFeatureLayer.FeatureClass;

            ITable pOverlayTable;
            pOverlayTable = pOverlayFeatureClass as ITable;

            //IFeatureClass pOverlayFeatureClass;
            //pOverlayFeatureClass = pOverlayFeatureLayer.FeatureClass;

            if (pInputTable == null)
            {
                MessageBox.Show("����ͼ��Ϊ��");
                return;
            }

            if (pOverlayTable == null)
            {
                MessageBox.Show("����ͼ��Ϊ��");
                return;
            }

            IFeatureClassName pFeatureClassName;
            pFeatureClassName = new FeatureClassNameClass();
            pFeatureClassName.FeatureType = esriFeatureType.esriFTSimple;
            pFeatureClassName.ShapeFieldName = "Shape";
            pFeatureClassName.ShapeType = pInputFeatureClass.ShapeType;

            IWorkspaceName pNewWSName;
            pNewWSName = new WorkspaceNameClass();
            pNewWSName.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory";
            pNewWSName.PathName = ss;

            IDatasetName pDatasetName;
            pDatasetName = pFeatureClassName as IDatasetName;
            pDatasetName.Name = openpath.Name;  //"Intersect_Result";
            pDatasetName.WorkspaceName = pNewWSName;

            double tol = 0.1;

            IBasicGeoprocessor pBGP;
            pBGP = new BasicGeoprocessorClass();
            pBGP.SpatialReference = m_mapControl.Map.SpatialReference;
            IFeatureClass pOutputFeatureClass;
            IFeatureLayer pOutputFeatLayer;
            pOutputFeatLayer = new FeatureLayerClass();
            int n = listBox1.SelectedIndex;

            if (n>= 0 && n< 3)
            {
                switch (n)
                {
                    case(0):
                        pOutputFeatureClass = pBGP.Intersect(pInputTable, false, pOverlayTable, false, tol, pFeatureClassName);
                        pOutputFeatLayer.FeatureClass = pOutputFeatureClass;
                        pOutputFeatLayer.Name = pOutputFeatureClass.AliasName;
                        m_mapControl.Map.AddLayer(pOutputFeatLayer);
                        break;
                    case(1):
                        pOutputFeatureClass = pBGP.Union(pInputTable, false, pOverlayTable, false, tol, pFeatureClassName);
                        pOutputFeatLayer.FeatureClass = pOutputFeatureClass;
                        pOutputFeatLayer.Name = pOutputFeatureClass.AliasName;
                        m_mapControl.Map.AddLayer(pOutputFeatLayer);
                        break;
                    case(2):
                        pOutputFeatureClass = pBGP.Clip(pInputTable, false, pOverlayTable, false, tol, pFeatureClassName);
                        pOutputFeatLayer.FeatureClass = pOutputFeatureClass;
                        pOutputFeatLayer.Name = pOutputFeatureClass.AliasName;
                        m_mapControl.Map.AddLayer(pOutputFeatLayer);
                        break;
                }
            }*/
            //Geoprocessor processor = new Geoprocessor();
            IFeatureLayer inputLyr = m_mapControl.Map.get_Layer(comboBox1.SelectedIndex) as IFeatureLayer;
            IDataLayer2 dataLy = inputLyr as IDataLayer2;
            IDatasetName inputdsName = dataLy.DataSourceName as IDatasetName;
            IWorkspaceName inputws = inputdsName.WorkspaceName as IWorkspaceName;
            string input=inputws.PathName+"\\"+inputLyr.Name;

            IFeatureLayer overlayLyr = m_mapControl.Map.get_Layer(comboBox2.SelectedIndex) as IFeatureLayer;
            IDataLayer2 dataOverlay = overlayLyr as IDataLayer2;
            IDatasetName overlayDsName = dataOverlay.DataSourceName as IDatasetName;
            IWorkspaceName overlayWs = overlayDsName.WorkspaceName;
            string overlay =overlayWs.PathName+"\\"+overlayLyr.Name;

            string output =textBox1.Text;

            Geoprocessor processor = new Geoprocessor();
            processor.OverwriteOutput = true;
            IGPProcess process=null;
            switch (listBox1.SelectedIndex)
            {
                case 0:
                    Intersect intersect = new Intersect();
                    intersect.in_features = "'" + input + "'" + ";" + "'" + overlay + "'";
                    intersect.out_feature_class =output;
                    intersect.output_type = "INPUT";
                    intersect.join_attributes = "ALL";
                    //intersect.cluster_tolerance=0.1;
                    process = intersect;
                    break;
                case 1:
                    Union union = new Union();
                    union.in_features = "'" + input+"'" +";"+"'"+overlay+ "'";
                    union.out_feature_class = @""+output;
                    union.join_attributes = "ALL";
                    //union.cluster_tolerance = 0.1;
                    process = union;
                    break;
                case 2:
                    Erase erase = new Erase();
                    erase.in_features = "'" + input + "'";
                    erase.erase_features = "'" + overlay + "'";
                    erase.out_feature_class = output;
                    //erase.cluster_tolerance = 0.1;
                    process = erase;
                    break;

            }
            processor.Validate(process, true);
            processor.Execute(process, null);
            this.Dispose();

            FileInfo fi = new FileInfo(textBox1.Text);
            string pathDir = fi.Directory.FullName;
            string name = fi.Name;
            IWorkspaceFactory wsf = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace fws = wsf.OpenFromFile(pathDir, 0) as IFeatureWorkspace;
            IFeatureClass featCls = fws.OpenFeatureClass(name);
            IFeatureLayer layer = new FeatureLayerClass();
            layer.FeatureClass = featCls;
            layer.Name = featCls.AliasName;
            m_mapControl.Map.AddLayer(layer as ILayer);
        }
Beispiel #5
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            /*FileInfo openpath = new FileInfo(textBox1.Text);
             * string ss = openpath.Directory.ToString();//路径的父目录
             *
             * ILayer pLayer;
             * pLayer = m_mapControl.Map.get_Layer(comboBox1.SelectedIndex);
             * IFeatureLayer pInputFeatureLayer;
             * pInputFeatureLayer = pLayer as IFeatureLayer;
             * IFeatureClass pInputFeatureClass = pInputFeatureLayer.FeatureClass;
             *
             *
             * ITable pInputTable;
             * pInputTable = pInputFeatureClass as ITable;
             *
             *
             * pInputFeatureClass = pInputFeatureLayer.FeatureClass;
             *
             * pLayer = m_mapControl.Map.get_Layer(comboBox2.SelectedIndex);
             * IFeatureLayer pOverlayFeatureLayer;
             * pOverlayFeatureLayer = pLayer as IFeatureLayer;
             * IFeatureClass pOverlayFeatureClass;
             * pOverlayFeatureClass = pOverlayFeatureLayer.FeatureClass;
             *
             * ITable pOverlayTable;
             * pOverlayTable = pOverlayFeatureClass as ITable;
             *
             *
             * //IFeatureClass pOverlayFeatureClass;
             * //pOverlayFeatureClass = pOverlayFeatureLayer.FeatureClass;
             *
             * if (pInputTable == null)
             * {
             *  MessageBox.Show("输入图层为空");
             *  return;
             * }
             *
             * if (pOverlayTable == null)
             * {
             *  MessageBox.Show("叠置图层为空");
             *  return;
             * }
             *
             * IFeatureClassName pFeatureClassName;
             * pFeatureClassName = new FeatureClassNameClass();
             * pFeatureClassName.FeatureType = esriFeatureType.esriFTSimple;
             * pFeatureClassName.ShapeFieldName = "Shape";
             * pFeatureClassName.ShapeType = pInputFeatureClass.ShapeType;
             *
             * IWorkspaceName pNewWSName;
             * pNewWSName = new WorkspaceNameClass();
             * pNewWSName.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory";
             * pNewWSName.PathName = ss;
             *
             * IDatasetName pDatasetName;
             * pDatasetName = pFeatureClassName as IDatasetName;
             * pDatasetName.Name = openpath.Name;  //"Intersect_Result";
             * pDatasetName.WorkspaceName = pNewWSName;
             *
             * double tol = 0.1;
             *
             * IBasicGeoprocessor pBGP;
             * pBGP = new BasicGeoprocessorClass();
             * pBGP.SpatialReference = m_mapControl.Map.SpatialReference;
             * IFeatureClass pOutputFeatureClass;
             * IFeatureLayer pOutputFeatLayer;
             * pOutputFeatLayer = new FeatureLayerClass();
             * int n = listBox1.SelectedIndex;
             *
             * if (n>= 0 && n< 3)
             * {
             *  switch (n)
             *  {
             *      case(0):
             *          pOutputFeatureClass = pBGP.Intersect(pInputTable, false, pOverlayTable, false, tol, pFeatureClassName);
             *          pOutputFeatLayer.FeatureClass = pOutputFeatureClass;
             *          pOutputFeatLayer.Name = pOutputFeatureClass.AliasName;
             *          m_mapControl.Map.AddLayer(pOutputFeatLayer);
             *          break;
             *      case(1):
             *          pOutputFeatureClass = pBGP.Union(pInputTable, false, pOverlayTable, false, tol, pFeatureClassName);
             *          pOutputFeatLayer.FeatureClass = pOutputFeatureClass;
             *          pOutputFeatLayer.Name = pOutputFeatureClass.AliasName;
             *          m_mapControl.Map.AddLayer(pOutputFeatLayer);
             *          break;
             *      case(2):
             *          pOutputFeatureClass = pBGP.Clip(pInputTable, false, pOverlayTable, false, tol, pFeatureClassName);
             *          pOutputFeatLayer.FeatureClass = pOutputFeatureClass;
             *          pOutputFeatLayer.Name = pOutputFeatureClass.AliasName;
             *          m_mapControl.Map.AddLayer(pOutputFeatLayer);
             *          break;
             *  }
             * }*/
            //Geoprocessor processor = new Geoprocessor();
            IFeatureLayer  inputLyr    = m_mapControl.Map.get_Layer(comboBox1.SelectedIndex) as IFeatureLayer;
            IDataLayer2    dataLy      = inputLyr as IDataLayer2;
            IDatasetName   inputdsName = dataLy.DataSourceName as IDatasetName;
            IWorkspaceName inputws     = inputdsName.WorkspaceName as IWorkspaceName;
            string         input       = inputws.PathName + "\\" + inputLyr.Name;

            IFeatureLayer  overlayLyr    = m_mapControl.Map.get_Layer(comboBox2.SelectedIndex) as IFeatureLayer;
            IDataLayer2    dataOverlay   = overlayLyr as IDataLayer2;
            IDatasetName   overlayDsName = dataOverlay.DataSourceName as IDatasetName;
            IWorkspaceName overlayWs     = overlayDsName.WorkspaceName;
            string         overlay       = overlayWs.PathName + "\\" + overlayLyr.Name;

            string output = textBox1.Text;

            Geoprocessor processor = new Geoprocessor();

            processor.OverwriteOutput = true;
            IGPProcess process = null;

            switch (listBox1.SelectedIndex)
            {
            case 0:
                Intersect intersect = new Intersect();
                intersect.in_features       = "'" + input + "'" + ";" + "'" + overlay + "'";
                intersect.out_feature_class = output;
                intersect.output_type       = "INPUT";
                intersect.join_attributes   = "ALL";
                //intersect.cluster_tolerance=0.1;
                process = intersect;
                break;

            case 1:
                Union union = new Union();
                union.in_features       = "'" + input + "'" + ";" + "'" + overlay + "'";
                union.out_feature_class = @"" + output;
                union.join_attributes   = "ALL";
                //union.cluster_tolerance = 0.1;
                process = union;
                break;

            case 2:
                Erase erase = new Erase();
                erase.in_features       = "'" + input + "'";
                erase.erase_features    = "'" + overlay + "'";
                erase.out_feature_class = output;
                //erase.cluster_tolerance = 0.1;
                process = erase;
                break;
            }
            processor.Validate(process, true);
            processor.Execute(process, null);
            this.Dispose();

            FileInfo          fi      = new FileInfo(textBox1.Text);
            string            pathDir = fi.Directory.FullName;
            string            name    = fi.Name;
            IWorkspaceFactory wsf     = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace fws     = wsf.OpenFromFile(pathDir, 0) as IFeatureWorkspace;
            IFeatureClass     featCls = fws.OpenFeatureClass(name);
            IFeatureLayer     layer   = new FeatureLayerClass();

            layer.FeatureClass = featCls;
            layer.Name         = featCls.AliasName;
            m_mapControl.Map.AddLayer(layer as ILayer);
        }
Beispiel #6
0
        /// <summary>
        /// 图层切割栅格数据
        /// </summary>
        /// <param name="rasterLayer">栅格数据图层</param>
        /// <param name="clipLayer">切割适量图层</param>
        /// <param name="outputFullPath">切割栅格完整路径</param>
        public void ClipRasterByLayer(ILayer rasterLayer, ILayer clipLayer, string outputFullPath)
        {
            string rasterPath = GetLayerPath(rasterLayer);
            string clipPath = GetLayerPath(clipLayer);

            ExtractByMask clipTool = new ExtractByMask();
            clipTool.in_raster = rasterPath;
            clipTool.in_mask_data = clipPath;
            clipTool.out_raster = outputFullPath;

            Geoprocessor processor = new Geoprocessor();
            IGPProcess process = null;
            processor.OverwriteOutput = true;
            process = clipTool;
            processor.Validate(process, true);
            processor.Execute(process, null);

            DirectoryInfo di = new DirectoryInfo(outputFullPath);
            string rasterDir = di.Parent.FullName;
            string name = di.Name;
            IWorkspaceFactory rasterWorkspaceFactory = new RasterWorkspaceFactoryClass();
            IRasterWorkspace rasterWorkspace = rasterWorkspaceFactory.OpenFromFile(rasterDir, 0) as IRasterWorkspace;
            IRasterDataset rasterDataset = rasterWorkspace.OpenRasterDataset(name);
            IRasterLayer rasterLyr = new RasterLayerClass();
            rasterLyr.CreateFromDataset(rasterDataset);
            m_mapControl.Map.AddLayer(rasterLyr as ILayer);
        }