Exemplo n.º 1
0
        //获得提取的工作区间
        private IWorkspace GetWorkspace()
        {
            IWorkspace functionReturnValue = default(IWorkspace);
            string     sFileRoute          = null;
            string     sFileStyle          = null;
            IWorkspace pWorkspace          = default(IWorkspace);

            sFileRoute = this.txtFileRoute.Text;
            sFileStyle = this.cmbFileStyle.Text;
            if (string.IsNullOrEmpty(sFileRoute.Trim()))
            {
                //g_clsErrorHandle.DisplayInformation("请设置提取路径!", false);
                MessageBoxEx.Show("请设置提取路径!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                functionReturnValue = null;
                return(functionReturnValue);
            }
            pWorkspace = null;
            if (sFileStyle == "SHP File")
            {
                pWorkspace = ClsCreatAndGetDataset.CreatOrGetSHPWorkspace(sFileRoute);
            }
            else if (sFileStyle == "File GeoDatabase")
            {
                pWorkspace = ClsCreatAndGetDataset.GetPDBOrGDBWorkspace(sFileRoute, true);
            }
            else if (sFileStyle == "Personal GeoDatabase")
            {
                pWorkspace = ClsCreatAndGetDataset.GetPDBOrGDBWorkspace(sFileRoute, false);
            }
            functionReturnValue = pWorkspace;
            return(functionReturnValue);
        }
Exemplo n.º 2
0
        //开始提取
        private void Deal()
        {
            IWorkspace    pWorkspace      = default(IWorkspace);
            string        sDesFeatClsName = null;
            IFeatureClass pDesFeatCls     = default(IFeatureClass);
            string        sInfo           = null;
            IFeatureLayer pFeatLayer      = default(IFeatureLayer);
            IFeatureClass pFeatureCls     = default(IFeatureClass);
            IGeometry     pDomainGeometry = default(IGeometry);
            int           ErrorCount      = 0;
            int           lFeatCount      = 0;
            bool          bIsCut          = false;

            if (this.ChkClip.Checked)
            {
                bIsCut = true;
                ////是否剪切
            }
            else
            {
                bIsCut = false;
            }
            int intChooseLayer = 0;

            ////印骅 20081121  获得多边形范围
            int iRegion = 0;

            if (_featureLayerRegion != null)
            {
                IFeatureCursor featureCursor = _featureLayerRegion.FeatureClass.Search(null, true);
                IFeature       feature       = featureCursor.NextFeature();
                while (feature != null)
                {
                    iRegion++;
                    if (Convert.ToBoolean(((DataGridViewCheckBoxCell)dgvRegionChoose.Rows[iRegion - 1].Cells["colChoose"]).Value))
                    {
                        intChooseLayer++;
                        IPolygon polygon = feature.Shape as IPolygon;
                        pDomainGeometry = polygon;

                        if (_map.LayerCount == 0)
                        {
                            MessageBoxEx.Show("没有加载图层或没有图层处于选中状态!请选中需要提取的图层!", "提示");
                            return;
                        }

                        int      iCount       = 0;
                        IDataset pTempDataset = default(IDataset);
                        //ploger = new WHFUtilities.clsLog();
                        //ploger.DBConnectionString = "Data Source=" + g_Sys.DbName + ";User ID=" + g_Sys.DbUser + " ;Password="******"当前操作层:" + pFeatLayer.Name;
                                this.lblInfo.Text = sInfo;
                                Application.DoEvents();
                                if (!string.IsNullOrEmpty(sDesFeatClsName.Trim()))
                                {
                                    if (pFeatureCls != null)
                                    {
                                        this.lblInfo.Text = sInfo + "正在获得目标要素类,请稍候....";
                                        lblInfo.Refresh();
                                        Application.DoEvents();
                                        if (sDesFeatClsName.Contains("."))
                                        {
                                            int dotIndex = 0;
                                            dotIndex        = sDesFeatClsName.IndexOf(".");
                                            sDesFeatClsName = sDesFeatClsName.Substring(dotIndex + 1, sDesFeatClsName.Length - dotIndex - 1);
                                        }

                                        //判断是否需要创建要素类 yh 15/4/09
                                        ClsCreateFeat.CheckFeatCls(bIsCut, pFeatLayer, ref lFeatCount, pDomainGeometry);
                                        if (lFeatCount != 0)
                                        {
                                            IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWorkspace;
                                            IFields           pFields           = pFeatureCls.Fields;
                                            pDesFeatCls = ClsCreatAndGetDataset.CreatOrOpenFeatClsByName(ref pFeatureWorkspace, sDesFeatClsName, ref pFields, null, null);
                                            pWorkspace  = (IWorkspace)pFeatureWorkspace;
                                            //pFeatureCls.Fields = pFields;
                                        }
                                        if (pDesFeatCls != null)
                                        {
                                            //如果不剪切的,则使用该方法,需要剪切,则使用选择集,分位于内部要素和位于外部要素或直接使用pfeatcls搜索二遍
                                            //如果数据量大的话,搜索二遍的方法是不可行的
                                            ISpatialReference           pSpatialReference = null;
                                            Dictionary <string, string> pDicField         = null;

                                            iCount = (int)ClsCreateFeat.OutPutFeat(ref pDesFeatCls, ref pFeatureCls, strRegionLayer[i], pDomainGeometry, bIsCut, ref pSpatialReference, pDicField, ref this.lblInfo, sInfo);
                                            IFeatureLayer showFeatureLayer = new FeatureLayer();
                                            showFeatureLayer.FeatureClass = pDesFeatCls;
                                            ILayer showLayer = showFeatureLayer as ILayer;
                                            showLayer.Name = pDesFeatCls.AliasName;
                                            _map.AddLayer(showLayer);
                                            // 陈昉  2009-3-1  修改 修改原因 写日志
                                            if (iCount > 0)
                                            {
                                                pTempDataset = (IDataset)pFeatureCls;
                                                //ploger.log(System.Environment.MachineName, g_Sys.User.UserID, System.DateTime.Now.ToString(),
                                                //        "数据管理子系统", "WHFDataExtract", "快速提取" + pTempDataset.Name + "中" + iCount +
                                                //        "个要素到" + pDesFeatCls.AliasName, "目标:" + System.IO.Path.GetFileName(pWorkspace.PathName));
                                            }
                                        }
                                        else
                                        {
                                            ErrorCount = ErrorCount + 1;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    feature = featureCursor.NextFeature();
                }
                this.Refresh();
                Application.DoEvents();
                if (ErrorCount > 0)
                {
                    this.lblInfo.Text = "操作中有错误发生!";
                    //g_clsErrorHandle.DisplayInformation("操作中有错误发生!", false);
                    MessageBoxEx.Show("操作中有错误发生!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                if (intChooseLayer == 0)
                {
                    MessageBoxEx.Show("没有选择提取要素,请选择!", "提示");
                    return;
                }
                //Member member = new Member();
                //member.AddLayerToMap(pWorkspace, _map);
                ESRI.ArcGIS.Carto.IActiveView activeView = _map as ESRI.ArcGIS.Carto.IActiveView;
                activeView.Refresh();
                this.lblInfo.Text = "操作完成!";
                MessageBoxEx.Show("操作完成!", "提示");
            }
        }
Exemplo n.º 3
0
        //开始提取
        private void Deal()
        {
            IWorkspace pWorkspace = default(IWorkspace);
            //grouplayer中图层可见性
            string        sDesFeatClsName = null;
            IFeatureClass pDesFeatCls     = default(IFeatureClass);
            string        sInfo           = null;
            IFeatureLayer pFeatLayer      = default(IFeatureLayer);
            IFeatureClass pFeatureCls     = default(IFeatureClass);
            int           ErrorCount      = 0;

            ErrorCount = 0;

            if (_map.LayerCount == 0)
            {
                //g_clsErrorHandle.DisplayInformation("没有加载图层或没有图层处于选中状态!请选中需要提取的图层!", false);
                MessageBoxEx.Show("没有加载图层或没有图层处于选中状态!请选中需要提取的图层!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            //WHFUtilities.clsLog ploger = default(WHFUtilities.clsLog);
            //// 陈昉  2009-2-23  修改 修改原因 写日志
            IDataset pTempDataset = default(IDataset);
            int      iCount       = 0;
            //ploger = new WHFUtilities.clsLog();
            //ploger.DBConnectionString = "Data Source=" + g_Sys.DbName + ";User ID=" + g_Sys.DbUser + " ;Password="******"当前操作层:" + pFeatLayer.Name;
                    this.lblInfo.Text = sInfo;
                    Application.DoEvents();
                    if (!string.IsNullOrEmpty(sDesFeatClsName.Trim()))
                    {
                        if (pFeatureCls != null)
                        {
                            this.lblInfo.Text = sInfo + "正在获得目标要素类,请稍候....";
                            lblInfo.Refresh();
                            Application.DoEvents();
                            if (sDesFeatClsName.Contains("."))
                            {
                                int dotIndex = 0;
                                dotIndex        = sDesFeatClsName.IndexOf(".");
                                sDesFeatClsName = sDesFeatClsName.Substring(dotIndex + 1, sDesFeatClsName.Length - dotIndex - 1);
                            }
                            IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWorkspace;
                            IFields           pFields           = pFeatureCls.Fields;
                            pDesFeatCls = ClsCreatAndGetDataset.CreatOrOpenFeatClsByName(ref pFeatureWorkspace, sDesFeatClsName, ref pFields, null, null);
                            pWorkspace  = (IWorkspace)pFeatureWorkspace;
                            //pFeatureCls.Fields = pFields;

                            if (pDesFeatCls != null)
                            {
                                //如果不剪切的,则使用该方法,需要剪切,则使用选择集,分位于内部要素和位于外部要素或直接使用pfeatcls搜索二遍
                                //如果数据量大的话,搜索二遍的方法是不可行的
                                ISpatialReference pSpatialRefer = null;

                                iCount = (int)ClsCreateFeat.OutPutFeat(ref pDesFeatCls, ref pFeatureCls, "", null, false, ref pSpatialRefer, null, ref this.lblInfo, sInfo);
                                IFeatureLayer showFeatureLayer = new FeatureLayer();
                                showFeatureLayer.FeatureClass = pDesFeatCls;
                                ILayer showLayer = showFeatureLayer as ILayer;
                                showLayer.Name = pDesFeatCls.AliasName + "_Extract";
                                _map.AddLayer(showLayer);
                                if (iCount > 0)
                                {
                                    pTempDataset = (IDataset)pFeatureCls;
                                    //// 陈昉  2009-3-1  修改 修改原因 写日志
                                    //ploger.log(System.Environment.MachineName, g_Sys.User.UserID, System.DateTime.Now.ToString(), "数据管理子系统", "WHFDataExtract", "快速提取" + pTempDataset.Name + "中" + iCount + "个要素到" + pDesFeatCls.AliasName, "目标 :" + System.IO.Path.GetFileName(pWorkspace.PathName));
                                }
                            }
                            else
                            {
                                ErrorCount = ErrorCount + 1;
                            }
                        }
                    }
                }
            }
            if (intChooseLayer == 0)
            {
                MessageBoxEx.Show("没有选择提取要素,请选择!", "提示");
                return;
            }
            this.Refresh();
            Application.DoEvents();
            if (ErrorCount > 0)
            {
                this.lblInfo.Text = "操作中有错误发生!";
                //g_clsErrorHandle.DisplayInformation("操作中有错误发生!", false);
                MessageBoxEx.Show("操作中有错误发生!", "提示");
                return;
            }
            else
            {
                //Member member = new Member();
                //member.AddLayerToMap(pWorkspace, _map);
                this.lblInfo.Text = "操作完成!";
                //g_clsErrorHandle.DisplayInformation("操作完成!", false);
                MessageBoxEx.Show("操作完成!", "提示");
            }
        }