Exemplo n.º 1
0
        /// <summary>
        /// Check数据是否在矿界范围之内。
        /// </summary>
        /// <params name="file"></params>
        /// <returns></returns>
        private bool withIn(string file)
        {
            try
            {
                bool   within = true;
                ILayer pLayer = DataEditCommon.GetLayerByName(DataEditCommon.g_pMap, LayerNames.LAYER_ALIAS_MINE_BOUNDARY);
                if (pLayer == null)
                {
                    MessageBox.Show("煤层矿界图层缺失!");
                    return(false);
                }
                IFeatureLayer pFeatureLayer = (IFeatureLayer)pLayer;
                IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
                IQueryFilter  pFilter       = new QueryFilterClass();
                pFilter.WhereClause = "layer='预警矿界'";
                IFeatureCursor   pCursor  = pFeatureClass.Search(pFilter, false);
                IFeature         pFeature = pCursor.NextFeature();
                List <IGeometry> list     = new List <IGeometry>();
                if (pFeature == null)
                {
                    return(false);
                }
                ISegmentCollection pSegmentCollection = new PolygonClass();
                while (pFeature != null)
                {
                    list.Add(pFeature.Shape);
                    pFeature = pCursor.NextFeature();
                }
                IGeometry pgeoLine = MyMapHelp.GetGeoFromGeos(list);
                pSegmentCollection = pgeoLine as ISegmentCollection;
                IPolyline pPolyline = pSegmentCollection as IPolyline;

                IPolygon pPolygon = DataEditCommon.PolylineToPolygon(pPolyline);

                string[] liststr = File.ReadAllLines(file);
                list = new List <IGeometry>();
                IPoint pt = new PointClass();
                double x, y;
                for (int i = 0; i < liststr.Length; i++)
                {
                    pt = new PointClass();
                    if (!double.TryParse(liststr[i].Split(',')[0], out x) || !double.TryParse(liststr[i].Split(',')[1], out y))
                    {
                        MessageBox.Show("存在非数字的坐标,请检查!");
                        return(false);
                    }
                    pt.X = x;
                    pt.Y = y;
                    list.Add(pt);
                }
                if (list.Count < 3)
                {
                    MessageBox.Show("离散点数据为空或小于三个,无法生成等值线!");
                    return(false);
                }
                for (int i = 0; i < liststr.Length; i++)
                {
                    for (int j = 0; j < liststr.Length; j++)
                    {
                        if (liststr[i].Split(',')[0] == liststr[j].Split(',')[0] && liststr[i].Split(',')[1] == liststr[j].Split(',')[1] && liststr[i].Split(',')[2] == liststr[j].Split(',')[2] && i != j)
                        {
                            MessageBox.Show("存在重复点,请检查!");
                            return(false);
                        }
                    }
                }
                List <IGeometry> listrt = MyMapHelp.withIn(pPolygon, list);
                if (listrt.Count > 0)
                {
                    within = false;
                    DialogResult dr = MessageBox.Show("存在超边界的坐标,是否立即查看?", "", MessageBoxButtons.YesNo);
                    if (dr == DialogResult.Yes)
                    {
                        string strlen = "";
                        for (int i = 0; i < listrt.Count; i++)
                        {
                            pt      = listrt[i] as IPoint;
                            strlen += pt.X.ToString() + "," + pt.Y.ToString() + " \r\n";
                        }
                        string filename = Application.StartupPath + "\\ContentError.txt";
                        File.WriteAllText(filename, strlen);
                        Process.Start(filename);
                    }
                }
                return(within);
            }
            catch (Exception ex)
            {
                MessageBox.Show("获取矿界失败!" + ex.Message);
                return(false);
            }
        }