コード例 #1
0
        /// <summary>
        /// The display rectangle.
        /// </summary>
        /// <param name="activeView">
        /// The active view.
        /// </param>
        /// <param name="elm">
        /// The elm.
        /// </param>
        /// <returns>
        /// The <see cref="IPolygon"/>.
        /// </returns>
        public static IPolygon DisplayRectangle(IActiveView activeView, out IElement elm)
        {
            ISegmentCollection segmentCollection = new PolygonClass();

            var tempEnvelope = activeView.Extent;

            CapEnvelope(ref tempEnvelope);
            segmentCollection.SetRectangle(tempEnvelope);

            var polygon  = (IPolygon)segmentCollection;
            var rgbColor = VectorIndexColor();

            elm = AddGraphicToMap(activeView.FocusMap, polygon, rgbColor, rgbColor);

            //Best practice: Redraw only the portion of the active view that contains graphics.
            activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
            return(polygon);
        }
コード例 #2
0
 /// <summary>
 /// 验证拓扑
 /// </summary>
 /// <param name="topology">拓扑</param>
 /// <param name="envelope">验证拓扑范围</param>
 /// <param name="errEx">异常</param>
 public void ValidateTopology(ITopology topology, IEnvelope envelope, out Exception errEx)
 {
     errEx = null;
     try
     {
         ISegmentCollection pLocation = new PolygonClass();
         pLocation.SetRectangle(envelope);
         IPolygon  pPoly          = topology.get_DirtyArea(pLocation as IPolygon);
         IEnvelope pAreaValidated = topology.ValidateTopology(pPoly.Envelope);
     }
     catch (Exception err)
     {
         ////*********************************************
         ////guozheng 2010-12-24 平安夜  added 系统异常日志
         //if (ModData.SysLog == null) ModData.SysLog = new clsWriteSystemFunctionLog();
         //ModData.SysLog.Write(err);
         ////**********************************************
         errEx = err;
     }
 }
コード例 #3
0
        /// <summary>
        /// 重复线
        /// </summary>
        private void Line_redo(object para)
        {
            Plugin.Application.IAppFormRef pAppForm  = para as Plugin.Application.IAppFormRef;
            System.Data.DataTable          Datatable = new System.Data.DataTable(); //手动建立一个数据表,将得到的数据邦定到检查结果当中显示
            Datatable.Columns.Add("重复线", typeof(string));                           //创建一列
            ///如果检查结果提示内有内容就清除
            ClearDataCheckGrid ClearGrid = new ClearDataCheckGrid();

            ClearGrid.Operate(pAppForm, _AppHk);
            #region 打开要操作的数据集
            if (_AppHk.MapControl.LayerCount == 0)
            {
                return;                                   //如果MAP上打开的图层为空,就返回
            }
            SetCheckState.CheckShowTips(pAppForm, "重复线检查开始,准备载入检查数据,请稍后.....");
            int L_count = _AppHk.MapControl.LayerCount;//MAP上总图层数
            if (L_count == 0)
            {
                return;              //当MAP上是空,就返回
            }
            IGeoDataset            pGeoDataset = SetCheckState.Geodatabase;
            ITopologyRuleContainer pRuleCont   = SetCheckState.pT as ITopologyRuleContainer;//引入拓扑规则接口对象,将拓扑转成对应的规则接口对象
            #endregion
            try
            {
                #region 遍历整个数据集要素
                ArrayList list_line = new ArrayList();//用动态的数组来接收满足线要素类的对象,以后面实现遍历拓扑检查
                for (int l = 0; l < L_count; l++)
                {
                    ILayer layer_1 = _AppHk.MapControl.get_Layer(l); //通过索引得到对应的层
                    #region                                          //判别是不是组,如果是,就从组中取一个层
                    if (layer_1 is IGroupLayer && layer_1.Name == SetCheckState.CheckDataBaseName)
                    {
                        ICompositeLayer grouplayer_1 = layer_1 as ICompositeLayer;//把组图层转成组合图层
                        int             group_count  = grouplayer_1.Count;
                        if (group_count == 0)
                        {
                            return;
                        }
                        for (int g = 0; g < group_count; g++)
                        {
                            ILayer        layer_temp    = grouplayer_1.get_Layer(g);
                            IFeatureLayer pFeaturelayer = layer_temp as IFeatureLayer;
                            IFeatureClass pFeatureClass = pFeaturelayer.FeatureClass;
                            #region 将符合线要素的类加入到拓扑中
                            if (pFeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline && pFeatureClass.FeatureType != esriFeatureType.esriFTAnnotation && pFeatureClass.Search(null, false).NextFeature() != null)
                            {
                                list_line.Add(pFeatureClass);//将符合的要素类加入动态数组当中
                            }
                            #endregion
                        }
                        break;
                    }
                    #endregion
                }
                #endregion
                SetCheckState.CheckShowTips(pAppForm, "数据准备完毕,准备进度显示数据,请稍后.....");
                #region 通过过滤后的要素类来进行拓扑检查
                int Count = list_line.Count;//总要遍历的层数
                if (Count == 0)
                {
                    _AppHk.CurrentThread = null;
                    SetCheckState.CheckShowTips(pAppForm, "重复线检查完成!");
                    SetCheckState.Message(pAppForm, "提示", "线重复检查完成!");
                    //选中检查出错列表
                    ClearGrid.CheckDataGridShow(pAppForm, _AppHk);
                    return;
                }
                SetCheckState.TreeIni_Fun(list_line, _AppHk);//初始化树
                SetCheckState.CheckShowTips(pAppForm, "进度数据准备完毕,马上进入拓扑分析,请稍后.....");
                for (int N = 0; N < Count; N++)
                {
                    IFeatureClass TempClass = list_line[N] as IFeatureClass;                    //将对象转成相应的要素类
                    IDataset      ds        = TempClass as IDataset;
                    SetCheckState.TreeCheckFun(ds.Name, N, _AppHk);                             //调用树节点选中
                    ITopologyRule topologyRule = new TopologyRuleClass();                       //实例一个拓扑规则类
                    topologyRule.TopologyRuleType  = esriTopologyRuleType.esriTRTLineNoOverlap; //使用规则的类型(线不重叠)
                    topologyRule.Name              = "www";                                     //给规则取个名
                    topologyRule.OriginClassID     = TempClass.FeatureClassID;
                    topologyRule.AllOriginSubtypes = true;
                    pRuleCont.AddRule(topologyRule);
                    ISegmentCollection pLocation = new PolygonClass();                            //使用多边形接口 实例一个面的片段
                    pLocation.SetRectangle(pGeoDataset.Extent);                                   //将我们用来操作验证的要素类利用SETRECTANGLE来构造一个完整的几何形体
                    IPolygon  pPoly          = SetCheckState.pT.get_DirtyArea(pLocation as IPolygon);
                    IEnvelope pAreaValidated = SetCheckState.pT.ValidateTopology(pPoly.Envelope); //返回利用拓扑规则验证后的出错结果

                    SetCheckState.CheckShowTips(pAppForm, "拓扑分析中,请稍后.....");
                    IErrorFeatureContainer    pErrFeatCon      = SetCheckState.pT as IErrorFeatureContainer;                                                                 //实例一个拓扑出错的容器
                    IEnumTopologyErrorFeature pEnumTopoErrFeat = pErrFeatCon.get_ErrorFeatures(pGeoDataset.SpatialReference, topologyRule, pGeoDataset.Extent, true, false); //将所有的拓扑出错进行枚举
                    int num = N + 1;                                                                                                                                         //由于层的索引是从0开始的,所以得加1

                    ITopologyErrorFeature Topo_ErrFeat = pEnumTopoErrFeat.Next();                                                                                            //开始遍历拓扑错误,表示下一个s
                    ArrayList             TempTopList  = new ArrayList();
                    //将当前层的所有出错要素放入动态数组当中
                    while (Topo_ErrFeat != null)
                    {
                        TempTopList.Add(Topo_ErrFeat);//将出错的要素存入动态数组
                        Topo_ErrFeat = pEnumTopoErrFeat.Next();
                    }
                    SetCheckState.CheckShowTips(pAppForm, "拓扑分析完毕,进行具体检查操作,请稍后.....");
                    int P_count = TempTopList.Count;//每个层的总出错记录
                    if (P_count == 0)
                    {
                        SetCheckState.CheckShowTips(pAppForm, "无重复线准备进行下一个图层操作,请稍后....");
                        continue;
                    }
                    SetCheckState.CheckShowTips(pAppForm, "正在进行" + TempClass.AliasName + "图层操作,请稍后....");
                    pAppForm.MainForm.Invoke(new ShowPrcoessBar(Show_processBar), new object[] { true, pAppForm });//是否显示进度条,加载让它显示
                    #region 遍历出错
                    for (int p = 0; p < P_count; p++)
                    {
                        int i = p + 1;                                                                                            //方便计算
                        pAppForm.MainForm.Invoke(new ProcessBar(ControlProcessBar), new object[] { P_count, 0, 1, i, pAppForm }); //给进度条传需要的值
                        ITopologyErrorFeature pTopoErrFeat = TempTopList[p] as ITopologyErrorFeature;
                        int OriginOID = pTopoErrFeat.OriginOID;                                                                   //源ID

                        int      DestinationOID = pTopoErrFeat.DestinationOID;                                                    //目标ID
                        IFeature source_fe      = TempClass.GetFeature(OriginOID);                                                //源要素
                        IFeature des_fe         = TempClass.GetFeature(DestinationOID);                                           //目标要素

                        ///求几何空间差值,必须要两种情况考虑:a->b  b->a,如果同时都为空,说明两个重复
                        ITopologicalOperator Origin_0     = des_fe.Shape as ITopologicalOperator;              //空间几何运算
                        IGeometry            difference_0 = Origin_0.Difference(source_fe.Shape as IGeometry); //求两个面的差值

                        ITopologicalOperator Origin     = source_fe.Shape as ITopologicalOperator;             //空间几何运算
                        IGeometry            difference = Origin.Difference(des_fe.Shape as IGeometry);        //求两个面的差值

                        if (difference.IsEmpty && difference_0.IsEmpty)
                        {
                            StringBuilder origin_temp      = new StringBuilder(); //除了SHAPE外的字段对比源
                            StringBuilder destination_temp = new StringBuilder(); //除了SHAPE外的字段对比目标

                            ArrayList list  = Foreach();                          //得到我们需要遍历的对比字段
                            int       count = list.Count;
                            if (count > 0)
                            {
                                for (int n = 0; n < count; n++)
                                {
                                    int index = TempClass.GetFeature(OriginOID).Fields.FindFieldByAliasName(list[n].ToString());       //查看我们要对比的字段名是不是存在 源

                                    int index1 = TempClass.GetFeature(DestinationOID).Fields.FindFieldByAliasName(list[n].ToString()); //查看我们要对比的字段名是不是存在 目标
                                    if (index >= 0 && index1 >= 0)
                                    {
                                        origin_temp.Append(TempClass.GetFeature(OriginOID).get_Value(index));
                                        destination_temp.Append(TempClass.GetFeature(DestinationOID).get_Value(index1));
                                    }
                                }
                                if (origin_temp.Equals(destination_temp) && origin_temp != null && destination_temp != null)
                                {
                                    string temp             = ds.Name + " ID:" + OriginOID.ToString() + " 目标ID:" + DestinationOID.ToString();
                                    System.Data.DataRow Row = Datatable.NewRow();
                                    Row[0] = temp;
                                    Datatable.Rows.Add(Row);
                                    SetCheckState.CheckShowTips(pAppForm, temp);
                                }
                                else
                                {
                                    pTopoErrFeat = pEnumTopoErrFeat.Next();
                                    continue;
                                }
                            }
                            else
                            {
                                string temp             = ds.Name + " ID:" + OriginOID.ToString() + " 目标ID:" + DestinationOID.ToString();
                                System.Data.DataRow Row = Datatable.NewRow();
                                Row[0] = temp;
                                Datatable.Rows.Add(Row);
                                SetCheckState.CheckShowTips(pAppForm, temp);
                            }
                        }
                    }
                    #endregion

                    pRuleCont.DeleteRule(topologyRule);//移除拓扑规则

                    if (num == Count)
                    {
                        SetCheckState.CheckShowTips(pAppForm, "重复线检查马上完成,请稍后....");
                        break;
                    }
                }
                pAppForm.MainForm.Invoke(new ShowPrcoessBar(Show_processBar), new object[] { false, pAppForm }); //显示完成隐藏进度条
                pAppForm.MainForm.Invoke(new Update_data(Bind), new object[] { Datatable, _AppHk });             //将窗体控件进行方法的委托,因为得让它成为安全的
                _AppHk.CurrentThread = null;                                                                     //将线程置空
                SetCheckState.CheckShowTips(pAppForm, "重复线检查完成!");
                SetCheckState.Message(pAppForm, "提示", "线重复检查完成!");
                //选中检查出错列表
                ClearGrid.CheckDataGridShow(pAppForm, _AppHk);
                #endregion
            }
            catch (Exception ex)
            {
                _AppHk.CurrentThread = null;//将线程置空
                MessageBox.Show(ex.ToString());
                return;
            }
        }
コード例 #4
0
        /// <summary>
        /// 面套面处理主函数
        /// </summary>
        /// <param name="_AppHk"></param>
        private void ExcutePolygonOverlapTreat()
        {
            Plugin.Application.IAppFormRef pAppFrm = _AppHk as Plugin.Application.IAppFormRef;

            pAppFrm.MainForm.Invoke(new ShowTips(ShowStatusTips), new object[] { pAppFrm, "正在获取所有面层..." });
            //获取所有面层
            List <ILayer> listLayers = GetCheckLayers(_AppHk.MapControl.Map, "更新修编数据");

            if (listLayers == null)
            {
                return;
            }
            List <ILayer> listCheckLays = new List <ILayer>();

            //遍历更新库体里的所有层
            foreach (ILayer pTempLay in listLayers)
            {
                IFeatureLayer pFeatLay = pTempLay as IFeatureLayer;
                if (pFeatLay == null)
                {
                    continue;
                }
                if (pFeatLay.FeatureClass.FeatureType == esriFeatureType.esriFTAnnotation)
                {
                    continue;
                }
                //接边针对的是线和面,所以我们操作时只需对线和面层进行即可
                if (pFeatLay.FeatureClass.ShapeType != esriGeometryType.esriGeometryPolygon)
                {
                    continue;
                }

                listCheckLays.Add(pTempLay);
            }
            if (listCheckLays.Count == 0)
            {
                return;
            }

            //遍历各个面层并与其它面层建立拓扑规则以获取所有存在重叠的最小面
            pAppFrm.MainForm.Invoke(new ShowTips(ShowStatusTips), new object[] { pAppFrm, "正在建立拓扑规则..." });
            Dictionary <ITopologyRule, IFeatureClass> dicTemp = new Dictionary <ITopologyRule, IFeatureClass>();
            ITopologyRuleContainer pTopologyRuleContainer     = SetCheckState.pT as ITopologyRuleContainer;//使用建立好的拓扑

            //遍历我们得出的所有面层并操作
            foreach (ILayer pLay in listCheckLays)
            {
                IFeatureLayer pFeatLay = pLay as IFeatureLayer;
                if (pFeatLay == null)
                {
                    continue;
                }
                ITopologyRule topologyRule = new TopologyRuleClass();                       //实例一个拓扑规则类
                topologyRule.TopologyRuleType  = esriTopologyRuleType.esriTRTAreaNoOverlap; //使用规则的类型(面不相交)
                topologyRule.OriginClassID     = pFeatLay.FeatureClass.FeatureClassID;
                topologyRule.AllOriginSubtypes = true;
                topologyRule.Name = pFeatLay.FeatureClass.AliasName;
                if (pTopologyRuleContainer.get_CanAddRule(topologyRule) == true)//提示拓扑规则是否可以被添加
                {
                    pTopologyRuleContainer.AddRule(topologyRule);
                    dicTemp.Add(topologyRule, pFeatLay.FeatureClass);
                }

                foreach (ILayer pOtherLay in listCheckLays)
                {
                    if (pOtherLay == pLay)
                    {
                        continue;
                    }
                    IFeatureLayer pOtherFeatLay = pOtherLay as IFeatureLayer;
                    if (pOtherFeatLay == null)
                    {
                        continue;
                    }
                    topologyRule = new TopologyRuleClass();
                    topologyRule.TopologyRuleType       = esriTopologyRuleType.esriTRTAreaNoOverlapArea;
                    topologyRule.OriginClassID          = pFeatLay.FeatureClass.FeatureClassID;
                    topologyRule.AllOriginSubtypes      = true;
                    topologyRule.DestinationClassID     = pOtherFeatLay.FeatureClass.FeatureClassID;
                    topologyRule.AllDestinationSubtypes = true;
                    topologyRule.Name = pFeatLay.FeatureClass.AliasName + " AreaNoOverlapArea with " + pOtherFeatLay.FeatureClass.AliasName;
                    if (pTopologyRuleContainer.get_CanAddRule(topologyRule) == true)
                    {
                        pTopologyRuleContainer.AddRule(topologyRule);
                        dicTemp.Add(topologyRule, pFeatLay.FeatureClass);
                    }
                }
            }

            pAppFrm.MainForm.Invoke(new ShowTips(ShowStatusTips), new object[] { pAppFrm, "正在验证拓扑..." });
            ISegmentCollection pLocation = new PolygonClass();                            //使用多边形接口

            pLocation.SetRectangle(SetCheckState.Geodatabase.Extent);                     //将我们用来操作验证的要素类利用SETRECTANGLE来构造一个完整的几何形体
            IPolygon  pPoly          = SetCheckState.pT.get_DirtyArea(pLocation as IPolygon);
            IEnvelope pAreaValidated = SetCheckState.pT.ValidateTopology(pPoly.Envelope); //验证拓扑

            pAppFrm.MainForm.Invoke(new ShowTips(ShowStatusTips), new object[] { pAppFrm, "正在分析获取要处理的要素..." });
            pAppFrm.MainForm.Invoke(new ShowProgress(ShowProgressBar), new object[] { pAppFrm, true });
            pAppFrm.MainForm.Invoke(new ChangeProgress(ChangeProgressBar), new object[] { pAppFrm.ProgressBar, 0, dicTemp.Count, 0 });
            //获取所有存在重叠的最小面
            Dictionary <IFeature, IFeatureClass> dicCheckFeats = new Dictionary <IFeature, IFeatureClass>();
            IErrorFeatureContainer pErrFeatCon = SetCheckState.pT as IErrorFeatureContainer;
            IEnumRule pEnumRule = pTopologyRuleContainer.Rules;

            pEnumRule.Reset();
            ITopologyRule pTempTopologyRule = pEnumRule.Next() as ITopologyRule;
            int           intcnt            = 0;

            while (pTempTopologyRule != null)
            {
                intcnt++;
                pAppFrm.MainForm.Invoke(new ChangeProgress(ChangeProgressBar), new object[] { pAppFrm.ProgressBar, -1, -1, intcnt });
                if (!(pTempTopologyRule.TopologyRuleType == esriTopologyRuleType.esriTRTAreaNoOverlap || pTempTopologyRule.TopologyRuleType == esriTopologyRuleType.esriTRTAreaNoOverlapArea))
                {
                    continue;
                }
                IEnumTopologyErrorFeature pEnumTopoErrFeat = pErrFeatCon.get_ErrorFeatures(SetCheckState.Geodatabase.SpatialReference, pTempTopologyRule, SetCheckState.Geodatabase.Extent, true, false);
                ITopologyErrorFeature     pTopoErrFeat     = pEnumTopoErrFeat.Next();

                IFeatureClass pOrgFeatCls = null;
                if (dicTemp.ContainsKey(pTempTopologyRule))
                {
                    pOrgFeatCls = dicTemp[pTempTopologyRule];
                }
                if (pOrgFeatCls == null)
                {
                    break;
                }
                IDataset pDatasetTemp = pOrgFeatCls as IDataset;
                while (pTopoErrFeat != null)
                {
                    IFeature orgFeat  = pOrgFeatCls.GetFeature(pTopoErrFeat.OriginOID);
                    bool     bHasFeat = false;
                    foreach (ILayer pLay in listCheckLays)
                    {
                        IFeatureLayer pFeatLay = pLay as IFeatureLayer;
                        if (pFeatLay == null)
                        {
                            continue;
                        }
                        IDataset pDataset = pFeatLay.FeatureClass as IDataset;
                        string   strCon   = "";
                        //排除指定要素
                        if (pDataset.Name == pDatasetTemp.Name)
                        {
                            strCon = "OBJECTID<>" + orgFeat.OID.ToString();
                        }

                        //判断面orgFeat内是否包含有面
                        if (HasFeatureWithInGeometry(pFeatLay.FeatureClass, orgFeat.Shape, strCon) == true)
                        {
                            bHasFeat = true;
                            break;
                        }
                    }

                    if (bHasFeat == false)
                    {
                        dicCheckFeats.Add(orgFeat, pOrgFeatCls);
                    }
                    pTopoErrFeat = pEnumTopoErrFeat.Next();
                }

                pTempTopologyRule = pEnumRule.Next() as ITopologyRule;
            }

            pAppFrm.MainForm.Invoke(new ShowTips(ShowStatusTips), new object[] { pAppFrm, "处理数据中..." });
            pAppFrm.MainForm.Invoke(new ChangeProgress(ChangeProgressBar), new object[] { pAppFrm.ProgressBar, 0, dicCheckFeats.Count, 0 });

            Exception err = null;
            //开启编辑  wjj 20090921
            IDataset       pFeatDataset   = SetCheckState.Geodatabase as IDataset;
            IWorkspaceEdit pWorkspaceEdit = pFeatDataset.Workspace as IWorkspaceEdit;

            if (pWorkspaceEdit.IsBeingEdited() == false)
            {
                pWorkspaceEdit.StartEditing(false);
            }

            //遍历上步所获得到的重叠最小面,分析获取包含该面的所有面并根据面积排序
            intcnt = 0;
            foreach (KeyValuePair <IFeature, IFeatureClass> keyvlue in dicCheckFeats)
            {
                intcnt++;
                pAppFrm.MainForm.Invoke(new ChangeProgress(ChangeProgressBar), new object[] { pAppFrm.ProgressBar, -1, -1, intcnt });
                IFeature pFeat = keyvlue.Key;
                Dictionary <IFeature, IFeatureClass> dicFeats = GetFeaturesByGeometry(pFeat, listCheckLays);
                bool bDel = false;
                if (dicFeats.Count > 0)
                {
                    //从外到内做处理,处理原则分类代码相同则利用小面套空大面并删除小面,不同则小面套空大面
                    IFeature[] pFeatArray = new IFeature[dicFeats.Count];
                    dicFeats.Keys.CopyTo(pFeatArray, 0);
                    for (int i = 0; i < dicFeats.Count - 1; i++)
                    {
                        if (bDel == false)
                        {
                            IFeature pBigFeat = pFeatArray[i];
                            IFeature pLowFeat = pFeatArray[i + 1];

                            //小面掏空大面
                            UpdateFeatureByOverlapArea(dicFeats[pBigFeat], "OBJECTID=" + pBigFeat.OID.ToString(), pLowFeat.Shape, out err);
                            if (pBigFeat.get_Value(pBigFeat.Fields.FindField("CODE")).ToString() == pLowFeat.get_Value(pLowFeat.Fields.FindField("CODE")).ToString())
                            {
                                SysCommon.Gis.ModGisPub.DelFeature(dicFeats[pLowFeat], "OBJECTID=" + pLowFeat.OID.ToString(), out err);
                                bDel = true;
                            }
                            else
                            {
                                bDel = false;
                            }
                        }
                        else
                        {
                            bDel = false;
                        }
                    }


                    IFeature pLastFeat = pFeatArray[dicFeats.Count - 1];
                    //小面掏空大面
                    UpdateFeatureByOverlapArea(dicFeats[pLastFeat], "OBJECTID=" + pLastFeat.OID.ToString(), pFeat.Shape, out err);
                    if (pLastFeat.get_Value(pLastFeat.Fields.FindField("CODE")).ToString() == pFeat.get_Value(pFeat.Fields.FindField("CODE")).ToString())
                    {
                        SysCommon.Gis.ModGisPub.DelFeature(dicCheckFeats[pFeat], "OBJECTID=" + pFeat.OID.ToString(), out err);
                        bDel = true;
                    }
                    else
                    {
                        bDel = false;
                    }
                }
            }

            pEnumRule.Reset();
            pTempTopologyRule = pEnumRule.Next() as ITopologyRule;
            while (pTempTopologyRule != null)
            {
                pTopologyRuleContainer.DeleteRule(pTempTopologyRule);
                pTempTopologyRule = pEnumRule.Next() as ITopologyRule;
            }

            //结束编辑 wjj 20090921
            if (pWorkspaceEdit.IsBeingEdited() == true)
            {
                pWorkspaceEdit.StopEditing(true);
            }

            _AppHk.CurrentThread = null;
            pAppFrm.MainForm.Invoke(new ShowTips(ShowStatusTips), new object[] { pAppFrm, "" });
            pAppFrm.MainForm.Invoke(new ShowProgress(ShowProgressBar), new object[] { pAppFrm, false });
            pAppFrm.MainForm.Invoke(new ShowForm(ShowErrForm), new object[] { "提示", "处理完毕!" });
        }
コード例 #5
0
        /// <summary>
        /// The display rectangle.
        /// </summary>
        /// <param name="activeView">
        /// The active view.
        /// </param>
        /// <param name="elm">
        /// The elm.
        /// </param>
        /// <returns>
        /// The <see cref="IPolygon"/>.
        /// </returns>
        public static IPolygon DisplayRectangle(IActiveView activeView, out IElement elm)
        {
            ISegmentCollection segmentCollection = new PolygonClass();

            var tempEnvelope = activeView.Extent;
            CapEnvelope(ref tempEnvelope);
            segmentCollection.SetRectangle(tempEnvelope);

            var polygon = (IPolygon)segmentCollection;
            var rgbColor = VectorIndexColor();
            elm = AddGraphicToMap(activeView.FocusMap, polygon, rgbColor, rgbColor);

            //Best practice: Redraw only the portion of the active view that contains graphics.
            activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
            return polygon;
        }
コード例 #6
0
        /// <summary>
        /// 重复面
        /// </summary>
        private void Cover(object para)
        {
            Plugin.Application.IAppFormRef pAppForm  = para as Plugin.Application.IAppFormRef;
            System.Data.DataTable          Datatable = new System.Data.DataTable();//手动建立一个数据表,将得到的数据邦定到检查结果当中显示

            ///如果检查结果提示内有内容就清除
            ClearDataCheckGrid ClearGrid = new ClearDataCheckGrid();

            ClearGrid.Operate(pAppForm, _AppHk);
            Datatable.Columns.Add("重复面", typeof(string));//创建一列

            #region 打开要操作的数据集

            int L_count = _AppHk.MapControl.LayerCount;//MAP上总图层数
            if (L_count == 0)
            {
                return;              //当MAP上是空,就返回
            }
            SetCheckState.CheckShowTips(pAppForm, "面重复检查开始......");
            IGeoDataset            pGeoDataset = SetCheckState.Geodatabase;
            ITopologyRuleContainer pRuleCont   = SetCheckState.pRuleCont;//引入拓扑规则接口对象,将拓扑转成对应的规则接口对象
            #endregion
            try
            {
                #region 遍历整个数据集要素
                ArrayList list_line = new ArrayList();//用动态的数组来接收满足线要素类的对象,以后面实现遍历拓扑检查
                for (int l = 0; l < L_count; l++)
                {
                    ILayer layer_1 = _AppHk.MapControl.get_Layer(l); //通过索引得到对应的层
                    #region                                          //判别是不是组,如果是,就从组中取一个层
                    if (layer_1 is IGroupLayer && layer_1.Name == SetCheckState.CheckDataBaseName)
                    {
                        ICompositeLayer grouplayer_1 = layer_1 as ICompositeLayer;//把组图层转成组合图层
                        int             group_count  = grouplayer_1.Count;
                        if (group_count == 0)
                        {
                            return;
                        }
                        for (int g = 0; g < group_count; g++)
                        {
                            ILayer        layer_temp    = grouplayer_1.get_Layer(g);
                            IFeatureLayer pFeaturelayer = layer_temp as IFeatureLayer;
                            IFeatureClass pFeatureClass = pFeaturelayer.FeatureClass;
                            #region 将符合线要素的类加入到拓扑中
                            if (pFeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon && pFeatureClass.FeatureType != esriFeatureType.esriFTAnnotation && pFeatureClass.Search(null, false).NextFeature() != null)
                            {
                                list_line.Add(pFeatureClass);//将符合的要素类加入动态数组当中
                            }
                            #endregion
                        }
                    }
                    #endregion
                }
                #endregion
                int Count = list_line.Count;
                if (Count == 0)
                {
                    SetCheckState.CheckShowTips(pAppForm, "重复面检查完成!");
                    _AppHk.CurrentThread = null;
                    SetCheckState.Message(pAppForm, "提示", "面重复检查完成!");
                    //选中检查出错列表
                    ClearGrid.CheckDataGridShow(pAppForm, _AppHk);
                    return;
                }
                if (Count == 0)
                {
                    return;
                }
                SetCheckState.TreeIni_Fun(list_line, _AppHk);//初始化树图
                SetCheckState.CheckShowTips(pAppForm, "检查数据准备完毕,请稍后........");
                #region 通过过滤后的要素类来进行拓扑检查
                for (int N = 0; N < Count; N++)
                {
                    int num = N + 1;//由于层的索引是从0开始的,所以得加1

                    #region 创建拓扑并验证拓扑
                    IFeatureClass TempClass = list_line[N] as IFeatureClass;                    //将对象转成相应的要素类
                    IDataset      ds        = TempClass as IDataset;
                    SetCheckState.TreeCheckFun(ds.Name, N, _AppHk);                             //调用树节点选中方法
                    ITopologyRule topologyRule = new TopologyRuleClass();                       //实例一个拓扑规则类
                    topologyRule.TopologyRuleType  = esriTopologyRuleType.esriTRTAreaNoOverlap; //使用规则的类型(面不相交)
                    topologyRule.Name              = "www";                                     //给规则取个名
                    topologyRule.OriginClassID     = TempClass.FeatureClassID;
                    topologyRule.AllOriginSubtypes = true;
                    pRuleCont.AddRule(topologyRule);


                    ISegmentCollection pLocation = new PolygonClass();                            //使用多边形接口
                    pLocation.SetRectangle(pGeoDataset.Extent);                                   //将我们用来操作验证的要素类利用SETRECTANGLE来构造一个完整的几何形体
                    IPolygon  pPoly          = SetCheckState.pT.get_DirtyArea(pLocation as IPolygon);
                    IEnvelope pAreaValidated = SetCheckState.pT.ValidateTopology(pPoly.Envelope); //验证拓扑

                    SetCheckState.CheckShowTips(pAppForm, "正在进行拓扑分析,请稍后........");
                    IErrorFeatureContainer    pErrFeatCon      = SetCheckState.pT as IErrorFeatureContainer;                                                                 //实例一个拓扑出错的容器
                    IEnumTopologyErrorFeature pEnumTopoErrFeat = pErrFeatCon.get_ErrorFeatures(pGeoDataset.SpatialReference, topologyRule, pGeoDataset.Extent, true, false); //将所有的拓扑出错进行枚举
                    #endregion

                    ITopologyErrorFeature Topo_ErrFeat = pEnumTopoErrFeat.Next();//开始遍历拓扑错误,表示下一个s
                    ArrayList             TempTopList  = new ArrayList();
                    //将当前层的所有出错要素放入动态数组当中
                    while (Topo_ErrFeat != null)
                    {
                        TempTopList.Add(Topo_ErrFeat);//将出错的要素存入动态数组
                        Topo_ErrFeat = pEnumTopoErrFeat.Next();
                    }
                    int P_count = TempTopList.Count;//每个层的总出错记录
                    if (P_count == 0)
                    {
                        SetCheckState.CheckShowTips(pAppForm, "图层完好,准备进行下一个图层,请稍后........");
                        continue;
                    }
                    pAppForm.MainForm.Invoke(new ShowPrcoessBar(Show_processBar), new object[] { true, pAppForm });//是否显示进度条,加载让它显示
                    #region 遍历出错
                    for (int p = 0; p < P_count; p++)
                    {
                        int i = p + 1;                                                                                            //方便计算
                        pAppForm.MainForm.Invoke(new ProcessBar(ControlProcessBar), new object[] { P_count, 0, 1, i, pAppForm }); //给进度条传需要的值
                        ITopologyErrorFeature pTopoErrFeat = TempTopList[p] as ITopologyErrorFeature;
                        int      OriginOID      = pTopoErrFeat.OriginOID;                                                         //源ID
                        int      DestinationOID = pTopoErrFeat.DestinationOID;                                                    //目标ID
                        IFeature source_fe      = TempClass.GetFeature(OriginOID);                                                //源要素
                        IFeature des_fe         = TempClass.GetFeature(DestinationOID);                                           //目标要素
                        #region 通过拓扑出来的错进行再次分析求重复面
                        ///求几何空间差值,必须要两种情况考虑:a->b  b->a,如果同时都为空,说明两个重复
                        ITopologicalOperator Origin_0     = des_fe.Shape as ITopologicalOperator;              //空间几何运算
                        IGeometry            difference_0 = Origin_0.Difference(source_fe.Shape as IGeometry); //求两个面的差值

                        ITopologicalOperator Origin     = source_fe.Shape as ITopologicalOperator;             //空间几何运算
                        IGeometry            difference = Origin.Difference(des_fe.Shape as IGeometry);        //求两个面的差值


                        if (difference.IsEmpty && difference_0.IsEmpty)
                        {
                            #region MyRegion
                            //    StringBuilder origin_temp = new StringBuilder();//除了SHAPE外的字段对比源
                            //    StringBuilder destination_temp = new StringBuilder();//除了SHAPE外的字段对比目标
                            //    //IDataset ds = TempClass as IDataset;
                            //    ArrayList list = Foreach();//调用要对比的XML文件里的字段名
                            //    int count = list.Count;
                            //    #region 通过拓扑出错及对出错的对象再次的进行差值及字段对比,得出最终的结果是否一样
                            //    if (count > 0)
                            //    {
                            //        #region 得到要实际比较的字段值
                            //        for (int n = 0; n < count; n++)
                            //        {
                            //            int index = TempClass.GetFeature(OriginOID).Fields.FindFieldByAliasName(list[n].ToString());//得到源的列ID

                            //            int index1 = TempClass.GetFeature(DestinationOID).Fields.FindFieldByAliasName(list[n].ToString());//得到目标的列ID
                            //            if (index > 0 && index1 > 0)
                            //            {
                            //                origin_temp.Append(TempClass.GetFeature(OriginOID).get_Value(index));//在对应的要素类当中取出源对应ID列的值,加入BUILDER中
                            //                destination_temp.Append(TempClass.GetFeature(DestinationOID).get_Value(index1));//在对应的要素类当中取出目标对应的ID列值,加入目录的BUILDER中
                            //            }
                            //        }
                            //        #endregion
                            //        #region 比较两个值是否一样
                            //        if (origin_temp.ToString() == destination_temp.ToString() && origin_temp != null && destination_temp != null)//将两个列的值进行对比
                            //        {
                            #endregion
                            string temp             = ds.Name + " ID:" + OriginOID.ToString() + " 目标ID:" + DestinationOID.ToString();
                            System.Data.DataRow Row = Datatable.NewRow(); //新创建一个行
                            Row[0] = temp;
                            Datatable.Rows.Add(Row);                      //将行加入到表数据集中
                            SetCheckState.CheckShowTips(pAppForm, temp);
                            #region
                            //        }
                            //        else
                            //        {
                            //            pTopoErrFeat = pEnumTopoErrFeat.Next();//遍历下一个错误
                            //            continue;
                            //        }
                            //        #endregion
                            //    }
                            //    else
                            //    {
                            //        string temp = ds.Name + " ID:" + OriginOID.ToString() + " 目标ID:" + DestinationOID.ToString();//将结果组织起来,放到一个字符串当中
                            //        System.Data.DataRow Row = Datatable.NewRow();//新创建一个行
                            //        Row[0] = temp;
                            //        Datatable.Rows.Add(Row);//将行加入到表数据集中
                            //    }
                            #endregion
                        }
                        #endregion
                    }

                    pRuleCont.DeleteRule(topologyRule);
                    #endregion
                    if (num == Count)
                    {
                        string Case = "马上完成请稍后.....";//状态栏显示
                        SetCheckState.CheckShowTips(pAppForm, Case);
                    }
                }
                #endregion
                pAppForm.MainForm.Invoke(new Update_data(Bind), new object[] { Datatable, _AppHk });             //将窗体控件使用委托
                pAppForm.MainForm.Invoke(new ShowPrcoessBar(Show_processBar), new object[] { false, pAppForm }); //是否显示进度条,加载让它显示
                _AppHk.CurrentThread = null;
                SetCheckState.Message(pAppForm, "提示", "面重复检查完成!");
                //选中检查出错列表
                SetCheckState.CheckShowTips(pAppForm, "面重复检查完成!");
                ClearGrid.CheckDataGridShow(pAppForm, _AppHk);
            }
            catch (Exception ex)
            {
                _AppHk.CurrentThread = null;
                SetCheckState.Message(pAppForm, "错误", ex.ToString());
                return;
            }
        }
コード例 #7
0
        /// <summary>
        /// 悬挂点
        /// </summary>
        private void Point_dangles(object par)
        {
            Plugin.Application.IAppFormRef pAppForm  = par as Plugin.Application.IAppFormRef;
            System.Data.DataTable          Datatable = new System.Data.DataTable(); //手动建立一个数据表,将得到的数据邦定到检查结果当中显示
            Datatable.Columns.Add("悬挂点重复", typeof(string));                         //创建一列
            ///如果检查结果提示内有内容就清除
            ClearDataCheckGrid ClearGrid = new ClearDataCheckGrid();

            ClearGrid.Operate(pAppForm, _AppHk);
            #region 打开要操作的数据集
            if (_AppHk.MapControl.LayerCount == 0)
            {
                return;                                   //如果MAP上打开的图层为空,就返回
            }
            SetCheckState.CheckShowTips(pAppForm, "悬挂点重复检查开始.....");
            int L_count = _AppHk.MapControl.LayerCount;//MAP上总图层数
            if (L_count == 0)
            {
                return;              //当MAP上是空,就返回
            }
            IGeoDataset            pGeoDataset = SetCheckState.Geodatabase;
            ITopologyRuleContainer pRuleCont   = SetCheckState.pT as ITopologyRuleContainer;//引入拓扑规则接口对象,将拓扑转成对应的规则接口对象

            #endregion
            try
            {
                #region 遍历整个数据集要素
                ArrayList list_line = new ArrayList();//用动态的数组来接收满足线要素类的对象,以后面实现遍历拓扑检查
                for (int l = 0; l < L_count; l++)
                {
                    ILayer layer_1 = _AppHk.MapControl.get_Layer(l); //通过索引得到对应的层
                    #region                                          //判别是不是组,如果是,就从组中取一个层
                    if (layer_1 is IGroupLayer)
                    {
                        ICompositeLayer grouplayer_1 = layer_1 as ICompositeLayer;//把组图层转成组合图层
                        int             group_count  = grouplayer_1.Count;
                        if (group_count == 0)
                        {
                            return;
                        }
                        for (int g = 0; g < group_count; g++)
                        {
                            ILayer        layer_temp    = grouplayer_1.get_Layer(g);
                            IFeatureLayer pFeaturelayer = layer_temp as IFeatureLayer;
                            IFeatureClass pFeatureClass = pFeaturelayer.FeatureClass;
                            #region 将符合线要素的类加入到拓扑中
                            if (pFeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline && pFeatureClass.FeatureType != esriFeatureType.esriFTAnnotation && pFeatureClass.Search(null, false).NextFeature() != null)
                            {
                                list_line.Add(pFeatureClass);//将符合的要素类加入动态数组当中
                            }
                            #endregion
                        }
                    }
                    #endregion
                }
                #endregion
                int Count = list_line.Count;//得到拓扑层的总数
                if (Count == 0)
                {
                    return;
                }
                SetCheckState.TreeIni_Fun(list_line, _AppHk);//实始化树图
                #region 通过过滤后的要素类来进行拓扑检查
                for (int N = 0; N < Count; N++)
                {
                    int           num       = N + 1;                                            //由于层的索引是从0开始的,所以得加1
                    IFeatureClass TempClass = list_line[N] as IFeatureClass;                    //将对象转成相应的要素类
                    IDataset      ds        = TempClass as IDataset;
                    SetCheckState.TreeCheckFun(ds.Name, N, _AppHk);                             //调用节点选中方法
                    ITopologyRule topologyRule = new TopologyRuleClass();                       //实例一个拓扑规则类
                    topologyRule.TopologyRuleType  = esriTopologyRuleType.esriTRTLineNoDangles; //使用规则的类型(悬挂点)
                    topologyRule.Name              = "www";                                     //给规则取个名
                    topologyRule.OriginClassID     = TempClass.FeatureClassID;
                    topologyRule.AllOriginSubtypes = true;
                    pRuleCont.AddRule(topologyRule);


                    ISegmentCollection pLocation = new PolygonClass(); //使用多边形接口
                    pLocation.SetRectangle(pGeoDataset.Extent);        //将我们用来操作验证的要素类利用SETRECTANGLE来构造一个完整的几何形体
                    IPolygon  pPoly          = SetCheckState.pT.get_DirtyArea(pLocation as IPolygon);
                    IEnvelope pAreaValidated = SetCheckState.pT.ValidateTopology(pPoly.Envelope);

                    IErrorFeatureContainer    pErrFeatCon      = SetCheckState.pT as IErrorFeatureContainer;                                                                 //实例一个拓扑出错的容器
                    IEnumTopologyErrorFeature pEnumTopoErrFeat = pErrFeatCon.get_ErrorFeatures(pGeoDataset.SpatialReference, topologyRule, pGeoDataset.Extent, true, false); //将所有的拓扑出错进行枚举

                    ITopologyErrorFeature Topo_ErrFeat = pEnumTopoErrFeat.Next();                                                                                            //开始遍历拓扑错误,表示下一个s
                    ArrayList             TempTopList  = new ArrayList();
                    while (Topo_ErrFeat != null)
                    {
                        TempTopList.Add(Topo_ErrFeat);//将出错的要素存入动态数组
                        Topo_ErrFeat = pEnumTopoErrFeat.Next();
                    }
                    #region 遍历出错
                    int P_count = TempTopList.Count;//每个层的总出错记录
                    if (P_count == 0)
                    {
                        pAppForm.MainForm.Invoke(new ShowPrcoessBar(Show_processBar), new object[] { false, pAppForm });//是否显示进度条,加载让它显示
                        SetCheckState.CheckShowTips(pAppForm, "图层完好,无悬挂点!");
                        continue;
                    }
                    pAppForm.MainForm.Invoke(new ShowPrcoessBar(Show_processBar), new object[] { true, pAppForm });//是否显示进度条,加载让它显示
                    #region 遍历错误
                    for (int p = 0; p < P_count; p++)
                    {
                        int i = p + 1;                                                                                            //方便计算
                        pAppForm.MainForm.Invoke(new ProcessBar(ControlProcessBar), new object[] { P_count, 0, 1, i, pAppForm }); //给进度条传需要的值
                        ITopologyErrorFeature pTopoErrFeat = TempTopList[p] as ITopologyErrorFeature;
                        int OriginOID = pTopoErrFeat.OriginOID;                                                                   //源ID
                        if (i % 2 != 0)
                        {
                            string temp             = ds.Name + " 悬挂ID:" + OriginOID.ToString();
                            System.Data.DataRow Row = Datatable.NewRow(); //新创建一个行
                            Row[0] = temp;
                            Datatable.Rows.Add(Row);                      //将行加入到表数据集中
                            SetCheckState.CheckShowTips(pAppForm, temp);
                        }
                    }
                    #endregion

                    pRuleCont.DeleteRule(topologyRule);//删除拓扑规则
                    if (num == Count)
                    {
                        SetCheckState.CheckShowTips(pAppForm, "马上完成,请稍后....");
                    }
                    #endregion
                }
                #endregion
                pAppForm.MainForm.Invoke(new Update_data(Bind), new object[] { Datatable, _AppHk });             //将窗体控件使用委托
                pAppForm.MainForm.Invoke(new ShowPrcoessBar(Show_processBar), new object[] { false, pAppForm }); //是否显示进度条,加载让不显示
                SetCheckState.CheckShowTips(pAppForm, "悬挂点检查完成!");
                _AppHk.CurrentThread = null;
                SetCheckState.Message(pAppForm, "提示", "悬挂点检查完成!");
                //选中检查出错列表
                ClearGrid.CheckDataGridShow(pAppForm, _AppHk);
            }
            catch (Exception ex)
            {
                _AppHk.CurrentThread = null;
                MessageBox.Show(ex.ToString());
                return;
            }
        }
コード例 #8
0
ファイル: BaseTest.cs プロジェクト: EAWCS1/SUITT
        public bool ValidateTopology(ITopology t)
        {
            bool theReturn = false;

            if (t != null)
            {
                try
                {
                    IWorkspaceEdit theWSEdit = t.FeatureDataset.Workspace as IWorkspaceEdit;
                    if (theWSEdit != null)
                    {
                        IGeoDataset theGeoDS = (IGeoDataset)t;
                        ISegmentCollection theSegColl = new PolygonClass();
                        theSegColl.SetRectangle(theGeoDS.Extent);

                        IPolygon theDirtyArea = t.get_DirtyArea((IPolygon)theSegColl);

                        if (theDirtyArea.IsEmpty == false)
                        {
                            bool bNeedStopEdit = false;
                            if (theWSEdit.IsBeingEdited() == false)
                            {
                                theWSEdit.StartEditing(false);
                                bNeedStopEdit = true;
                            }

                            try
                            {
                                theWSEdit.StartEditOperation();
                                t.ValidateTopology(theDirtyArea.Envelope);
                                theWSEdit.StopEditOperation();

                                if (bNeedStopEdit)
                                {
                                    theWSEdit.StopEditing(true);
                                }
                            }
                            catch (Exception ex)
                            {
                                theWSEdit.StopEditing(false);
                                throw ex;
                            }
                        }

                        theReturn = true;
                    }
                }
                catch (Exception ex)
                {
                    this.LogMessage("Exception raised validating topology for " + this.Name + Environment.NewLine
                        + ex.Message + Environment.NewLine + ex.StackTrace);
                }
            }

            return theReturn;
        }
コード例 #9
0
ファイル: ImportToFC.cs プロジェクト: siszoey/geosufan
        //剪裁输出forShp
        public static void cutExportShp(IFeatureCursor pfeaturecursor, IFeatureClass pfeatureclass, IGeometry pgeometry, int featurecount)
        {
            progressStep.Minimum = 0;
            progressStep.Maximum = featurecount;
            progressStep.Step    = 1;
            IFeature pFeature = pfeaturecursor.NextFeature();

            if (pFeature == null)
            {
                return;
            }

            IFeatureCursor pFeatureCursor = pfeatureclass.Insert(true);

            ISegmentCollection pSegmentCol = new PolygonClass();

            if (pgeometry.GeometryType == esriGeometryType.esriGeometryEnvelope)
            {
                IEnvelope pEnvelope = new EnvelopeClass();
                pEnvelope = pgeometry as IEnvelope;
                pSegmentCol.SetRectangle(pEnvelope);
                pgeometry = pSegmentCol as IGeometry;
            }
            else if (pgeometry.GeometryType == esriGeometryType.esriGeometryCircularArc)
            {
                ICircularArc pCircularArc = new CircularArcClass();
                pCircularArc = pgeometry as ICircularArc;
                object obj = System.Reflection.Missing.Value;
                pSegmentCol.AddSegment((ISegment)pCircularArc, ref obj, ref obj);
                pgeometry = pSegmentCol as IGeometry;
            }

            ITopologicalOperator pTopoOp  = (ITopologicalOperator)pgeometry;
            IGeometry            pBndGeom = pTopoOp.Boundary;

            esriGeometryDimension iDimension;

            IGeometry pAimGeometry = pFeature.ShapeCopy;

            if (pAimGeometry.Dimension < pgeometry.Dimension)
            {
                iDimension = pAimGeometry.Dimension;
            }
            else
            {
                iDimension = pgeometry.Dimension;
            }

            int iCount = 0;

            while (pFeature != null)
            {
                IFeatureBuffer pFeatureBuffer = pfeatureclass.CreateFeatureBuffer();
                IFeature       pAimFeature    = (IFeature)pFeatureBuffer;

                pAimGeometry = pFeature.ShapeCopy;
                IRelationalOperator pRelOpeator = (IRelationalOperator)pAimGeometry;

                for (int i = 0; i < pFeature.Fields.FieldCount; i++)
                {
                    //IField pFld = pAimFeature.Fields.get_Field(i);
                    //if ((pFld.Editable == true) && pFld.Type != esriFieldType.esriFieldTypeGeometry)
                    //{
                    //    try
                    //    {
                    //        pAimFeature.set_Value(i, pFeature.get_Value(i));
                    //    }
                    //    catch
                    //    { }
                    //}

                    string sFieldName = pFeature.Fields.get_Field(i).Name;

                    int iIndex = -1;
                    if (m_DicFields.Keys.Contains(sFieldName))
                    {
                        iIndex = pFeatureBuffer.Fields.FindField(m_DicFields[sFieldName]);
                    }
                    else
                    {
                        iIndex = pFeatureBuffer.Fields.FindField(sFieldName);
                    }

                    if (iIndex == -1)
                    {
                        continue;
                    }
                    IField pFld = pAimFeature.Fields.get_Field(iIndex);
                    if ((iIndex > -1) && (pFld.Editable == true) && pFld.Type != esriFieldType.esriFieldTypeGeometry)
                    {
                        pAimFeature.set_Value(iIndex, pFeature.get_Value(i));
                    }
                }

                if (pAimGeometry.GeometryType == esriGeometryType.esriGeometryPoint)
                {
                    pAimFeature.Shape = pFeature.ShapeCopy;
                }
                //判断是否相交或者包含关系,如果是则进行空间切割
                else
                {
                    bool bCross   = false;
                    bool bContain = false;
                    try
                    {
                        bCross = pRelOpeator.Crosses(pBndGeom);//changed by chulili 20111213 这句话可能报错,不要直接放在IF条件里
                    }
                    catch
                    { }
                    try
                    {
                        bContain = pRelOpeator.Contains(pBndGeom);//changed by chulili 20111213 这句话可能报错
                    }
                    catch
                    { }
                    if (bCross || bContain)
                    {
                        pTopoOp = (ITopologicalOperator)pFeature.ShapeCopy;
                        pTopoOp.Simplify();
                        pAimFeature.Shape = pTopoOp.Intersect(pgeometry, iDimension);
                    }
                    else
                    {
                        pAimFeature.Shape = pFeature.ShapeCopy;
                    }
                }
                pFeatureCursor.InsertFeature(pFeatureBuffer);
                if (iCount == 500)
                {
                    pFeatureCursor.Flush();
                    iCount = 0;
                }
                iCount = iCount + 1;
                progressStep.PerformStep();
                pFeature = pfeaturecursor.NextFeature();
            }

            if (iCount > 0)
            {
                pFeatureCursor.Flush();
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureCursor);
            pFeatureCursor = null;
        }
コード例 #10
0
ファイル: FrmNewZHZZT.cs プロジェクト: zhongshuiyuan/gews
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            //1煤2碳化灰岩3粉砂质泥岩4泥岩5泥质粉砂岩
            IWorkspaceEdit workspaceEdit = null;

            try
            {
                labelSC.Visible = true;
                Application.DoEvents();
                //去除无用空行
                for (int i = 0; i < dgrdvZhzzt.RowCount - 1; i++)
                {
                    if (this.dgrdvZhzzt.Rows[i].Cells[0].Value == null &&
                        this.dgrdvZhzzt.Rows[i].Cells[1].Value == null &&
                        this.dgrdvZhzzt.Rows[i].Cells[2].Value == null)
                    {
                        this.dgrdvZhzzt.Rows.RemoveAt(i);
                    }
                }
                //验证
                if (!check())
                {
                    this.DialogResult = DialogResult.None;
                    return;
                }
                this.DialogResult = DialogResult.OK;
                if (isadd)
                {
                    bid = IDGenerator.NewBindingID();
                }
                //实体赋值
                Histogram historam = new Histogram();
                historam.HistogramEntName = txtname.Text.Trim();
                historam.BLC    = Convert.ToDouble(txtBlc.Text.Trim());
                historam.ID     = bid;
                historam.listMY = new List <Historgramlist>();
                double height = 0;
                for (int i = 0; i < dgrdvZhzzt.RowCount - 1; i++)
                {
                    Historgramlist hisl = new Historgramlist();
                    hisl.BID   = bid;
                    hisl.Index = (i + 1);
                    //煤岩名称
                    DataGridViewTextBoxCell cell = dgrdvZhzzt.Rows[i].Cells[0] as DataGridViewTextBoxCell;
                    hisl.MYName  = cell.Value.ToString();
                    cell         = dgrdvZhzzt.Rows[i].Cells[1] as DataGridViewTextBoxCell;
                    hisl.Height  = Convert.ToDouble(cell.Value.ToString());
                    height      += hisl.Height;
                    hisl.SHeight = height;
                    hisl.ZZType  = ZZStrToCode(dgrdvZhzzt.Rows[i].Cells[2].Value.ToString());
                    cell         = dgrdvZhzzt.Rows[i].Cells[3] as DataGridViewTextBoxCell;
                    if (cell.Value != null)
                    {
                        hisl.Describe = cell.Value.ToString();
                    }
                    historam.listMY.Add(hisl);
                }
                if (!isadd)
                {
                    DataEditCommon.DeleteFeatureByWhereClause(frmZhzzt.pFeatureClass, "BID='" + bid + "'");
                }

                progressBar1.Maximum = historam.listMY.Count * 6 + 9;
                progressBar1.Value   = 0;


                IFeatureClass pFeatureClass = frmZhzzt.pFeatureClass;
                progressBar1.Value += 1;
                Application.DoEvents();
                IDataset   dataset   = (IDataset)pFeatureClass;
                IWorkspace workspace = dataset.Workspace;
                workspaceEdit = workspace as IWorkspaceEdit;

                workspaceEdit.StartEditing(true);
                workspaceEdit.StartEditOperation();


                ISegmentCollection pSegmentCollection = new PolygonClass();

                double xbasic = 100;
                double xmin = xbasic, ymin = 99.5, xmax = 110, ymax = 100;

                List <IGeometry> listgeo   = new List <IGeometry>();
                IEnvelope        pEnvelope = new EnvelopeClass();
                pEnvelope.PutCoords(xmin, ymin, xmax, ymax);
                List <ziduan> listzd = new List <ziduan>();
                listzd.Add(new ziduan("textstr", historam.HistogramEntName));
                listzd.Add(new ziduan("zztype", "6"));
                listzd.Add(new ziduan("strtype", "1"));
                listzd.Add(new ziduan("bilici", historam.BLC.ToString()));
                listzd.Add(new ziduan("BID", historam.ID));
                pSegmentCollection.SetRectangle(pEnvelope);
                DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd);
                listgeo.Add(pSegmentCollection as IGeometry);
                progressBar1.Value += 1;
                Application.DoEvents();

                pEnvelope = new EnvelopeClass();
                ymax      = ymin;
                ymin     -= 0.3;
                pEnvelope.PutCoords(xmin, ymin, xmax, ymax);
                listzd = new List <ziduan>();
                listzd.Add(new ziduan("textstr", "比例 1:" + historam.BLC.ToString() + "  单位:米"));
                listzd.Add(new ziduan("zztype", "6"));
                listzd.Add(new ziduan("strtype", "2"));
                listzd.Add(new ziduan("bilici", historam.BLC.ToString()));
                listzd.Add(new ziduan("BID", historam.ID));
                pSegmentCollection = new PolygonClass();
                pSegmentCollection.SetRectangle(pEnvelope);
                DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd);
                listgeo.Add(pSegmentCollection as IGeometry);
                progressBar1.Value += 1;
                Application.DoEvents();

                pEnvelope = new EnvelopeClass();
                ymax      = ymin;
                ymin     -= 0.3; xmax = xmin + 0.6;
                pEnvelope.PutCoords(xmin, ymin, xmax, ymax);
                listzd = new List <ziduan>();
                listzd.Add(new ziduan("textstr", "序号"));
                listzd.Add(new ziduan("zztype", "0"));
                listzd.Add(new ziduan("strtype", "0"));
                listzd.Add(new ziduan("BID", historam.ID));
                pSegmentCollection = new PolygonClass();
                pSegmentCollection.SetRectangle(pEnvelope);
                DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd);
                listgeo.Add(pSegmentCollection as IGeometry);
                progressBar1.Value += 1;
                Application.DoEvents();

                pEnvelope = new EnvelopeClass();
                xmin      = xmax; xmax += 1.8;
                pEnvelope.PutCoords(xmin, ymin, xmax, ymax);
                listzd = new List <ziduan>();
                listzd.Add(new ziduan("textstr", "煤 岩 名 称"));
                listzd.Add(new ziduan("zztype", "0"));
                listzd.Add(new ziduan("strtype", "0"));
                listzd.Add(new ziduan("BID", historam.ID));
                pSegmentCollection = new PolygonClass();
                pSegmentCollection.SetRectangle(pEnvelope);
                DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd);
                listgeo.Add(pSegmentCollection as IGeometry);
                progressBar1.Value += 1;
                Application.DoEvents();

                pEnvelope = new EnvelopeClass();
                xmin      = xmax; xmax += 0.8;
                pEnvelope.PutCoords(xmin, ymin, xmax, ymax);
                listzd = new List <ziduan>();
                listzd.Add(new ziduan("textstr", "真厚"));
                listzd.Add(new ziduan("zztype", "0"));
                listzd.Add(new ziduan("strtype", "0"));
                listzd.Add(new ziduan("BID", historam.ID));
                pSegmentCollection = new PolygonClass();
                pSegmentCollection.SetRectangle(pEnvelope);
                DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd);
                listgeo.Add(pSegmentCollection as IGeometry);
                progressBar1.Value += 1;
                Application.DoEvents();

                pEnvelope = new EnvelopeClass();
                xmin      = xmax; xmax += 1;
                pEnvelope.PutCoords(xmin, ymin, xmax, ymax);
                listzd = new List <ziduan>();
                listzd.Add(new ziduan("textstr", "累厚"));
                listzd.Add(new ziduan("zztype", "0"));
                listzd.Add(new ziduan("strtype", "0"));
                listzd.Add(new ziduan("BID", historam.ID));
                pSegmentCollection = new PolygonClass();
                pSegmentCollection.SetRectangle(pEnvelope);
                DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd);
                listgeo.Add(pSegmentCollection as IGeometry);
                progressBar1.Value += 1;
                Application.DoEvents();

                pEnvelope = new EnvelopeClass();
                xmin      = xmax; xmax += 1.2;
                pEnvelope.PutCoords(xmin, ymin, xmax, ymax);
                listzd = new List <ziduan>();
                listzd.Add(new ziduan("textstr", "柱  状"));
                listzd.Add(new ziduan("zztype", "0"));
                listzd.Add(new ziduan("strtype", "0"));
                listzd.Add(new ziduan("BID", historam.ID));
                pSegmentCollection = new PolygonClass();
                pSegmentCollection.SetRectangle(pEnvelope);
                DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd);
                listgeo.Add(pSegmentCollection as IGeometry);
                progressBar1.Value += 1;
                Application.DoEvents();

                pEnvelope = new EnvelopeClass();
                xmin      = xmax; xmax += 4.6;
                pEnvelope.PutCoords(xmin, ymin, xmax, ymax);
                listzd = new List <ziduan>();
                listzd.Add(new ziduan("textstr", "岩 性 描 述"));
                listzd.Add(new ziduan("zztype", "0"));
                listzd.Add(new ziduan("strtype", "0"));
                listzd.Add(new ziduan("BID", historam.ID));
                pSegmentCollection = new PolygonClass();
                pSegmentCollection.SetRectangle(pEnvelope);
                DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd);
                listgeo.Add(pSegmentCollection as IGeometry);
                progressBar1.Value += 1;
                Application.DoEvents();


                List <Historgramlist> list = historam.ListMY;
                for (int i = 0; i < list.Count; i++)
                {
                    xmin = xbasic;

                    double m_height = list[i].Height;
                    if (m_height < 0.3)
                    {
                        m_height = 0.3;
                    }
                    pEnvelope = new EnvelopeClass();
                    ymax      = ymin;
                    ymin     -= m_height; xmax = xmin + 0.6;
                    pEnvelope.PutCoords(xmin, ymin, xmax, ymax);
                    listzd = new List <ziduan>();
                    listzd.Add(new ziduan("textstr", list[i].Index.ToString()));
                    listzd.Add(new ziduan("xuhaoR", list[i].Index.ToString()));
                    listzd.Add(new ziduan("xuhaoC", "1"));
                    listzd.Add(new ziduan("zztype", "0"));
                    listzd.Add(new ziduan("strtype", "0"));
                    listzd.Add(new ziduan("BID", historam.ID));
                    pSegmentCollection = new PolygonClass();
                    pSegmentCollection.SetRectangle(pEnvelope);
                    DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd);
                    listgeo.Add(pSegmentCollection as IGeometry);
                    progressBar1.Value += 1;
                    Application.DoEvents();

                    pEnvelope = new EnvelopeClass();
                    xmin      = xmax; xmax += 1.8;
                    pEnvelope.PutCoords(xmin, ymin, xmax, ymax);
                    listzd = new List <ziduan>();
                    listzd.Add(new ziduan("textstr", list[i].MYName));
                    listzd.Add(new ziduan("zztype", "0"));
                    listzd.Add(new ziduan("xuhaoR", list[i].Index.ToString()));
                    listzd.Add(new ziduan("xuhaoC", "2"));
                    listzd.Add(new ziduan("strtype", "0"));
                    listzd.Add(new ziduan("BID", historam.ID));
                    pSegmentCollection = new PolygonClass();
                    pSegmentCollection.SetRectangle(pEnvelope);
                    DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd);
                    listgeo.Add(pSegmentCollection as IGeometry);
                    progressBar1.Value += 1;
                    Application.DoEvents();

                    pEnvelope = new EnvelopeClass();
                    xmin      = xmax; xmax += 0.8;
                    pEnvelope.PutCoords(xmin, ymin, xmax, ymax);
                    listzd = new List <ziduan>();
                    listzd.Add(new ziduan("textstr", list[i].Height.ToString()));
                    listzd.Add(new ziduan("zztype", "0"));
                    listzd.Add(new ziduan("xuhaoR", list[i].Index.ToString()));
                    listzd.Add(new ziduan("xuhaoC", "3"));
                    listzd.Add(new ziduan("strtype", "0"));
                    listzd.Add(new ziduan("BID", historam.ID));
                    pSegmentCollection = new PolygonClass();
                    pSegmentCollection.SetRectangle(pEnvelope);
                    DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd);
                    listgeo.Add(pSegmentCollection as IGeometry);
                    progressBar1.Value += 1;
                    Application.DoEvents();

                    pEnvelope = new EnvelopeClass();
                    xmin      = xmax; xmax += 1;
                    pEnvelope.PutCoords(xmin, ymin, xmax, ymax);
                    listzd = new List <ziduan>();
                    listzd.Add(new ziduan("textstr", Math.Round(list[i].SHeight, 1).ToString()));
                    listzd.Add(new ziduan("zztype", "0"));
                    listzd.Add(new ziduan("xuhaoR", list[i].Index.ToString()));
                    listzd.Add(new ziduan("xuhaoC", "4"));
                    listzd.Add(new ziduan("strtype", "0"));
                    listzd.Add(new ziduan("BID", historam.ID));
                    pSegmentCollection = new PolygonClass();
                    pSegmentCollection.SetRectangle(pEnvelope);
                    DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd);
                    listgeo.Add(pSegmentCollection as IGeometry);
                    progressBar1.Value += 1;
                    Application.DoEvents();

                    pEnvelope = new EnvelopeClass();
                    xmin      = xmax; xmax += 1.2;
                    pEnvelope.PutCoords(xmin, ymin, xmax, ymax);
                    listzd = new List <ziduan>();
                    listzd.Add(new ziduan("textstr", ""));
                    listzd.Add(new ziduan("zztype", list[i].ZZType));
                    listzd.Add(new ziduan("xuhaoR", list[i].Index.ToString()));
                    listzd.Add(new ziduan("xuhaoC", "5"));
                    listzd.Add(new ziduan("strtype", "0"));
                    listzd.Add(new ziduan("BID", historam.ID));
                    pSegmentCollection = new PolygonClass();
                    pSegmentCollection.SetRectangle(pEnvelope);
                    DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd);
                    listgeo.Add(pSegmentCollection as IGeometry);
                    progressBar1.Value += 1;
                    Application.DoEvents();

                    pEnvelope = new EnvelopeClass();
                    xmin      = xmax; xmax += 4.6;
                    pEnvelope.PutCoords(xmin, ymin, xmax, ymax);
                    listzd = new List <ziduan>();
                    string strms   = list[i].Describe;
                    string miaoshu = "";
                    if (strms != null && strms.Length > 0)
                    {
                        ASCIIEncoding ascii  = new ASCIIEncoding();
                        int           temLen = 0;
                        byte[]        s      = ascii.GetBytes(strms);

                        for (int j = 0; j < s.Length; j++)
                        {
                            if ((int)s[j] == 63)
                            {
                                temLen += 2;
                            }
                            else
                            {
                                temLen += 1;
                            }
                            miaoshu += strms[j];
                            if (temLen % 38 == 0 || (temLen + 1) % 38 == 0)
                            {
                                if (miaoshu.LastIndexOf('|') != miaoshu.Length - 1)
                                {
                                    miaoshu += "|";
                                }
                            }
                        }
                    }

                    listzd.Add(new ziduan("textstr", miaoshu));
                    listzd.Add(new ziduan("zztype", "0"));
                    listzd.Add(new ziduan("xuhaoR", list[i].Index.ToString()));
                    listzd.Add(new ziduan("xuhaoC", "6"));
                    listzd.Add(new ziduan("strtype", "3"));
                    listzd.Add(new ziduan("BID", historam.ID));
                    pSegmentCollection = new PolygonClass();
                    pSegmentCollection.SetRectangle(pEnvelope);
                    DataEditCommon.CreateFeatureNoEditor(pFeatureClass, (IGeometry)pSegmentCollection, listzd);
                    listgeo.Add(pSegmentCollection as IGeometry);
                    progressBar1.Value += 1;
                    Application.DoEvents();
                }
                workspaceEdit.StopEditOperation();
                workspaceEdit.StopEditing(true);

                frmZhzzt.pGeometry = MyMapHelp.GetGeoFromGeos(listgeo);
                frmZhzzt.BID       = historam.ID;
                frmZhzzt.blc       = historam.BLC;

                DialogResult = DialogResult.OK;
                this.Close();
                if (!isadd)
                {
                    frmZhzzt.refresh();
                }
            }
            catch (Exception ex)
            {
                labelSC.Visible = false;
                MessageBox.Show(ex.Message);
                if (workspaceEdit != null)
                {
                    workspaceEdit.AbortEditOperation();
                    workspaceEdit.StopEditing(false);
                }
            }
        }
        protected override void OnMouseDown(MouseEventArgs arg)
        {
            IFeatureLayer pPointLayer     = null;
            IFeatureLayer pLineLayer      = null;
            IArray        pParcelLayers   = null;
            IFeatureLayer pControlLayer   = null;
            IFeatureLayer pLinePointLayer = null;

            double         dXYTol      = 0.003;
            clsFabricUtils FabricUTILS = new clsFabricUtils();
            IEditor        pEd         = (IEditor)ArcMap.Application.FindExtensionByName("esri object editor");

            //first get the extension
            UID pUID = new UIDClass();

            pUID.Value = "{114D685F-99B7-4B63-B09F-6D1A41A4DDC1}";
            ICadastralExtensionManager2 pCadExtMan = (ICadastralExtensionManager2)ArcMap.Application.FindExtensionByCLSID(pUID);
            ICadastralEditor            pCadEd     = (ICadastralEditor)ArcMap.Application.FindExtensionByCLSID(pUID);

            //check if there is a Manual Mode "modify" job active ===========
            ICadastralPacketManager pCadPacMan = (ICadastralPacketManager)pCadExtMan;

            if (pCadPacMan.PacketOpen)
            {
                FabricUTILS.ExecuteCommand(m_CommUID);
                MessageBox.Show("This tool cannot be used when there is an open parcel, construction, or job.\r\nPlease complete or discard the open items, and try again.");
                return;
            }

            ICadastralFabric pCadFabric = null;

            //if we're in an edit session then grab the target fabric
            if (pEd.EditState == esriEditState.esriStateEditing)
            {
                pCadFabric = pCadEd.CadastralFabric;
            }
            else
            {
                FabricUTILS.ExecuteCommand(m_CommUID);
                MessageBox.Show("This tool works on a parcel fabric in an edit session.\r\nPlease start editing and try again.");
                return;
            }

            if (pCadFabric == null)
            {//find the first fabric in the map
                if (!FabricUTILS.GetFabricFromMap(ArcMap.Document.ActiveView.FocusMap, out pCadFabric))
                {
                    FabricUTILS.ExecuteCommand(m_CommUID);
                    MessageBox.Show("No Parcel Fabric found in the map.\r\nPlease add a single fabric to the map, and try again.");
                    return;
                }
            }

            IGeoDataset pGeoDS = (IGeoDataset)pCadFabric;
            ISpatialReferenceTolerance pSpatRefTol = (ISpatialReferenceTolerance)pGeoDS.SpatialReference;

            if (pSpatRefTol.XYToleranceValid == esriSRToleranceEnum.esriSRToleranceOK)
            {
                dXYTol = pSpatRefTol.XYTolerance;
            }

            IMouseCursor          pMouseCursor        = null;
            ISpatialFilter        pSpatFilt           = null; //spatial filter query hinging off the dragged rectangle selection
            IQueryFilter          pQuFilter           = null; //used for the non-spatial query for radial lines, as they have no geometry
            IRubberBand2          pRubberRect         = null;
            IGeometryBag          pGeomBag            = null;
            ITopologicalOperator5 pUnionedPolyine     = null;
            IPolygon      pBufferedToolSelectGeometry = null;         //geometry used to search for parents
            IFIDSet       pLineFIDs            = null;                //the FIDSet used to collect the lines that'll be deleted
            IFIDSet       pPointFIDs           = null;                // the FIDSet used to collect the points that'll be deleted
            IFIDSet       pLinePointFIDs       = null;                // the FIDSet used to collect the line-points that'll be deleted
            List <int>    pDeletedLinesPoints  = new List <int>();    //list used to stage the ids for points that are referenced by lines
            List <int>    pUsedPoints          = new List <int>();    //list used to collect pointids that are referenced by existing lines
            List <int>    CtrPointIDList       = new List <int>();    //list for collecting the ids of center points
            List <int>    pParcelsList         = new List <int>();    //used only to avoid adding duplicates to IN clause string for, based on ties to radial lines
            List <int>    pOrphanPointsList    = new List <int>();    //list of orphan points defined from radial ines
            List <int>    pPointsInsideBoxList = new List <int>();    //list of parcels that exist and that intersect the drag-box
            List <string> sFromToPair          = new List <string>(); //list of from/to pairs for manging line points
            List <int>    pLineToParcelIDRef   = new List <int>();    //list of parcel id refs stored on lines

            IInvalidArea3 pInvArea = null;

            IFeatureClass pLines      = null;
            IFeatureClass pPoints     = null;
            IFeatureClass pParcels    = null;
            IFeatureClass pLinePoints = null;
            IWorkspace    pWS         = null;

            try
            {
                #region define the rubber envelope geometry
                pRubberRect = new RubberEnvelopeClass();
                IGeometry ToolSelectEnvelope = pRubberRect.TrackNew(ArcMap.Document.ActiveView.ScreenDisplay, null);

                if (ToolSelectEnvelope == null)
                {
                    return;
                }

                ISegmentCollection pSegmentColl = new PolygonClass();
                pSegmentColl.SetRectangle(ToolSelectEnvelope.Envelope);
                IPolygon ToolSelectGeometry = (IPolygon)pSegmentColl;

                if (pCadFabric == null)
                {
                    return;
                }

                pMouseCursor = new MouseCursorClass();
                pMouseCursor.SetCursor(2);

                #endregion

                FabricUTILS.GetFabricSubLayersFromFabric(ArcMap.Document.ActiveView.FocusMap, pCadFabric,
                                                         out pPointLayer, out pLineLayer, out pParcelLayers, out pControlLayer,
                                                         out pLinePointLayer);

                #region get tables and field indexes
                pLines      = (IFeatureClass)pCadFabric.get_CadastralTable(esriCadastralFabricTable.esriCFTLines);
                pPoints     = (IFeatureClass)pCadFabric.get_CadastralTable(esriCadastralFabricTable.esriCFTPoints);
                pParcels    = (IFeatureClass)pCadFabric.get_CadastralTable(esriCadastralFabricTable.esriCFTParcels);
                pLinePoints = (IFeatureClass)pCadFabric.get_CadastralTable(esriCadastralFabricTable.esriCFTLinePoints);
                string sPref = "";
                string sSuff = "";

                int iCtrPtFldIDX  = pLines.FindField("CENTERPOINTID");
                int iFromPtFldIDX = pLines.FindField("FROMPOINTID");
                int iToPtFldIDX   = pLines.FindField("TOPOINTID");
                int iCatFldIDX    = pLines.FindField("CATEGORY");
                int iParcelIDX    = pLines.FindField("PARCELID");
                int iDistanceIDX  = pLines.FindField("DISTANCE");


                pWS = pLines.FeatureDataset.Workspace;
                ISQLSyntax pSQLSyntax = (ISQLSyntax)pWS;
                sPref = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierPrefix);
                sSuff = pSQLSyntax.GetSpecialCharacter(esriSQLSpecialCharacters.esriSQL_DelimitedIdentifierSuffix);

                pSpatFilt            = new SpatialFilterClass();
                pSpatFilt.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                pSpatFilt.Geometry   = ToolSelectGeometry;
                #endregion

                #region center point
                //need to make sure that center points are correctly handled for cases where the center point
                //is inside the select box, but the curve itself is not. The following is used to build an
                //IN CLAUSE for All the center points that are found within the tool's select geometry.
                int    iIsCtrPtIDX    = pPoints.FindField("CENTERPOINT");
                int    iCount         = 0;
                int    iCntCtrPoint   = 0;
                string sCtrPntIDList1 = "";

                IFeatureCursor pFeatCursPoints = pPoints.Search(pSpatFilt, false);
                IFeature       pFeat7          = pFeatCursPoints.NextFeature();
                while (pFeat7 != null)
                {
                    iCount++;
                    int    iVal     = -1;
                    object Attr_val = pFeat7.get_Value(iIsCtrPtIDX);

                    if (Attr_val != DBNull.Value)
                    {
                        iVal = Convert.ToInt32(pFeat7.get_Value(iIsCtrPtIDX));
                    }

                    if (iVal == 1)
                    {
                        if (sCtrPntIDList1.Trim() == "")
                        {
                            sCtrPntIDList1 += pFeat7.OID.ToString();
                        }
                        else
                        {
                            sCtrPntIDList1 += "," + pFeat7.OID.ToString();
                        }
                        iCntCtrPoint++;
                    }
                    pPointsInsideBoxList.Add(pFeat7.OID); //used to check for orphan linepoints
                    pOrphanPointsList.Add(pFeat7.OID);    //this gets whittled down till only "pure" orphan points remain
                    Marshal.ReleaseComObject(pFeat7);
                    pFeat7 = pFeatCursPoints.NextFeature();
                }
                Marshal.FinalReleaseComObject(pFeatCursPoints);
                #endregion

                #region create convex hull of lines
                //get the lines that intersect the search box and build a
                //polygon search geometry being the convex hull of those lines.
                IFeatureCursor pFeatCursLines = pLines.Search(pSpatFilt, false);
                pGeomBag = new GeometryBagClass();
                IGeometryCollection pGeomColl = (IGeometryCollection)pGeomBag;
                IFeature            pFeat1    = pFeatCursLines.NextFeature();
                m_sDebug = "Add lines to Geometry Collection.";
                string sParcelRefOnLines = "";
                object missing           = Type.Missing;
                while (pFeat1 != null)
                {
                    int    iVal    = (int)pFeat1.get_Value(iFromPtFldIDX);
                    string sFromTo = iVal.ToString() + ":";

                    if (pOrphanPointsList.Contains(iVal)) //Does this need to be done...will remove fail if it's not there?
                    {
                        pOrphanPointsList.Remove(iVal);   //does this need to be in the if block?
                    }
                    iVal     = (int)pFeat1.get_Value(iToPtFldIDX);
                    sFromTo += iVal.ToString();
                    if (pOrphanPointsList.Contains(iVal))
                    {
                        pOrphanPointsList.Remove(iVal);
                    }

                    sFromToPair.Add(sFromTo);
                    pGeomColl.AddGeometry(pFeat1.ShapeCopy, missing, missing);

                    if (sParcelRefOnLines.Trim() == "")
                    {
                        sParcelRefOnLines = pFeat1.get_Value(iParcelIDX).ToString();
                    }
                    else
                    {
                        sParcelRefOnLines += "," + pFeat1.get_Value(iParcelIDX).ToString();
                    }

                    Marshal.ReleaseComObject(pFeat1);
                    pFeat1 = pFeatCursLines.NextFeature();
                }
                Marshal.FinalReleaseComObject(pFeatCursLines);

                #endregion

                #region Add Center Points for curves outside map extent

                if (iCntCtrPoint > 999)
                {
                    throw new InvalidOperationException("The Delete Orphans tool works with smaller amounts of data." + Environment.NewLine +
                                                        "Please try again, by selecting fewer fabric lines and points. (More than 1000 center points returned.)");
                }

                //If there is no line geometry found, and there are also no points found, then nothing to do...
                if (pGeomColl.GeometryCount == 0 && iCount == 0)
                {
                    return;
                }

                //Radial lines have no geometry so there is a special treatment for those;
                //that special treatment takes two forms,
                //1. if a circular arc is selected and it turns out that it is an orphan line, then we
                //need to take down its radial lines, and its center point as well.
                //2. if a center point is selected, we need to check if it's an orphan, by searching for its parent.
                //The parent parcel can easily be well beyond the query rectangle, so the original
                //search rectangle is buffered by the largest found radius distance, to make sure that all
                //parent parcels are "find-able."

                //The radial lines themselves are also needed; Get the radial lines from the Center Points
                //CtrPt is always TO point, so find lines CATEGORY = 4 AND TOPOINT IN ()
                string sRadialLineListParcelID = "";
                string sRadialLinesID          = "";
                string sRadialLinePoints       = "";

                double dRadiusBuff = 0;
                pQuFilter = new QueryFilterClass();
                //Find all the radial lines based on the search query
                if (sCtrPntIDList1.Trim() != "")
                {
                    pQuFilter.WhereClause = "CATEGORY = 4 AND TOPOINTID IN (" + sCtrPntIDList1 + ")";

                    //add all the *references* to Parcel ids for the radial lines,
                    //and add the ID's of the lines
                    IFeatureCursor pFeatCursLines8 = pLines.Search(pQuFilter, false);
                    IFeature       pFeat8          = pFeatCursLines8.NextFeature();
                    while (pFeat8 != null)
                    {
                        object Attr_val = pFeat8.get_Value(iDistanceIDX);
                        double dVal     = 0;
                        if (Attr_val != DBNull.Value)
                        {
                            dVal = Convert.ToDouble(Attr_val);
                        }
                        dRadiusBuff = dRadiusBuff > dVal ? dRadiusBuff : dVal;
                        int iVal = Convert.ToInt32(pFeat8.get_Value(iParcelIDX));
                        if (!pParcelsList.Contains(iVal))
                        {
                            if (sRadialLineListParcelID.Trim() == "")
                            {
                                sRadialLineListParcelID += Convert.ToString(iVal);
                            }
                            else
                            {
                                sRadialLineListParcelID += "," + Convert.ToString(iVal);
                            }
                        }
                        pParcelsList.Add(iVal);

                        //pOrphanPointsList is used for "Pure Orphan point" detection
                        //meaning that these are points that do not have ANY line, not even an orphan line.
                        iVal = (int)pFeat8.get_Value(iFromPtFldIDX);
                        if (pOrphanPointsList.Contains(iVal))
                        {
                            pOrphanPointsList.Remove(iVal);
                        }

                        iVal = (int)pFeat8.get_Value(iToPtFldIDX);
                        if (pOrphanPointsList.Contains(iVal))
                        {
                            pOrphanPointsList.Remove(iVal);
                        }

                        if (sRadialLinesID.Trim() == "")
                        {
                            sRadialLinesID += Convert.ToString(iVal);
                        }
                        else
                        {
                            sRadialLinesID += "," + Convert.ToString(iVal);
                        }

                        //Add from point to list
                        if (sRadialLinePoints.Trim() == "")
                        {
                            sRadialLinePoints += Convert.ToString(pFeat8.get_Value(iFromPtFldIDX));
                        }
                        else
                        {
                            sRadialLinePoints += "," + Convert.ToString(pFeat8.get_Value(iFromPtFldIDX));
                        }
                        //Add To point to list
                        sRadialLinePoints += "," + Convert.ToString(pFeat8.get_Value(iToPtFldIDX));

                        Marshal.ReleaseComObject(pFeat8);
                        pFeat8 = pFeatCursLines8.NextFeature();
                    }
                    Marshal.FinalReleaseComObject(pFeatCursLines8);

                    //create a polygon goeometry that is a buffer of the selection rectangle expanded
                    //to the greatest radius of all the radial lines found.
                    ITopologicalOperator topologicalOperator = (ITopologicalOperator)ToolSelectGeometry;
                    pBufferedToolSelectGeometry = topologicalOperator.Buffer(dRadiusBuff) as IPolygon;
                }
                else
                {
                    pQuFilter.WhereClause = "";
                }
                #endregion

                #region OrphanLines

                if (pGeomColl.GeometryCount != 0)
                {
                    pUnionedPolyine = new PolylineClass();
                    pUnionedPolyine.ConstructUnion((IEnumGeometry)pGeomBag);
                    ITopologicalOperator pTopoOp     = (ITopologicalOperator)pUnionedPolyine;
                    IGeometry            pConvexHull = pTopoOp.ConvexHull();
                    //With this convex hull, do a small buffer,
                    //theis search geometry is used as a spatial query on the parcel polygons
                    //and also on the parcel lines, to build IN Clauses
                    pTopoOp = (ITopologicalOperator)pConvexHull;
                    IGeometry pBufferedConvexHull = pTopoOp.Buffer(10 * dXYTol);
                    if (pBufferedToolSelectGeometry != null)
                    {
                        pTopoOp = (ITopologicalOperator)pBufferedToolSelectGeometry;
                        IGeometry pUnionPolygon = pTopoOp.Union(pBufferedConvexHull);
                        pSpatFilt.Geometry = pUnionPolygon;
                    }
                    else
                    {
                        pSpatFilt.Geometry = pBufferedConvexHull;
                    }
                }
                else
                {
                    if (pQuFilter.WhereClause.Trim() == "" && pBufferedToolSelectGeometry == null)
                    {
                        pSpatFilt.Geometry = ToolSelectGeometry;
                    }
                    else
                    {
                        pSpatFilt.Geometry = pBufferedToolSelectGeometry;
                    }
                }

                IColor pColor = new RgbColorClass();
                pColor.RGB = System.Drawing.Color.Blue.ToArgb();
                IScreenDisplay pScreenDisplay = ArcMap.Document.ActiveView.ScreenDisplay;
                FabricUTILS.FlashGeometry(pSpatFilt.Geometry, pScreenDisplay, pColor, 5, 100);

                pSpatFilt.SearchOrder = esriSearchOrder.esriSearchOrderSpatial;

                m_sDebug = "Searching Parcels table.";
                pInvArea = new InvalidAreaClass();
                IFeatureCursor pFeatCursParcels = pParcels.Search(pSpatFilt, false);
                IFeature       pFeat2           = pFeatCursParcels.NextFeature();
                string         sParcelIDList    = "";
                iCount = 0;
                //create the "NOT IN" CLAUSE for parcels that exist in the DB and that are within the search area
                //Will be used as a search on lines to get the Orphan Lines

                while (pFeat2 != null)
                {
                    iCount++;
                    if (sParcelIDList.Trim() == "")
                    {
                        sParcelIDList += pFeat2.OID.ToString();
                    }
                    else
                    {
                        sParcelIDList += "," + pFeat2.OID.ToString();
                    }

                    Marshal.ReleaseComObject(pFeat2);
                    if (iCount > 999)
                    {
                        break;
                    }
                    pFeat2 = pFeatCursParcels.NextFeature();
                }
                Marshal.FinalReleaseComObject(pFeatCursParcels);

                //if we have more than 999 in clause tokens, there will be problems on Oracle.
                //Since this is an interactive tool, we expect it not to be used on a large amount of data.
                //for this reason, the following message is displayed if more than 999 parcels are returned in this query.
                //TODO: for the future this can be made to work on larger sets of data.
                if (iCount > 999)
                {
                    throw new InvalidOperationException("The Delete Orphans tool works with smaller amounts of data." + Environment.NewLine +
                                                        "Please try again, by selecting fewer fabric lines and points. (More than 1000 parcels returned.)");
                }

                m_sDebug = "Building the used points list.";
                //This first pass contains all references to points found within the parent parcel search buffer
                //Later, points are removed from this list
                IFeatureCursor pFeatCursLargerLineSet = pLines.Search(pSpatFilt, false);
                IFeature       pFeat3 = pFeatCursLargerLineSet.NextFeature();
                while (pFeat3 != null)
                {
                    iCount++;
                    object Attr_val = pFeat3.get_Value(iCtrPtFldIDX);
                    if (Attr_val != DBNull.Value)
                    {
                        pUsedPoints.Add(Convert.ToInt32(Attr_val)); //add center point
                    }
                    int iVal = (int)pFeat3.get_Value(iFromPtFldIDX);
                    pUsedPoints.Add(iVal);//add from point

                    iVal = (int)pFeat3.get_Value(iToPtFldIDX);
                    pUsedPoints.Add(iVal);//add to point

                    Marshal.ReleaseComObject(pFeat3);
                    pFeat3 = pFeatCursLargerLineSet.NextFeature();
                }
                Marshal.FinalReleaseComObject(pFeatCursLargerLineSet);

                //pUsedPoints list is at this stage, references to points for all lines found within the search area.
                //use the IN clause of the parcel ids to search for lines within
                //the original search box, and that are also orphans that do not have a parent parcel.
                pSpatFilt.WhereClause = "";
                pSpatFilt.Geometry    = ToolSelectGeometry;
                pSpatFilt.SpatialRel  = esriSpatialRelEnum.esriSpatialRelIntersects;
                pSpatFilt.SearchOrder = esriSearchOrder.esriSearchOrderSpatial;

                IFeatureCursor pFeatCursor = null;
                if (pGeomColl.GeometryCount == 0)
                {
                    if (sParcelIDList.Trim().Length > 0 && sCtrPntIDList1.Trim().Length > 0)
                    {
                        pQuFilter.WhereClause = "(PARCELID NOT IN (" + sParcelIDList +
                                                ")) AND (CATEGORY = 4 AND TOPOINTID IN (" + sCtrPntIDList1 + "))";
                        pFeatCursor = pLines.Search(pQuFilter, false);
                    }
                    else if (sParcelIDList.Trim().Length == 0 && sCtrPntIDList1.Trim().Length > 0)
                    {
                        pQuFilter.WhereClause = "CATEGORY = 4 AND TOPOINTID IN (" + sCtrPntIDList1 + ")";
                        pFeatCursor           = pLines.Search(pQuFilter, false);
                    }
                }
                else
                {//do a spatial query
                    if (sParcelIDList.Trim().Length > 0)
                    {
                        pSpatFilt.WhereClause = "PARCELID NOT IN (" + sParcelIDList + ")";
                    }
                    else
                    {
                        pSpatFilt.WhereClause = "";
                    }
                    pFeatCursor = pLines.Search(pSpatFilt, false);
                }

                m_sDebug = "Collecting lines to be deleted.";

                //start collecting the lines that need to be deleted
                iCount = 0;
                int    iCtrPointCount         = 0;
                string sCtrPointIDList        = "";
                string sLineParcelIDReference = "";
                //Feature cursor is lines that are NOT IN the ParcelIDList

                if (pFeatCursor != null)
                {
                    pLineFIDs = new FIDSetClass();
                    IFeature pFeat4 = pFeatCursor.NextFeature();
                    while (pFeat4 != null)
                    {
                        iCount++;
                        pLineFIDs.Add(pFeat4.OID);
                        int iParcRef = Convert.ToInt32(pFeat4.get_Value(iParcelIDX));
                        if (sLineParcelIDReference.Trim() == "")
                        {
                            sLineParcelIDReference = iParcRef.ToString();
                        }
                        else
                        {
                            if (!pLineToParcelIDRef.Contains(iParcRef))
                            {
                                sLineParcelIDReference += "," + iParcRef.ToString();
                            }
                        }
                        pLineToParcelIDRef.Add(iParcRef);
                        pInvArea.Add((IObject)pFeat4);
                        //now for this line, get it's points
                        //first add the center point reference if there is one
                        object Attr_val = pFeat4.get_Value(iCtrPtFldIDX);
                        if (Attr_val != DBNull.Value)
                        {
                            iCtrPointCount++;
                            int iCtrPointID = Convert.ToInt32(Attr_val);
                            pDeletedLinesPoints.Add(iCtrPointID); //add this line's center point
                            pUsedPoints.Remove(iCtrPointID);

                            if (sCtrPointIDList.Trim() == "")
                            {
                                sCtrPointIDList = iCtrPointID.ToString();
                            }
                            else
                            {
                                if (CtrPointIDList.Contains(iCtrPointID))
                                {
                                    iCtrPointCount--;
                                }
                                else
                                {
                                    sCtrPointIDList += "," + iCtrPointID.ToString();
                                }
                            }
                            CtrPointIDList.Add(iCtrPointID);//to keep track of repeats
                        }
                        //and also add the FROM and TO point references if they exist
                        int iVal = (int)pFeat4.get_Value(iFromPtFldIDX);
                        pDeletedLinesPoints.Add(iVal);//add FROM point
                        if (pGeomColl.GeometryCount > 0)
                        {
                            pUsedPoints.Remove(iVal);
                        }

                        iVal = (int)pFeat4.get_Value(iToPtFldIDX);
                        pDeletedLinesPoints.Add(iVal);//add TO point
                        if (pGeomColl.GeometryCount > 0)
                        {
                            pUsedPoints.Remove(iVal);
                        }

                        Marshal.ReleaseComObject(pFeat4);
                        if (iCtrPointCount > 999)
                        {
                            break;
                        }
                        pFeat4 = pFeatCursor.NextFeature();
                    }
                    Marshal.FinalReleaseComObject(pFeatCursor);
                }
                if (iCtrPointCount > 999)
                {
                    throw new InvalidOperationException("The Delete Orphans tool works with smaller amounts of data." + Environment.NewLine +
                                                        "Please try again, by selecting fewer fabric lines and points. (More than 1000 center points returned.)");
                }

                m_sDebug = "Adding orphan radial lines to list.";

                if (sCtrPointIDList.Trim().Length > 0)
                {
                    //add the Radial lines at each end of the curves using the collected CtrPtIDs
                    //CtrPt is always TO point, so find lines CATEGORY = 4 AND TOPOINT IN ()

                    pQuFilter.WhereClause = "CATEGORY = 4 AND TOPOINTID IN (" + sCtrPointIDList + ")";
                    pFeatCursor           = pLines.Search(pQuFilter, false);
                    IFeature pFeat5 = pFeatCursor.NextFeature();
                    while (pFeat5 != null)
                    {
                        pLineFIDs.Add(pFeat5.OID);
                        int iParcRef = Convert.ToInt32(pFeat5.get_Value(iParcelIDX));
                        pLineToParcelIDRef.Add(iParcRef);
                        if (sLineParcelIDReference.Trim() == "")
                        {
                            sLineParcelIDReference = iParcRef.ToString();
                        }
                        else
                        {
                            if (!pLineToParcelIDRef.Contains(iParcRef))
                            {
                                sLineParcelIDReference += "," + iParcRef.ToString();
                            }
                        }
                        Marshal.ReleaseComObject(pFeat5);
                        pFeat5 = pFeatCursor.NextFeature();
                    }
                    Marshal.FinalReleaseComObject(pFeatCursor);
                }
                else
                {
                    pQuFilter.WhereClause = "";
                }

                //refine the DeletedLinesPoints list
                foreach (int i in pUsedPoints)
                {
                    if (pDeletedLinesPoints.Contains(i))
                    {
                        do
                        {
                        } while (pDeletedLinesPoints.Remove(i));
                    }
                }

                //add the points to a new FIDSet
                pPointFIDs = new FIDSetClass();
                foreach (int i in pDeletedLinesPoints)
                {
                    pPointFIDs.Add(i);
                }

                #endregion

                #region OrphanPoints
                //We already know which points to delete based on taking down the orphan lines.
                //We need to still add to the points FIDSet those points that are "pure" ophan points
                //as defined for the pOrphanPointsList variable.
                //and add the orphan points to the points FIDSet
                foreach (int i in pOrphanPointsList)
                {
                    bool bFound = false;
                    pPointFIDs.Find(i, out bFound);
                    if (!bFound)
                    {
                        pPointFIDs.Add(i);
                    }
                }
                #endregion

                #region orphan Line points
                //next check for orphan line-points
                //the line-point is deleted if there is no underlying point
                //or if the from and to point references do not exist.
                pSpatFilt.WhereClause = "";
                pSpatFilt.Geometry    = ToolSelectGeometry;
                IFeatureCursor pFeatCursLinePoints = pLinePoints.Search(pSpatFilt, false);
                IFeature       pLPFeat             = pFeatCursLinePoints.NextFeature();
                int            iLinePtPointIdIdx   = pLinePoints.FindField("LINEPOINTID");
                int            iLinePtFromPtIdIdx  = pLinePoints.FindField("FROMPOINTID");
                int            iLinePtToPtIdIdx    = pLinePoints.FindField("TOPOINTID");

                pLinePointFIDs = new FIDSetClass();
                while (pLPFeat != null)
                {
                    bool bExistsA = true;

                    bool bExists1 = true;
                    bool bExists2 = true;
                    bool bExists3 = true;

                    int iVal = (int)pLPFeat.get_Value(iLinePtPointIdIdx);
                    pPointFIDs.Find(iVal, out bExists1);
                    if (!pPointsInsideBoxList.Contains(iVal))
                    {
                        bExistsA = false;
                    }

                    iVal = (int)pLPFeat.get_Value(iLinePtFromPtIdIdx);
                    string sFrom = iVal.ToString();
                    pPointFIDs.Find(iVal, out bExists2);

                    iVal = (int)pLPFeat.get_Value(iLinePtToPtIdIdx);
                    string sTo = iVal.ToString();
                    pPointFIDs.Find(iVal, out bExists3);

                    int iOID = pLPFeat.OID;

                    if (bExists1 || bExists2 || bExists3)
                    {
                        pLinePointFIDs.Add(iOID);
                    }

                    if (!sFromToPair.Contains(sFrom + ":" + sTo) && !sFromToPair.Contains(sTo + ":" + sFrom))
                    {
                        pLinePointFIDs.Find(iOID, out bExists1);
                        if (!bExists1)
                        {
                            pLinePointFIDs.Add(iOID);
                        }
                    }

                    //if (!bExistsA || !bExistsB || !bExistsC)
                    if (!bExistsA)
                    {
                        bool bFound = true;
                        pLinePointFIDs.Find(iOID, out bFound);
                        if (!bFound)
                        {
                            pLinePointFIDs.Add(iOID);
                        }
                    }
                    pPointsInsideBoxList.Contains(iVal);

                    Marshal.ReleaseComObject(pLPFeat);
                    pLPFeat = pFeatCursLinePoints.NextFeature();
                }

                Marshal.FinalReleaseComObject(pFeatCursLinePoints);
                #endregion

                #region Refine the lines that are on the delete list
                //next step is to refine and double-check to make sure that the lines that are on the delete list
                //do not have a parcel record somewhere else (not spatially connected to the line) (example unjoined, or bad geom)
                string sFreshlyFoundParcels = "";
                if (sLineParcelIDReference.Trim() != "")
                {
                    pQuFilter.WhereClause = sPref + pParcels.OIDFieldName + sSuff + " IN (" + sLineParcelIDReference + ")";
                    pFeatCursor           = pParcels.Search(pQuFilter, false);
                    IFeature pFeat6 = pFeatCursor.NextFeature();
                    while (pFeat6 != null)
                    {
                        int iOID = pFeat6.OID;
                        if (sFreshlyFoundParcels.Trim() == "")
                        {
                            sFreshlyFoundParcels = iOID.ToString();
                        }
                        else
                        {
                            sFreshlyFoundParcels += "," + iOID.ToString();
                        }
                        Marshal.ReleaseComObject(pFeat6);
                        pFeat6 = pFeatCursor.NextFeature();
                    }
                    Marshal.FinalReleaseComObject(pFeatCursor);

                    if (sFreshlyFoundParcels.Trim() != "")
                    {
                        pQuFilter.WhereClause = "PARCELID IN (" + sFreshlyFoundParcels + ")";
                        pFeatCursor           = pLines.Search(pQuFilter, false);
                        IFeature pFeat9 = pFeatCursor.NextFeature();
                        while (pFeat9 != null)
                        {
                            int  iOID    = pFeat9.OID;
                            bool bIsHere = false;
                            pLineFIDs.Delete(iOID);
                            int iVal = Convert.ToInt32(pFeat9.get_Value(iFromPtFldIDX));
                            pPointFIDs.Find(iVal, out bIsHere);
                            if (bIsHere)
                            {
                                pPointFIDs.Delete(iVal);
                            }

                            iVal = Convert.ToInt32(pFeat9.get_Value(iToPtFldIDX));
                            pPointFIDs.Find(iVal, out bIsHere);
                            if (bIsHere)
                            {
                                pPointFIDs.Delete(iVal);
                            }

                            Marshal.ReleaseComObject(pFeat9);
                            pFeat9 = pFeatCursor.NextFeature();
                        }
                        Marshal.FinalReleaseComObject(pFeatCursor);
                    }
                }
                #endregion

                #region Make sure the points on the delete list are not part of a construction
                //For post 10.0, Make sure the points on the delete list are not part of a construction if they are then null geometry
                //pQuFilter.WhereClause=pLines.LengthField.Name + " = 0 AND CATEGORY <> 4";
                //IFeatureCursor pFeatCursLines101 = pLines.Search(pQuFilter, false);
                //this would open a new cursor and do a query on the entire
                #endregion

                #region report results and do edits
                dlgReport Report = new dlgReport();
                //Display the dialog
                System.Drawing.Color BackColorNow = Report.textBox1.BackColor;
                if (iCount == 0 && pPointFIDs.Count() == 0 && pLinePointFIDs.Count() == 0)
                {
                    Report.textBox1.BackColor = System.Drawing.Color.LightGreen;
                    Report.textBox1.Text      = "Selected area has no orphan lines or points.";
                }
                else
                {
                    int iCount1 = 0;
                    int iCount2 = 0;
                    int iCount3 = 0;
                    if (pLineFIDs != null)
                    {
                        iCount1 = pLineFIDs.Count();
                    }

                    if (pPointFIDs != null)
                    {
                        iCount2 = pPointFIDs.Count();
                    }

                    if (pLinePointFIDs != null)
                    {
                        iCount3 = pLinePointFIDs.Count();
                    }

                    iCount = iCount1 + iCount2 + iCount3;
                    if (iCount > 0)
                    {
                        pEd.StartOperation();
                        FabricUTILS.DeleteRowsByFIDSet((ITable)pLines, pLineFIDs, null, null);
                        FabricUTILS.DeleteRowsByFIDSet((ITable)pPoints, pPointFIDs, null, null);
                        if (pPointFIDs.Count() > 0)
                        {
                            //now need to update the control points associated with any deleted points.
                            ICadastralFabricSchemaEdit2 pSchemaEd = (ICadastralFabricSchemaEdit2)pCadFabric;
                            ITable     pControlTable       = pCadFabric.get_CadastralTable(esriCadastralFabricTable.esriCFTControl);
                            int        idxNameFldOnControl = pControlTable.FindField("POINTID");
                            string     ControlNameFldName  = pControlTable.Fields.get_Field(idxNameFldOnControl).Name;
                            int        i;
                            List <int> pPointFIDList = new List <int>();
                            pPointFIDs.Reset();
                            pPointFIDs.Next(out i);
                            while (i > -1)
                            {
                                pPointFIDList.Add(i);
                                pPointFIDs.Next(out i);
                            }
                            List <string> InClausePointsNotConnectedToLines = FabricUTILS.InClauseFromOIDsList(pPointFIDList, 995);
                            pQuFilter.WhereClause = ControlNameFldName + " IN (" + InClausePointsNotConnectedToLines[0] + ")";
                            pSchemaEd.ReleaseReadOnlyFields(pControlTable, esriCadastralFabricTable.esriCFTControl); //release safety-catch
                            if (!FabricUTILS.ResetControlAssociations(pControlTable, pQuFilter, false))
                            {
                                pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTControl);//set safety back on
                                pEd.AbortOperation();
                                return;
                            }
                            pSchemaEd.ResetReadOnlyFields(esriCadastralFabricTable.esriCFTControl);//set safety back on
                        }
                        pQuFilter.WhereClause = "";
                        FabricUTILS.DeleteRowsByFIDSet((ITable)pLinePoints, pLinePointFIDs, null, null);
                        pEd.StopOperation("Delete " + iCount.ToString() + " orphans");
                        Report.textBox1.Text = "Deleted:";
                        if (iCount1 > 0)
                        {
                            Report.textBox1.Text += Environment.NewLine + iCount1.ToString() + " orphaned lines";
                        }
                        if (iCount2 > 0)
                        {
                            Report.textBox1.Text += Environment.NewLine + iCount2.ToString() + " orphaned points";
                        }
                        if (iCount3 > 0)
                        {
                            Report.textBox1.Text += Environment.NewLine + iCount3.ToString() + " orphaned line points";
                        }
                    }
                    if (sFreshlyFoundParcels.Trim() != "")
                    {
                        if (Report.textBox1.Text.Trim() != "")
                        {
                            Report.textBox1.Text += Environment.NewLine;
                        }
                        Report.textBox1.Text += "Info: Line(s) that you selected are not directly" +
                                                Environment.NewLine + "touching a parent parcel geometry. Check parcels with OIDs:" +
                                                sFreshlyFoundParcels;
                    }
                }
                IArea pArea = (IArea)ToolSelectGeometry;
                if (pArea.Area > 0)
                {
                    SetDialogLocationAtPoint(Report, pArea.Centroid);
                }

                DialogResult pDialogResult = Report.ShowDialog();
                Report.textBox1.BackColor = BackColorNow;
                pInvArea.Display          = ArcMap.Document.ActiveView.ScreenDisplay;
                pInvArea.Invalidate((short)esriScreenCache.esriAllScreenCaches);

                if (pPointLayer != null)
                {
                    ArcMap.Document.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography,
                                                              pPointLayer, ArcMap.Document.ActiveView.Extent);
                }
                #endregion
            }

            catch (Exception ex)
            {
                if (pEd != null)
                {
                    pEd.AbortOperation();
                }
                MessageBox.Show(ex.Message + Environment.NewLine + m_sDebug, "Delete Orphans Tool");
                this.OnDeactivate();
            }

            #region Final Cleanup
            finally
            {
                pDeletedLinesPoints.Clear();
                pDeletedLinesPoints = null;
                pUsedPoints.Clear();
                pUsedPoints = null;
                CtrPointIDList.Clear();
                CtrPointIDList = null;
                pParcelsList.Clear();
                pParcelsList = null;
                pOrphanPointsList.Clear();
                pOrphanPointsList = null;
                pPointsInsideBoxList.Clear();
                pPointsInsideBoxList = null;
                pLineToParcelIDRef.Clear();
                pLineToParcelIDRef = null;
                sFromToPair.Clear();
                sFromToPair = null;

                FabricUTILS = null;
            }
            #endregion
        }
コード例 #12
0
        protected override void Execute()
        {
            if (Geometry is IEnvelope)
            {
                var polygon = new Polygon
                {
                    CRS = new Crs
                    {
                        WellKnownId = 26912
                    }
                };

                ISegmentCollection segmentColl = new PolygonClass();

                segmentColl.SetRectangle(Geometry as IEnvelope);
                var poly = segmentColl as IPolygon4;

                if (SpatialReference != null)
                {
                    poly.Project(SpatialReference);
                    polygon.CRS.WellKnownId = SpatialReference.FactoryCode;
                }

                var geometryCollection = poly as IGeometryCollection;
                var count = geometryCollection.GeometryCount;

                for (var i = 0; i < count; i++)
                {
                    var points = geometryCollection.Geometry[i] as IPointCollection4;

                    var pointCount = points.PointCount;
                    var ringPoints = new List <RingPoint>(pointCount);

                    for (var j = 0; j < pointCount; j++)
                    {
                        var point = points.Point[j];
                        ringPoints.Add(new RingPoint(point.X, point.Y));
                    }

                    polygon.AddRing(new List <RingPoint[]>
                    {
                        ringPoints.ToArray()
                    });
                }

                Result = JsonConvert.SerializeObject(polygon);
                return;
            }

            if (Geometry is IPoint)
            {
                var esriPoint = Geometry as IPoint;
                var point     = new Point
                {
                    CRS = new Crs
                    {
                        WellKnownId = 26912
                    }
                };

                if (SpatialReference != null)
                {
                    esriPoint.Project(SpatialReference);
                    point.CRS.WellKnownId = SpatialReference.FactoryCode;
                }

                point.X = esriPoint.X;
                point.Y = esriPoint.Y;

                Result = JsonConvert.SerializeObject(point);
                return;
            }

            if (Geometry is IPolyline)
            {
                var line = new Polyline
                {
                    CRS = new Crs
                    {
                        WellKnownId = 26912
                    }
                };

                var simpleGeom = Geometry as IPolyline5;
                simpleGeom.Generalize(10);

                if (SpatialReference != null)
                {
                    simpleGeom.Project(SpatialReference);
                    line.CRS.WellKnownId = SpatialReference.FactoryCode;
                }

                var geometryCollection = simpleGeom as IGeometryCollection;
                var count = geometryCollection.GeometryCount;

                for (var i = 0; i < count; i++)
                {
                    var points = geometryCollection.Geometry[i] as IPointCollection4;

                    var pointCount = points.PointCount;
                    var ringPoints = new List <RingPoint>(pointCount);

                    for (var j = 0; j < pointCount; j++)
                    {
                        var point = points.Point[j];
                        ringPoints.Add(new RingPoint(point.X, point.Y));
                    }

                    line.AddPath(new List <RingPoint[]>
                    {
                        ringPoints.ToArray()
                    });
                }

                Result = JsonConvert.SerializeObject(line);
                return;
            }

            if (Geometry is IPolygon)
            {
                var polygon = new Polygon
                {
                    CRS = new Crs
                    {
                        WellKnownId = 26912
                    }
                };

                var simpleGeom = Geometry as IPolygon4;
                simpleGeom.Generalize(10);

                if (SpatialReference != null)
                {
                    simpleGeom.Project(SpatialReference);
                    polygon.CRS.WellKnownId = SpatialReference.FactoryCode;
                }

                var geometryCollection = simpleGeom as IGeometryCollection;
                var count = geometryCollection.GeometryCount;

                for (var i = 0; i < count; i++)
                {
                    var points = geometryCollection.Geometry[i] as IPointCollection4;

                    var pointCount = points.PointCount;
                    var ringPoints = new List <RingPoint>(pointCount);

                    for (var j = 0; j < pointCount; j++)
                    {
                        var point = points.Point[j];
                        ringPoints.Add(new RingPoint(point.X, point.Y));
                    }

                    polygon.AddRing(new List <RingPoint[]>
                    {
                        ringPoints.ToArray()
                    });
                }

                Result = JsonConvert.SerializeObject(polygon);
            }
        }