Ejemplo n.º 1
0
 /// <summary>
 /// 构造函数,用来传一个数据集合进来
 /// </summary>
 /// <param name="Dataset">数据集合</param>
 public GeoPointDuplicateCheck(IArcgisDataCheckHook Mhook)
 {
     Hook = Mhook;
 }
 public void OnCreate(IDataCheckHook hook)
 {
     Hook = hook as IArcgisDataCheckHook;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 等高线高程点点线矛盾检查,还需要完善
        /// </summary>
        /// <param name="pFeaDataset"></param>
        /// <param name="desFeaCls">等高线要素类</param>
        /// <param name="oriFeaCls">高程点要素类</param>
        /// <param name="pointFeature">高程点要素</param>
        /// <param name="lineFieldName">等高线高程字段名</param>
        /// <param name="lineIndex">等高线高程字段索引</param>
        /// <param name="pointIndex">高程点高程字段民</param>
        /// <param name="nearestFea">离高程点要素最近的等高线要素</param>
        /// <param name="intervalElev">等高线间距值</param>
        /// <param name="eError"></param>
        private void PointLineAccordanceCheck2(IArcgisDataCheckHook hook, IFeatureDataset pFeaDataset, IFeatureClass desFeaCls, IFeatureClass oriFeaCls, IFeature pointFeature, string lineFieldName, int lineIndex, int pointIndex, IFeature nearestFea, double pShortestDis, double intervalElev, out Exception eError)
        {
            eError = null;

            try
            {
                double pValue    = 0.0;                                   //点要素的高程值
                double fValue    = 0.0;                                   //最近线要素高程值
                double lValue    = 0.0;                                   //最近线要素相邻的第一条要素
                double sValue    = 0.0;                                   //最近线要素相邻的第二条要素
                int    eErrorID  = enumErrorType.等高线点线矛盾检查.GetHashCode(); //错误ID
                string eErrorDes = "等高线与高程点高程值点线矛盾!";                     //错误描述

                //点要素的高程值
                string pValueStr = pointFeature.get_Value(pointIndex).ToString().Trim();
                if (pValueStr == "")
                {
                    eError = new Exception("高程点的高程值为空,OID为:" + pointFeature.OID);
                    return;
                }
                pValue = Convert.ToDouble(pValueStr);
                //最近线要素高程值
                string fValueStr = nearestFea.get_Value(lineIndex).ToString().Trim();
                if (fValueStr == "")
                {
                    eError = new Exception("线要素的高程值为空。OID为:" + nearestFea.OID);
                    return;
                }
                fValue = Convert.ToDouble(fValueStr);

                if (pShortestDis == 0)
                {
                    //说明点在线上
                    if (pValue != fValue)
                    {
                        //点线高程值矛盾
                        GetErrorList(hook, pFeaDataset, oriFeaCls, pointFeature, desFeaCls, nearestFea, eErrorID, eErrorDes, out eError);
                        if (eError != null)
                        {
                            return;
                        }
                    }
                }
                else
                {
                    if (fValue < intervalElev)
                    {
                        #region 说明是最小高程,说明该要素是最里面或最外面的要素
                        //最近线要素相邻的第一条要素的高程值
                        lValue = fValue + intervalElev;
                        string          whereStr = lineFieldName + "=" + lValue;
                        List <IFeature> lstFefa  = GetFeatureByStr(desFeaCls, whereStr, out eError);
                        if (eError != null || lstFefa == null || lstFefa.Count == 0)
                        {
                            return;
                        }
                        //bool isIntersact = false;

                        //for (int k = 0; k < lstFefa.Count; k++)
                        //{
                        if (lstFefa.Count == 1)
                        {
                            IFeature secondFea = lstFefa[0];
                            //返回secondFea上与高程点最近的点
                            IProximityOperator pProxiOper = secondFea.Shape as IProximityOperator;
                            IPoint             p          = new PointClass();
                            p = pProxiOper.ReturnNearestPoint(pointFeature.Shape as IPoint, esriSegmentExtension.esriNoExtension);
                            //    if (IsIntersect(pointFeature.Shape as IPoint, p, nearestFea))
                            //    {
                            //        isIntersact = true;
                            //        secondFea = lstFefa[k];
                            //        break;
                            //    }
                            //}

                            #region 最近线要素相邻的第一条要素上点与高程点连线与最近线要素的拓扑关系包含两种情况:相交、不相交。
                            if (IsIntersect(pointFeature.Shape as IPoint, p, nearestFea))
                            {
                                //若两点连线与nearestFea相交,说明高程点在线要素的最里面或者最外面
                                //由于fValue<lValue
                                if (pValue > fValue)
                                {
                                    //点线高程值矛盾
                                    GetErrorList(hook, pFeaDataset, oriFeaCls, pointFeature, desFeaCls, nearestFea, eErrorID, eErrorDes, out eError);
                                    if (eError != null)
                                    {
                                        return;
                                    }
                                }
                            }
                            else
                            {
                                //若两点连线与nearestFea不相交,高程点在两条线要素之间
                                if (pValue < fValue)
                                {
                                    //点线高程值矛盾
                                    GetErrorList(hook, pFeaDataset, oriFeaCls, pointFeature, desFeaCls, secondFea, eErrorID, eErrorDes, out eError);
                                    if (eError != null)
                                    {
                                        return;
                                    }
                                }
                                if (pValue > lValue)
                                {
                                    //点线高程值矛盾
                                    GetErrorList(hook, pFeaDataset, oriFeaCls, pointFeature, desFeaCls, nearestFea, eErrorID, eErrorDes, out eError);
                                    if (eError != null)
                                    {
                                        return;
                                    }
                                }
                            }
                            #endregion
                        }

                        #endregion
                    }
                    else if (fValue >= intervalElev)
                    {
                        #region 分为两种情况:或者是最里面或最外面的线要素、或者是中间线要素
                        //与nearestFea相邻的两线要素的高程值
                        lValue = fValue + intervalElev;
                        sValue = fValue - intervalElev;
                        //与最近要素要素的两个要素
                        IFeature secondFea = null;
                        IFeature thirdFea  = null;

                        string whereStr = lineFieldName + "=" + lValue;

                        List <IFeature> lstFea2 = GetFeatureByStr(desFeaCls, whereStr, out eError);
                        if (eError != null || lstFea2 == null)
                        {
                            return;
                        }
                        whereStr = lineFieldName + "=" + sValue;
                        List <IFeature> lstFea3 = GetFeatureByStr(desFeaCls, whereStr, out eError);
                        if (eError != null || lstFea3 == null)
                        {
                            return;
                        }

                        if (lstFea2.Count == 0 && lstFea3.Count == 0)
                        {
                            //只有一条等高线
                            eError = new Exception("只有一条等高线,不能进行检查!");
                            return;
                        }
                        else if (lstFea2.Count == 1 && lstFea3.Count == 1)
                        {
                            secondFea = lstFea2[0];
                            thirdFea  = lstFea3[0];
                            #region nearestFea不是最里面或最外面的要素
                            IPoint             p          = new PointClass();
                            IProximityOperator pProxiOper = secondFea.Shape as IProximityOperator;
                            p = pProxiOper.ReturnNearestPoint(pointFeature.Shape as IPoint, esriSegmentExtension.esriNoExtension);
                            if (IsIntersect(pointFeature.Shape as IPoint, p, nearestFea))
                            {
                                //相交。sValue<fValue<lValue ,pValue应位于sValue与fValue之间
                                if (pValue < sValue)
                                {
                                    //点线高程值矛盾
                                    GetErrorList(hook, pFeaDataset, oriFeaCls, pointFeature, desFeaCls, thirdFea, eErrorID, eErrorDes, out eError);
                                    if (eError != null)
                                    {
                                        return;
                                    }
                                }
                                if (pValue > fValue)
                                {
                                    //点线高程值矛盾
                                    GetErrorList(hook, pFeaDataset, oriFeaCls, pointFeature, desFeaCls, nearestFea, eErrorID, eErrorDes, out eError);
                                    if (eError != null)
                                    {
                                        return;
                                    }
                                }
                            }
                            else
                            {
                                //不相交。sValue<fValue<lValue ,pValue应位于fValue与lValue之间
                                if (pValue < fValue)
                                {
                                    //点线高程值矛盾
                                    GetErrorList(hook, pFeaDataset, oriFeaCls, pointFeature, desFeaCls, nearestFea, eErrorID, eErrorDes, out eError);
                                    if (eError != null)
                                    {
                                        return;
                                    }
                                }
                                if (pValue > lValue)
                                {
                                    //点线高程值矛盾
                                    GetErrorList(hook, pFeaDataset, oriFeaCls, pointFeature, desFeaCls, secondFea, eErrorID, eErrorDes, out eError);
                                    if (eError != null)
                                    {
                                        return;
                                    }
                                }
                            }
                            #endregion
                        }
                        else if (lstFea2.Count == 1 || lstFea3.Count == 1)
                        {
                            if (lstFea2.Count == 1 && lstFea3.Count == 0)
                            {
                                secondFea = lstFea2[0];
                            }
                            else if (lstFea3.Count == 1 && lstFea2.Count == 0)
                            {
                                thirdFea = lstFea3[0];
                            }
                            if (secondFea == null && thirdFea == null)
                            {
                                return;
                            }

                            #region  nearestFea是最里面或最外面的要素
                            IPoint p = new PointClass();
                            if (secondFea != null)
                            {
                                IProximityOperator pProxiOper = secondFea.Shape as IProximityOperator;
                                p = pProxiOper.ReturnNearestPoint(pointFeature.Shape as IPoint, esriSegmentExtension.esriNoExtension);
                            }
                            if (thirdFea != null)
                            {
                                IProximityOperator pProxiOper = thirdFea.Shape as IProximityOperator;
                                p = pProxiOper.ReturnNearestPoint(pointFeature.Shape as IPoint, esriSegmentExtension.esriNoExtension);
                            }
                            if (IsIntersect(pointFeature.Shape as IPoint, p, nearestFea))
                            {
                                //相交。高程点在等高线的最外面或最里面
                                if (secondFea != null)
                                {
                                    //由于fValue<lValue
                                    if (pValue > fValue)
                                    {
                                        //点线高程值矛盾
                                        GetErrorList(hook, pFeaDataset, oriFeaCls, pointFeature, desFeaCls, nearestFea, eErrorID, eErrorDes, out eError);
                                        if (eError != null)
                                        {
                                            return;
                                        }
                                    }
                                }
                                if (thirdFea != null)
                                {
                                    //由于fValue>sValue
                                    if (pValue < fValue)
                                    {
                                        //点线高程值矛盾
                                        GetErrorList(hook, pFeaDataset, oriFeaCls, pointFeature, desFeaCls, nearestFea, eErrorID, eErrorDes, out eError);
                                        if (eError != null)
                                        {
                                            return;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                //不相交。高程点在等高线的最靠边的两条等高线之间
                                if (secondFea != null)
                                {
                                    //由于fValue<lValue
                                    if (pValue < fValue)
                                    {
                                        //点线高程值矛盾
                                        GetErrorList(hook, pFeaDataset, oriFeaCls, pointFeature, desFeaCls, nearestFea, eErrorID, eErrorDes, out eError);
                                        if (eError != null)
                                        {
                                            return;
                                        }
                                    }
                                    if (pValue > lValue)
                                    {
                                        //点线高程值矛盾
                                        GetErrorList(hook, pFeaDataset, oriFeaCls, pointFeature, desFeaCls, secondFea, eErrorID, eErrorDes, out eError);
                                        if (eError != null)
                                        {
                                            return;
                                        }
                                    }
                                }
                                if (thirdFea != null)
                                {
                                    //由于fValue>sValue
                                    if (pValue > fValue)
                                    {
                                        //点线高程值矛盾
                                        GetErrorList(hook, pFeaDataset, oriFeaCls, pointFeature, desFeaCls, nearestFea, eErrorID, eErrorDes, out eError);
                                        if (eError != null)
                                        {
                                            return;
                                        }
                                    }
                                    if (pValue < sValue)
                                    {
                                        //点线高程值矛盾
                                        GetErrorList(hook, pFeaDataset, oriFeaCls, pointFeature, desFeaCls, thirdFea, eErrorID, eErrorDes, out eError);
                                        if (eError != null)
                                        {
                                            return;
                                        }
                                    }
                                }
                            }
                            #endregion
                        }
                        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                eError = ex;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 等高线点线矛盾一致性检查
        /// </summary>
        /// <param name="feaClsLst"></param>
        /// <param name="lineFeaClsName">等高线要素类名称</param>
        /// <param name="lineFieldName">等高线高程字段名</param>
        /// <param name="pointFeaClsName">高程点要素类名称</param>
        /// <param name="pointFieldName">高程点字段名</param>
        /// <param name="radiu">高程点搜索半径</param>
        /// <param name="intervalValue">等高线间距值</param>
        /// <param name="eError"></param>
        public void PointLineElevCheck(IArcgisDataCheckHook hook, List <IDataset> feaClsLst, string lineFeaClsName, string lineFieldName, string pointFeaClsName, string pointFieldName, double intervalValue, out Exception eError)
        {
            eError = null;
            try
            {
                //等高线要素类
                IFeatureClass lineFeaCls = null;// (pFeatureDataset.Workspace as IFeatureWorkspace).OpenFeatureClass(lineFeaClsName);
                foreach (IDataset pDT in feaClsLst)
                {
                    string tempName = pDT.Name;
                    if (tempName.Contains("."))
                    {
                        tempName = tempName.Substring(tempName.IndexOf('.') + 1);
                    }
                    if (tempName == lineFeaClsName)
                    {
                        lineFeaCls = pDT as IFeatureClass;
                        break;
                    }
                }
                if (lineFeaCls == null)
                {
                    return;
                }
                //等高线高程字段索引值
                int lineIndex = lineFeaCls.Fields.FindField(lineFieldName);
                if (lineIndex == -1)
                {
                    eError = new Exception("等高线图层的高程字段不存在,字段名为:" + lineFieldName);
                    return;
                }
                //高程点要素类
                IFeatureClass pointFeaCls = null;// (pFeatureDataset.Workspace as IFeatureWorkspace).OpenFeatureClass(pointFeaClsName);
                foreach (IDataset pDT in feaClsLst)
                {
                    string tempName = pDT.Name;
                    if (tempName.Contains("."))
                    {
                        tempName = tempName.Substring(tempName.IndexOf('.') + 1);
                    }
                    if (tempName == pointFeaClsName)
                    {
                        pointFeaCls = pDT as IFeatureClass;
                        break;
                    }
                }
                if (pointFeaCls == null)
                {
                    return;
                }
                int pointIndex = pointFeaCls.Fields.FindField(pointFieldName);
                if (lineIndex == -1)
                {
                    eError = new Exception("高程点图层的高程字段不存在,字段名为:" + pointFieldName);
                    return;
                }

                //遍历高程点要素
                IFeatureCursor pCusor = pointFeaCls.Search(null, false);
                if (pCusor == null)
                {
                    return;
                }
                IFeature pointFeature = pCusor.NextFeature();

                while (pointFeature != null)
                {
                    //高程点要素的高程值
                    double pointElevValue = Convert.ToDouble(pointFeature.get_Value(pointIndex).ToString());
                    //查找高程点相邻的两条高程线要素

                    //与高程点最近的等高线要素以及最短距离
                    Dictionary <double, IFeature> nearestFeaDic = GetShortestDis(lineFeaCls, pointFeature, out eError);
                    if (eError != null || nearestFeaDic == null)
                    {
                        eError = new Exception("在搜索范围内的未找到要素!");
                        return;
                    }
                    double   pShortestDis = -1;
                    IFeature nearestFea   = null;
                    foreach (KeyValuePair <double, IFeature> item in nearestFeaDic)
                    {
                        pShortestDis = item.Key;
                        nearestFea   = item.Value;
                        break;
                    }
                    if (eError != null || pShortestDis == -1)
                    {
                        return;
                    }
                    //获得等高线上离高程点最近的点
                    IPoint             nearestPoint = new PointClass();//等高线上的最近点
                    IProximityOperator mProxiOpe    = nearestFea.Shape as IProximityOperator;
                    if (mProxiOpe == null)
                    {
                        return;
                    }
                    nearestPoint = mProxiOpe.ReturnNearestPoint(pointFeature.Shape as IPoint, esriSegmentExtension.esriNoExtension);
                    //将高程点和等高线上的点连成线段并进行两端延长

                    PointLineAccordanceCheck2(hook, null, lineFeaCls, pointFeaCls, pointFeature, lineFieldName, lineIndex, pointIndex, nearestFea, pShortestDis, intervalValue, out eError);
                    //PointLineAccordanceCheck(pFeatureDataset, lineFeaCls, pointFeaCls, pointFeature, lineIndex, pointIndex, pShortestDis, nearestFea, intervalValue, out eError);
                    if (eError != null)
                    {
                        return;
                    }
                    pointFeature = pCusor.NextFeature();
                }

                //释放cursor
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pCusor);
            }
            catch (Exception ex)
            {
                eError = ex;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 等高线点线矛盾一致性检查
        /// </summary>
        /// <param name="pFeatureDataset"></param>
        /// <param name="lineFeaClsName">等高线要素类名称</param>
        /// <param name="lineFieldName">等高线高程字段名</param>
        /// <param name="pointFeaClsName">高程点要素类名称</param>
        /// <param name="pointFieldName">高程点字段名</param>
        /// <param name="radiu">高程点搜索半径</param>
        /// <param name="intervalValue">等高线间距值</param>
        /// <param name="eError"></param>
        private void PointLineElevCheck(IArcgisDataCheckHook hook, IFeatureDataset pFeatureDataset, string lineFeaClsName, string lineFieldName, string pointFeaClsName, string pointFieldName, double intervalValue, out Exception eError)
        {
            eError = null;
            try
            {
                //等高线要素类
                IFeatureClass lineFeaCls = (pFeatureDataset.Workspace as IFeatureWorkspace).OpenFeatureClass(lineFeaClsName);
                //等高线高程字段索引值
                int lineIndex = lineFeaCls.Fields.FindField(lineFieldName);
                if (lineIndex == -1)
                {
                    eError = new Exception("等高线图层的高程字段不存在,字段名为:" + lineFieldName);
                    return;
                }
                //高程点要素类
                IFeatureClass pointFeaCls = (pFeatureDataset.Workspace as IFeatureWorkspace).OpenFeatureClass(pointFeaClsName);
                int           pointIndex  = pointFeaCls.Fields.FindField(pointFieldName);
                if (lineIndex == -1)
                {
                    eError = new Exception("高程点图层的高程字段不存在,字段名为:" + pointFieldName);
                    return;
                }

                //遍历高程点要素
                IFeatureCursor pCusor = pointFeaCls.Search(null, false);
                if (pCusor == null)
                {
                    return;
                }
                IFeature pointFeature = pCusor.NextFeature();

                //设置进度条
                ProgressChangeEvent eInfo = new ProgressChangeEvent();
                eInfo.Max = pointFeaCls.FeatureCount(null);
                int pValue = 0;

                while (pointFeature != null)
                {
                    //高程点要素的高程值
                    double pointElevValue = Convert.ToDouble(pointFeature.get_Value(pointIndex).ToString());
                    //查找高程点相邻的两条高程线要素

                    //与高程点最近的等高线要素以及最短距离
                    Dictionary <double, IFeature> nearestFeaDic = GetShortestDis(lineFeaCls, pointFeature, out eError);
                    if (eError != null || nearestFeaDic == null)
                    {
                        eError = new Exception("在搜索范围内的未找到要素!");
                        return;
                    }
                    double   pShortestDis = -1;
                    IFeature nearestFea   = null;
                    foreach (KeyValuePair <double, IFeature> item in nearestFeaDic)
                    {
                        pShortestDis = item.Key;
                        nearestFea   = item.Value;
                        break;
                    }
                    if (eError != null || pShortestDis == -1)
                    {
                        return;
                    }
                    //获得等高线上离高程点最近的点
                    IPoint             nearestPoint = new PointClass();//等高线上的最近点
                    IProximityOperator mProxiOpe    = nearestFea.Shape as IProximityOperator;
                    if (mProxiOpe == null)
                    {
                        return;
                    }
                    nearestPoint = mProxiOpe.ReturnNearestPoint(pointFeature.Shape as IPoint, esriSegmentExtension.esriNoExtension);
                    //将高程点和等高线上的点连成线段并进行两端延长

                    PointLineAccordanceCheck2(hook, pFeatureDataset, lineFeaCls, pointFeaCls, pointFeature, lineFieldName, lineIndex, pointIndex, nearestFea, pShortestDis, intervalValue, out eError);
                    //PointLineAccordanceCheck(pFeatureDataset, lineFeaCls, pointFeaCls, pointFeature, lineIndex, pointIndex, pShortestDis, nearestFea, intervalValue, out eError);
                    if (eError != null)
                    {
                        return;
                    }
                    pointFeature = pCusor.NextFeature();

                    //进度条加1
                    pValue++;
                    eInfo.Value = pValue;
                    GeoDataChecker.GeoDataChecker_ProgressShow((object)GeoDataChecker._ProgressBarInner, eInfo);
                }

                //释放cursor
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pCusor);
            }
            catch (Exception ex)
            {
                eError = ex;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 注记高程值一致性检查
        /// </summary>
        /// <param name="hook"></param>
        /// <param name="feaClsLst"></param>
        /// <param name="codeName">分类代码字段名</param>
        /// <param name="oriFeaClsName">源要素类名称</param>
        /// <param name="oriCodeValue">源要素类分类代码值</param>
        /// <param name="oriElevFieldName">源高程值字段名</param>
        /// <param name="desFeaClsName">目标要素类名称</param>
        /// <param name="desCodeValue">目标要素类分类代码值</param>
        /// <param name="labelFieldName">目标要素类高程值</param>
        /// <param name="radius">搜索半径</param>
        /// <param name="precision">精度控制</param>
        /// <param name="outError"></param>
        public void ElevAccordanceCheck(IArcgisDataCheckHook hook, List <IDataset> feaClsLst, string codeName, string oriFeaClsName, string oriCodeValue, string oriElevFieldName, string desFeaClsName, string desCodeValue, string labelFieldName, double radius, long precision, out Exception outError)
        {
            outError = null;
            try
            {
                //源要素类
                IFeatureClass pOriFeaCls = null;// (pFeatureDataset.Workspace as IFeatureWorkspace).OpenFeatureClass(oriFeaClsName);
                foreach (IDataset pDT in feaClsLst)
                {
                    string tempName = pDT.Name;
                    if (tempName.Contains("."))
                    {
                        tempName = tempName.Substring(tempName.IndexOf('.') + 1);
                    }
                    if (tempName == oriFeaClsName)
                    {
                        pOriFeaCls = pDT as IFeatureClass;
                        break;
                    }
                }
                if (pOriFeaCls == null)
                {
                    return;
                }
                //源要素类高程字段索引值
                int oriEleIndex = pOriFeaCls.Fields.FindField(oriElevFieldName);
                if (oriEleIndex == -1)
                {
                    outError = new Exception("要素类" + oriFeaClsName + "字段" + oriElevFieldName + "不存在!");
                    return;
                }

                //目标要素类
                IFeatureClass pDesFeaCls = null;// (pFeatureDataset.Workspace as IFeatureWorkspace).OpenFeatureClass(desFeaClsName);
                foreach (IDataset pDT in feaClsLst)
                {
                    string tempName = pDT.Name;
                    if (tempName.Contains("."))
                    {
                        tempName = tempName.Substring(tempName.IndexOf('.') + 1);
                    }
                    if (tempName == desFeaClsName)
                    {
                        pDesFeaCls = pDT as IFeatureClass;
                        break;
                    }
                }
                if (pDesFeaCls == null)
                {
                    return;
                }
                //目标要素类高程字段索引值
                int desElevIndex = pDesFeaCls.Fields.FindField(labelFieldName);
                if (desElevIndex == -1)
                {
                    outError = new Exception("要素类" + desFeaClsName + "字段" + labelFieldName + "不存在!");
                    return;
                }

                //查找源要素类中符合分类代码限制条件的要素
                string whereStr = "";
                if (oriCodeValue != "")
                {
                    whereStr = codeName + " ='" + oriCodeValue + "'";
                }
                IQueryFilter pFilter = new QueryFilterClass();
                pFilter.WhereClause = whereStr;
                IFeatureCursor pCursor = pOriFeaCls.Search(pFilter, false);
                if (pCursor == null)
                {
                    return;
                }
                IFeature pOriFea = pCursor.NextFeature();

                //遍历源要素,进行比较
                while (pOriFea != null)
                {
                    #region 进行检查
                    string oriElevValue = pOriFea.get_Value(oriEleIndex).ToString();
                    //根据原高程值求出精度允许的高程值用于比较
                    if (oriElevValue.Contains("."))
                    {
                        //原高程值包含小数点
                        int oriDotIndex = oriElevValue.IndexOf('.');
                        if (precision == 0)
                        {
                            oriElevValue = oriElevValue.Substring(0, oriDotIndex);
                        }
                        else if (oriElevValue.Substring(oriDotIndex + 1).Length > precision && precision > 0)
                        {
                            //原高程值的小数点位数大于精度控制
                            int oriLen = oriDotIndex + 1 + Convert.ToInt32(precision);
                            oriElevValue = oriElevValue.Substring(0, oriLen);
                        }
                    }

                    IFeature desFeature = GetNearestFeature(pDesFeaCls, codeName, desCodeValue, pOriFea, radius, out outError);
                    if (outError != null)
                    {
                        return;
                    }
                    if (desFeature == null)
                    {
                        pOriFea = pCursor.NextFeature();
                        continue;
                    }
                    string desElevValue = desFeature.get_Value(desElevIndex).ToString();
                    if (desElevValue.Contains("."))
                    {
                        //目标高程值包含小数点
                        int desDotIndex = desElevValue.IndexOf('.');
                        if (precision == 0)
                        {
                            desElevValue = desElevValue.Substring(0, desDotIndex);
                        }
                        else if (desElevValue.Substring(desDotIndex + 1).Length > precision && precision > 0)
                        {
                            //目标高程值的小数点位数大于精度
                            int desLen = desDotIndex + 1 + Convert.ToInt32(precision);
                            desElevValue = desElevValue.Substring(0, desLen);
                        }
                    }

                    //根据精度进行比较,在容许的范围内不相同不算错误
                    if (Convert.ToDouble(oriElevValue) != Convert.ToDouble(desElevValue))
                    {
                        //说明点,或线与相应注记的高程值不一致。将错误结果显示出来
                        double pMapx  = 0.0;
                        double pMapy  = 0.0;
                        IPoint pPoint = new PointClass();
                        if (pOriFeaCls.ShapeType != esriGeometryType.esriGeometryPoint)
                        {
                            pPoint = TopologyCheckClass.GetPointofFeature(pOriFea);
                        }
                        else
                        {
                            //点要素类
                            pPoint = pOriFea.Shape as IPoint;
                        }
                        pMapx = pPoint.X;
                        pMapy = pPoint.Y;

                        List <object> ErrorLst = new List <object>();
                        ErrorLst.Add("要素属性检查");                                                //功能组名称
                        ErrorLst.Add("点线注记高程值一致性检查");                                          //功能名称
                        ErrorLst.Add("");                                                      //数据文件名
                        ErrorLst.Add(0);                                                       //错误id;
                        ErrorLst.Add("图层" + oriFeaClsName + "与图层" + desFeaClsName + "高程值不一致"); //错误描述
                        ErrorLst.Add(pMapx);                                                   //...
                        ErrorLst.Add(pMapy);                                                   //...
                        ErrorLst.Add(oriFeaClsName);
                        ErrorLst.Add(pOriFea.OID);
                        ErrorLst.Add(desFeaClsName);
                        ErrorLst.Add(desFeature.OID);
                        ErrorLst.Add(false);
                        ErrorLst.Add(System.DateTime.Now.ToString());

                        //传递错误日志
                        IDataErrInfo      dataErrInfo       = new DataErrInfo(ErrorLst);
                        DataErrTreatEvent dataErrTreatEvent = new DataErrTreatEvent(dataErrInfo);
                        DataErrTreat(hook.DataCheckParaSet as object, dataErrTreatEvent);
                    }
                    pOriFea = pCursor.NextFeature();
                    #endregion
                }

                //释放cursor
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pCursor);
            }
            catch (Exception ex)
            {
                outError = ex;
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 空值检查
        /// </summary>
        /// <param name="hook"></param>
        /// <param name="pFeatureDataset"></param>
        /// <param name="FeaClsNameDic">图层名和属性非空的字段名对</param>
        /// <param name="outError"></param>
        public void IsNullableCheck(IArcgisDataCheckHook hook, IFeatureDataset pFeatureDataset, Dictionary <string, List <string> > FeaClsNameDic, out Exception outError)
        {
            outError = null;
            try
            {
                //设置进度条
                ProgressChangeEvent eInfo = new ProgressChangeEvent();
                eInfo.Max = FeaClsNameDic.Count;
                int pValue = 0;

                foreach (KeyValuePair <string, List <string> > item in FeaClsNameDic)
                {
                    IFeatureClass pFeaCls = (pFeatureDataset.Workspace as IFeatureWorkspace).OpenFeatureClass(item.Key.Trim());
                    for (int i = 0; i < item.Value.Count; i++)
                    {
                        string fieldName = item.Value[i].Trim();
                        int    index     = pFeaCls.Fields.FindField(fieldName);
                        if (index == -1)
                        {
                            outError = new Exception("找不到字段名为" + fieldName + "的字段");
                            return;
                        }
                        if (pFeaCls.Fields.get_Field(index).IsNullable == true)
                        {
                            //字段属性为空,与标准不一致,将结果保存起来
                            List <object> ErrorLst = new List <object>();
                            ErrorLst.Add("要素属性检查");                                         //功能组名称
                            ErrorLst.Add("空值检查");                                           //功能名称
                            ErrorLst.Add((pFeatureDataset as IDataset).Workspace.PathName); //数据文件名
                            ErrorLst.Add(enumErrorType.空值检查.GetHashCode());                 //错误id;
                            ErrorLst.Add("图层" + item.Key + "的字段" + fieldName + "属性值不允许为空"); //错误描述
                            ErrorLst.Add(0);                                                //...
                            ErrorLst.Add(0);                                                //...
                            ErrorLst.Add(item.Key);
                            ErrorLst.Add(-1);
                            ErrorLst.Add("");
                            ErrorLst.Add(-1);
                            ErrorLst.Add(false);
                            ErrorLst.Add(System.DateTime.Now.ToString());

                            //传递错误日志
                            IDataErrInfo      dataErrInfo       = new DataErrInfo(ErrorLst);
                            DataErrTreatEvent dataErrTreatEvent = new DataErrTreatEvent(dataErrInfo);
                            DataErrTreat(hook.DataCheckParaSet as object, dataErrTreatEvent);
                        }
                        else
                        {
                            IFeatureCursor pFeaCusor = pFeaCls.Search(null, false);
                            if (pFeaCusor == null)
                            {
                                return;
                            }
                            IFeature pFeature = pFeaCusor.NextFeature();
                            if (pFeature == null)
                            {
                                continue;
                            }
                            while (pFeature != null)
                            {
                                object fieldValue = pFeature.get_Value(index);
                                if (fieldValue == null || fieldValue.ToString() == "")
                                {
                                    //字段值不能为空,将检查结果保存起来
                                    double pMapx  = 0.0;
                                    double pMapy  = 0.0;
                                    IPoint pPoint = new PointClass();
                                    if (pFeaCls.ShapeType != esriGeometryType.esriGeometryPoint)
                                    {
                                        pPoint = TopologyCheckClass.GetPointofFeature(pFeature);
                                    }
                                    else
                                    {
                                        pPoint = pFeature.Shape as IPoint;
                                    }
                                    pMapx = pPoint.X;
                                    pMapy = pPoint.Y;
                                    List <object> ErrorLst = new List <object>();
                                    ErrorLst.Add("要素属性检查");                                         //功能组名称
                                    ErrorLst.Add("空值检查");                                           //功能名称
                                    ErrorLst.Add((pFeatureDataset as IDataset).Workspace.PathName); //数据文件名
                                    ErrorLst.Add(enumErrorType.空值检查.GetHashCode());                 //错误id;
                                    ErrorLst.Add("图层" + item.Key + "的字段" + fieldName + "的值不能为空");   //错误描述
                                    ErrorLst.Add(pMapx);                                            //...
                                    ErrorLst.Add(pMapy);                                            //...
                                    ErrorLst.Add(item.Key);
                                    ErrorLst.Add(pFeature.OID);
                                    ErrorLst.Add("");
                                    ErrorLst.Add(-1);
                                    ErrorLst.Add(false);
                                    ErrorLst.Add(System.DateTime.Now.ToString());

                                    //传递错误日志
                                    IDataErrInfo      dataErrInfo       = new DataErrInfo(ErrorLst);
                                    DataErrTreatEvent dataErrTreatEvent = new DataErrTreatEvent(dataErrInfo);
                                    DataErrTreat(hook.DataCheckParaSet as object, dataErrTreatEvent);
                                }
                                pFeature = pFeaCusor.NextFeature();
                            }

                            //释放cursor
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeaCusor);
                        }
                    }


                    //进度条加1
                    pValue++;
                    eInfo.Value = pValue;
                    GeoDataChecker.GeoDataChecker_ProgressShow((object)GeoDataChecker._ProgressBarInner, eInfo);
                }
            }
            catch (Exception ex)
            {
                outError = ex;
            }
        }