Beispiel #1
0
        /*private DataTable DoCrossAnalysis(Dictionary<string, List<IFeature>> dict,int crossType)
         * {
         *  if (dict.Count <= 0) return null;
         *  //dicCross = new Dictionary<string,string>();
         *  hsCross = new HashSet<string>();
         *  DataTable dt = new DataTable();
         *  dt.Columns.Add(new DataColumn("图层"));
         *  foreach (string s in dict.Keys)
         *  {
         *      dt.Columns.Add(new DataColumn(s));
         *  }
         *  try
         *  {
         *      foreach (MajorClass mca in LogicDataStructureManage2D.Instance.GetAllMajorClass())
         *      {
         *          if (!dict.ContainsKey(mca.Alias)) continue;
         *          List<IFeature> linesA = dict[mca.Alias];
         *          DataRow dr = dt.NewRow();
         *          dr["图层"] = mca.Alias;
         *          foreach (MajorClass mcb in LogicDataStructureManage2D.Instance.GetAllMajorClass())
         *          {
         *              if (!dict.ContainsKey(mcb.Alias)) continue;
         *              List<IFeature> linesB = dict[mcb.Alias];
         *              int count = 0;
         *
         *              //if (linesB == linesA) continue;
         *
         *              int n = 0;
         *              foreach (IFeature la in linesA)
         *              {
         *                  count++;
         *                  WaitForm.SetCaption("正在分析【" + mca.Alias + "】与【" + mcb.Alias + "】," + count + "/" + linesA.Count);
         *                  int dA = GetDiameter(la, this._diameter);
         *                  IPolyline lineA = la.Shape as IPolyline;
         *                  foreach (IFeature lb in linesB)
         *                  {
         *                      if (la == lb) continue;
         *                      int dB = GetDiameter(lb, this._diameter);
         *                      IPolyline lineB = lb.Shape as IPolyline;
         *                      //ITopologicalOperator topo = lineA as ITopologicalOperator;
         *                      ITopologicalOperator topo = lineA as ITopologicalOperator;
         *                      topo.Simplify();
         *                      IGeometry geo = topo.Intersect(lineB, esriGeometryDimension.esriGeometry0Dimension);
         *                      if (geo.IsEmpty) continue;
         *                      IPointCollection pc = geo as IPointCollection;
         *                      IPoint point = pc.get_Point(0);
         *                      //if (point == lineA.FromPoint || point == lineA.ToPoint || point == lineB.FromPoint || point == lineB.ToPoint)
         *                      if(IsPointSame(point,lineA.FromPoint)||IsPointSame(point,lineA.ToPoint)||IsPointSame(point,lineB.FromPoint)||IsPointSame(point,lineB.ToPoint))
         *                          continue;
         *                      double disA = double.MaxValue;
         *                      double zA = double.MaxValue;
         *                      GetDistanceAndZ(lineA, point, out disA, out zA);
         *                      double disB = double.MaxValue;
         *                      double zB = double.MaxValue;
         *                      GetDistanceAndZ(lineB, point, out disB, out zB);
         *                      double l = Double.MaxValue;
         *                      if (crossType == 0)
         *                      {
         *                          l = Convert.ToDouble((dA + dB) / 2000);
         *                      }
         *                      else
         *                      {
         *                          if (dictVertical.ContainsKey(mca.Name + "_" + mcb.Name))
         *
         *
         *                              l = (((double)dA +(double) dB) / 2000) + dictVertical[mca.Name + "_" + mcb.Name];
         *                      }
         *                      if (l == Double.MaxValue) continue;
         *                      if (System.Math.Abs(zA - zB) > l) continue;
         *                      else
         *                      {
         *                          string idA = mca.Name + "_" + la.OID;
         *                          string idB = mcb.Name + "_" + lb.OID;
         *                          hsCross.Add(idA + "," + idB);
         *                          n++;
         *                          //if (dicCross.ContainsValue(idA) && dicCross.ContainsKey(idB))
         *                          //{
         *                          //    if (dicCross[idB] == idA) continue;
         *
         *                          //}
         *                          //else
         *                          //{
         *                          //    if (dicCross.ContainsKey(idA)) continue;
         *                          //    dicCross[idA] = idB;
         *                          //    n++;
         *
         *                          //}
         *                          //cross.Add(idA + "," + idB);
         *                          //n++;
         *                      }
         *                  }
         *              }
         *              dr[mcb.Alias] = n;
         *
         *          }
         *          dt.Rows.Add(dr);
         *      }
         *      return dt;
         *  }
         *  catch (System.Exception ex)
         *  {
         *      return null;
         *  }
         *
         * }
         *
         * private bool IsPointSame(IPoint p1, IPoint p2)
         * {
         *  if (p1.X == p2.X && p1.Y == p2.Y && p1.Z == p2.Z) return true;
         *  else return false;
         * }
         * private void GetDistanceAndZ(IPolyline line, IPoint point, out double dis, out double z)
         * {
         *  if (line == null || point == null)
         *  {
         *      dis = double.MaxValue;
         *      z = double.MaxValue;
         *      return;
         *  }
         *  else
         *  {
         *      dis = System.Math.Sqrt((point.X - line.FromPoint.X) * (point.X - line.FromPoint.X) + (point.Y - line.FromPoint.Y) * (point.Y - line.FromPoint.Y));
         *      z = dis * (line.ToPoint.Z - line.FromPoint.Z) / line.Length + line.FromPoint.Z;
         *  }
         *
         * }
         *
         * private int GetDiameter(IFeature feature, string fieldName)
         * {
         *  IFields fields = feature.Fields;
         *  int index = fields.FindField(this._diameter);
         *  string d = feature.get_Value(index).ToString();
         *  int h;
         *  if (d.Contains("*"))
         *  {
         *      int n = d.IndexOf("*");
         *      string strd = d.Substring(n + 1);
         *      System.Int32.TryParse(strd, out h);
         *  }
         *  else
         *  {
         *      System.Int32.TryParse(d, out h);
         *  }
         *  return h;
         * }*/

        private void lbx_CrossPipe_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                app.Current2DMapControl.ActiveView.FocusMap.ClearSelection();
                string temp  = this.lbx_CrossPipe.SelectedItem.ToString();
                string lineA = temp.Substring(0, (temp.IndexOf(",")));
                string lineB = temp.Substring(temp.IndexOf(",") + 1);
                if (lineA == null || lineB == null)
                {
                    return;
                }
                string mcNameA = lineA.Substring(0, lineA.IndexOf("_"));
                string fOidA   = lineA.Substring(lineA.IndexOf("_") + 1);
                string mcNameB = lineB.Substring(0, lineB.IndexOf("_"));
                string fOidB   = lineB.Substring(lineB.IndexOf("_") + 1);
                int    OIDA;
                int    OIDB;
                Int32.TryParse(fOidA, out OIDA);
                Int32.TryParse(fOidB, out OIDB);

                foreach (MajorClass mc in LogicDataStructureManage2D.Instance.GetAllMajorClass())
                {
                    if (mc.Name == mcNameA)
                    {
                        bool     have      = false;
                        string[] arrFc2DId = mc.Fc2D.Split(';');
                        if (arrFc2DId == null)
                        {
                            continue;
                        }
                        foreach (SubClass sc in mc.SubClasses)
                        {
                            if (!sc.Visible2D)
                            {
                                continue;
                            }
                            foreach (string fc2DId in arrFc2DId)
                            {
                                DF2DFeatureClass dffc = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fc2DId);//根据要素类ID得到DF2DFC
                                if (dffc == null)
                                {
                                    continue;
                                }
                                FacilityClass facc = dffc.GetFacilityClass(); //得到设施类
                                IFeatureClass fc   = dffc.GetFeatureClass();  //得到要素类
                                IFeatureLayer fl   = dffc.GetFeatureLayer();
                                if (fc == null || facc == null || facc.Name != "PipeLine")
                                {
                                    continue;
                                }
                                if (fl == null)
                                {
                                    return;
                                }
                                IFeature feature1 = fc.GetFeature(OIDA);
                                if (feature1 == null)
                                {
                                    return;
                                }
                                app.Current2DMapControl.ActiveView.FocusMap.SelectFeature(fl, feature1);
                                //app.Current2DMapControl.ActiveView.FocusMap.SelectFeature(fl, feature2);
                                IPolyline polyline = feature1.Shape as IPolyline;
                                IPoint    point    = polyline.ToPoint;
                                app.Current2DMapControl.MapScale = 500;
                                app.Current2DMapControl.CenterAt(point);
                                have = true;
                            }
                            if (have)
                            {
                                break;
                            }
                        }
                    }
                    if (mc.Name == mcNameB)
                    {
                        bool     have      = false;
                        string[] arrFc2DId = mc.Fc2D.Split(';');
                        if (arrFc2DId == null)
                        {
                            continue;
                        }
                        foreach (SubClass sc in mc.SubClasses)
                        {
                            if (!sc.Visible2D)
                            {
                                continue;
                            }
                            foreach (string fc2DId in arrFc2DId)
                            {
                                DF2DFeatureClass dffc = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fc2DId);//根据要素类ID得到DF2DFC
                                if (dffc == null)
                                {
                                    continue;
                                }
                                FacilityClass facc = dffc.GetFacilityClass(); //得到设施类
                                IFeatureClass fc   = dffc.GetFeatureClass();  //得到要素类
                                IFeatureLayer fl   = dffc.GetFeatureLayer();
                                if (fc == null || facc == null || facc.Name != "PipeLine")
                                {
                                    continue;
                                }
                                if (fl == null)
                                {
                                    return;
                                }
                                IFeature feature = fc.GetFeature(OIDB);
                                app.Current2DMapControl.ActiveView.FocusMap.SelectFeature(fl, feature);
                                IPolyline polyline = feature.Shape as IPolyline;
                                IPoint    point    = polyline.FromPoint;
                                app.Current2DMapControl.MapScale = 500;
                                app.Current2DMapControl.CenterAt(point);

                                have = true;
                            }
                            if (have)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
            }
        }
        public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY)
        {
            DF2DApplication app = DF2DApplication.Application;

            m_ActiveView = app.Current2DMapControl.ActiveView;
            IGraphicsContainer pGC = m_ActiveView.GraphicsContainer;

            if (this.m_ActiveView.FocusMap.FeatureSelection != null)
            {
                this.m_ActiveView.FocusMap.ClearSelection();
            }
            bool ready = false;

            if (app == null || app.Current2DMapControl == null)
            {
                return;
            }
            IGeometry pGeo = null;

            try
            {
                if (button == 1)
                {
                    PointClass searchPoint = new PointClass();
                    searchPoint.PutCoords(mapX, mapY);
                    pGeo = PublicFunction.DoBuffer(searchPoint,
                                                   PublicFunction.ConvertPixelsToMapUnits(m_ActiveView, GlobalValue.System_Selection_Option().Tolerate));
                    if (pGeo == null)
                    {
                        return;
                    }
                    ready = true;
                    if (ready)
                    {
                        bool haveone = false;

                        foreach (LogicGroup lg in LogicDataStructureManage2D.Instance.RootLogicGroups)
                        {
                            foreach (MajorClass mc in lg.MajorClasses)
                            {
                                string[] arrFc2DId = mc.Fc2D.Split(';');
                                if (arrFc2DId == null)
                                {
                                    continue;
                                }
                                IFeatureCursor pFeatureCursor = null;
                                IFeature       pFeature       = null;

                                foreach (string fc2DId in arrFc2DId)
                                {
                                    DF2DFeatureClass dffc = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fc2DId);
                                    if (dffc == null)
                                    {
                                        continue;
                                    }
                                    IFeatureClass fc   = dffc.GetFeatureClass();
                                    FacilityClass facc = dffc.GetFacilityClass();
                                    if (facc.Name != "PipeNode")
                                    {
                                        continue;
                                    }
                                    IFeatureLayer fl = dffc.GetFeatureLayer();
                                    if (fc == null || pGeo == null || fl == null)
                                    {
                                        continue;
                                    }
                                    if (!fl.Visible)
                                    {
                                        continue;
                                    }

                                    ISpatialFilter pSpatialFilter = new SpatialFilter();
                                    pSpatialFilter.Geometry   = pGeo;
                                    pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                                    pFeatureCursor            = fc.Search(pSpatialFilter, false);
                                    if (pFeatureCursor == null)
                                    {
                                        continue;
                                    }
                                    pFeature = pFeatureCursor.NextFeature();
                                    if (pFeature == null)
                                    {
                                        continue;
                                    }
                                    haveone = true;

                                    IGeometry pGeometry = pFeature.Shape as IGeometry;
                                    if (pGeometry.GeometryType == esriGeometryType.esriGeometryPoint)
                                    {
                                        IPoint pPoint = pGeometry as IPoint;
                                        if (this._bFinished)
                                        {
                                            this._bFinished = false;
                                            this._startFCID = fc.FeatureClassID.ToString();
                                            this._startOid  = pFeature.OID;
                                            AddCallout(pPoint, "起点");
                                            app.Current2DMapControl.ActiveView.Refresh();
                                        }
                                        else
                                        {
                                            if (this._startFCID == fc.FeatureClassID.ToString() && this._startOid == pFeature.OID)
                                            {
                                                XtraMessageBox.Show("您选中的是同一个管点设施。", "提示");
                                                return;
                                            }
                                            this._bFinished = true;
                                            AddCallout(pPoint, "终点");
                                            app.Current2DMapControl.ActiveView.Refresh();
                                            if (this._startFCID != fc.FeatureClassID.ToString())
                                            {
                                                XtraMessageBox.Show("您选中的不是同一类管点设施。", "提示");
                                                return;
                                            }
                                            else
                                            {
                                                WaitForm.Start("正在分析...", "请稍后");
                                                TopoClass2D tc = FacilityInfoService2D.GetTopoClassByFeatureClassID(fc.FeatureClassID.ToString());
                                                if (tc == null)
                                                {
                                                    return;
                                                }
                                                TopoNetwork net = tc.GetNetwork();
                                                if (net == null)
                                                {
                                                    WaitForm.Stop();
                                                    XtraMessageBox.Show("构建拓扑网络失败!", "提示");
                                                    return;
                                                }
                                                else
                                                {
                                                    string        startId = this._startFCID + "_" + this._startOid.ToString();
                                                    string        endId   = fc.FeatureClassID.ToString() + "_" + pFeature.OID.ToString();
                                                    List <string> path;
                                                    double        shortestLength = net.SPFA(startId, endId, out path);
                                                    if ((shortestLength > 0.0 && shortestLength != double.MaxValue) || (path != null && path.Count > 0))
                                                    {
                                                        List <IPoint>    listPt   = new List <IPoint>();
                                                        IPointCollection pointCol = new PolylineClass();
                                                        foreach (string nodeId in path)
                                                        {
                                                            int              index    = nodeId.LastIndexOf("_");
                                                            string           fcID     = nodeId.Substring(0, index);
                                                            string           oid      = nodeId.Substring(index + 1, nodeId.Length - index - 1);
                                                            DF2DFeatureClass dffcTemp = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fcID);
                                                            if (dffcTemp == null || dffcTemp.GetFeatureClass() == null)
                                                            {
                                                                continue;
                                                            }
                                                            if (dffcTemp.GetFacilityClassName() != "PipeNode")
                                                            {
                                                                continue;
                                                            }
                                                            IQueryFilter filter = new QueryFilter();
                                                            filter.WhereClause = "OBJECTID =" + oid;
                                                            filter.SubFields   = "OBJECTID ,SHAPE";
                                                            IFeature       feature = null;
                                                            IFeatureCursor cursor  = null;
                                                            try
                                                            {
                                                                cursor = dffcTemp.GetFeatureClass().Search(filter, false);
                                                                while ((feature = cursor.NextFeature()) != null)
                                                                {
                                                                    if (feature.Shape != null && feature.Shape is IGeometry)
                                                                    {
                                                                        IGeometry geo = feature.Shape as IGeometry;
                                                                        switch (geo.GeometryType)
                                                                        {
                                                                        case esriGeometryType.esriGeometryPoint:
                                                                            IPoint pt = geo as IPoint;
                                                                            //pt.Z = pt.Z + 1;
                                                                            listPt.Add(pt);
                                                                            pointCol.AddPoint(pt);
                                                                            break;
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                            catch (System.Exception ex)
                                                            {
                                                            }
                                                            finally
                                                            {
                                                                if (cursor != null)
                                                                {
                                                                    System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor);
                                                                    cursor = null;
                                                                }
                                                                if (feature != null)
                                                                {
                                                                    System.Runtime.InteropServices.Marshal.ReleaseComObject(feature);
                                                                    feature = null;
                                                                }
                                                            }
                                                        }
                                                        if (listPt.Count > 0)
                                                        {
                                                            IPolyline         polyline    = pointCol as IPolyline;
                                                            ISimpleLineSymbol pLineSymbol = new SimpleLineSymbol();
                                                            pLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
                                                            pLineSymbol.Width = 5;
                                                            pLineSymbol.Color = GetRGBColor(0, 230, 240);
                                                            IElement elementL = new LineElement();
                                                            elementL.Geometry = polyline;
                                                            ILineElement pLineElement = elementL as ILineElement;
                                                            pLineElement.Symbol = pLineSymbol;
                                                            pGC.AddElement(elementL, 0);

                                                            ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbol();
                                                            simpleMarkerSymbol.Color   = GetRGBColor(255, 0, 0);
                                                            simpleMarkerSymbol.Outline = false;
                                                            simpleMarkerSymbol.Size    = 5;
                                                            simpleMarkerSymbol.Style   = esriSimpleMarkerStyle.esriSMSCircle;

                                                            foreach (IPoint pt in listPt)
                                                            {
                                                                try
                                                                {
                                                                    IMarkerElement pMarkerElement = new MarkerElementClass();
                                                                    pMarkerElement.Symbol = simpleMarkerSymbol;
                                                                    IElement pElement = pMarkerElement as IElement;
                                                                    pElement.Geometry = pt;
                                                                    pGC.AddElement(pElement, 0);
                                                                }
                                                                catch (System.Exception ex)
                                                                {
                                                                    continue;
                                                                }
                                                            }
                                                        }

                                                        app.Current2DMapControl.ActiveView.Refresh();
                                                    }
                                                    else
                                                    {
                                                        WaitForm.Stop();
                                                        XtraMessageBox.Show("两点不连通!", "提示");
                                                        pGC.DeleteAllElements();
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                if (haveone)
                                {
                                    break;
                                }
                            }
                            if (haveone)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                XtraMessageBox.Show("分析出错!", "提示");
            }
            finally
            {
                WaitForm.Stop();
            }
        }
Beispiel #3
0
        //public void ShowProperty()
        //{
        //    try
        //    {
        //        _dtShow.Rows.Clear();

        //        if (_dt == null || _dt.Rows.Count < _num) return;
        //        this.bsiInfo.Caption = "浏览 " + _num + "/" + _dt.Rows.Count;
        //        DataRow dr = _dt.Rows[_num - 1];
        //        for (int i = 0; i < _dt.Columns.Count; i++)
        //        {
        //            String columnName = _dt.Columns[i].ColumnName;
        //            if (columnName == null) continue;

        //            if (dr[columnName] == null || dr[columnName].ToString() == "") continue;
        //            string value = dr[columnName].ToString();
        //            double dTemp = 0.0;
        //            string dStrTemp = "";
        //            bool bDouble = double.TryParse(value, out dTemp);
        //            if (bDouble) dStrTemp = dTemp.ToString("0.00");
        //            else dStrTemp = value;
        //            DataRow drnew = _dtShow.NewRow();
        //            drnew["Property"] = columnName;
        //            drnew["Value"] = dStrTemp;
        //            _dtShow.Rows.Add(drnew);
        //        }
        //    }
        //    catch (System.Exception ex)
        //    {

        //    }
        //}
        private void ShowProperty()
        {
            try
            {
                if (_currentClass == null)
                {
                    return;
                }
                _dtShow.Rows.Clear();
                DataTable dt = _dict[_currentClass];
                if (dt == null || dt.Rows.Count < _num)
                {
                    return;
                }
                if (dt.Rows.Count == 0 || dt.Rows.Count == 1)
                {
                    this.bbiFirst.Enabled       = false;
                    this.bbiPreviousOne.Enabled = false;
                    this.bbiNextOne.Enabled     = false;
                    this.bbiLastOne.Enabled     = false;
                }
                else
                {
                    if (_num == 1)
                    {
                        this.bbiFirst.Enabled       = false;
                        this.bbiPreviousOne.Enabled = false;
                        this.bbiNextOne.Enabled     = true;
                        this.bbiLastOne.Enabled     = true;
                    }
                    else if (_num == dt.Rows.Count)
                    {
                        this.bbiFirst.Enabled       = true;
                        this.bbiPreviousOne.Enabled = true;
                        this.bbiNextOne.Enabled     = false;
                        this.bbiLastOne.Enabled     = false;
                    }
                    else
                    {
                        this.bbiFirst.Enabled       = true;
                        this.bbiPreviousOne.Enabled = true;
                        this.bbiNextOne.Enabled     = true;
                        this.bbiLastOne.Enabled     = true;
                    }
                }
                this.bsiInfo.Caption = "浏览 " + _num + "/" + dt.Rows.Count;
                DataRow dr = dt.Rows[_num - 1];
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    DataRow drnew = _dtShow.NewRow();
                    drnew["Property"] = dt.Columns[i].Caption;
                    drnew["Value"]    = dr[dt.Columns[i].ColumnName];
                    _dtShow.Rows.Add(drnew);
                }
                #region 定位
                DF2DApplication app = DF2DApplication.Application;
                if (app == null || app.Current2DMapControl == null)
                {
                    return;
                }
                if (_currentClass == "建筑物" || _currentClass == "构筑物")
                {
                    FacilityClass fac;
                    if (_currentClass == "建筑物")
                    {
                        fac = FacilityClassManager.Instance.GetFacilityClassByName("Building");
                    }
                    else
                    {
                        fac = FacilityClassManager.Instance.GetFacilityClassByName("Structure");
                    }
                    if (fac != null)
                    {
                        string[]         fc2D = fac.Fc2D.Split(';');
                        DF2DFeatureClass dffc = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fc2D[0]);
                        if (dffc == null)
                        {
                            return;
                        }
                        IFeatureClass fc = dffc.GetFeatureClass();
                        IFeatureLayer fl = dffc.GetFeatureLayer();
                        if (fc == null)
                        {
                            return;
                        }
                        int      oid     = int.Parse(dr["oid"].ToString());
                        IFeature feature = fc.GetFeature(oid);
                        app.Current2DMapControl.ActiveView.FocusMap.ClearSelection();
                        app.Current2DMapControl.ActiveView.FocusMap.SelectFeature(fl as ILayer, feature);
                        app.Current2DMapControl.ActiveView.Refresh();
                        IGeometry geo    = feature.Shape;
                        IEnvelope pEnv   = geo.Envelope;
                        IPoint    pPoint = new PointClass();
                        pPoint.PutCoords((pEnv.XMax + pEnv.XMin) / 2, (pEnv.YMax + pEnv.YMin) / 2);
                        app.Current2DMapControl.MapScale = 500;
                        app.Current2DMapControl.CenterAt(pPoint);
                    }
                }
                else
                {
                    MajorClass mc = LogicDataStructureManage2D.Instance.GetMajorClassBySubClassName(_currentClass);
                    if (mc != null && !string.IsNullOrEmpty(mc.Fc2D))
                    {
                        string[] arrFc2DId = mc.Fc2D.Split(';');
                        if (arrFc2DId == null)
                        {
                            return;
                        }
                        foreach (string fc2DId in arrFc2DId)
                        {
                            DF2DFeatureClass dffc = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fc2DId);
                            if (dffc == null)
                            {
                                continue;
                            }
                            FacilityClass fac = dffc.GetFacilityClass();
                            if (fac == null || fac.Name != dt.TableName)
                            {
                                continue;
                            }
                            IFeatureClass fc = dffc.GetFeatureClass();
                            IFeatureLayer fl = dffc.GetFeatureLayer();
                            if (fc == null)
                            {
                                continue;
                            }
                            int      oid     = int.Parse(dr["oid"].ToString());
                            IFeature feature = fc.GetFeature(oid);
                            app.Current2DMapControl.ActiveView.FocusMap.ClearSelection();
                            app.Current2DMapControl.ActiveView.FocusMap.SelectFeature(fl as ILayer, feature);
                            app.Current2DMapControl.ActiveView.Refresh();
                            IGeometry geo    = feature.Shape;
                            IEnvelope pEnv   = geo.Envelope;
                            IPoint    pPoint = new PointClass();
                            pPoint.PutCoords((pEnv.XMax + pEnv.XMin) / 2, (pEnv.YMax + pEnv.YMin) / 2);
                            app.Current2DMapControl.MapScale = 500;
                            app.Current2DMapControl.CenterAt(pPoint);
                        }
                    }
                }

                #endregion
            }
            catch (Exception ex)
            {
            }
        }
Beispiel #4
0
        public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY)
        {
            IScreenDisplay pScr = m_pActiveView.ScreenDisplay;
            //跟踪画线
            IRubberBand pRB = new RubberLineClass();

            m_pGeoTrack = pRB.TrackNew(pScr, null);
            if ((m_pGeoTrack as IPointCollection).PointCount != 2)
            {
                XtraMessageBox.Show("请使用鼠标制定两点确定扯旗的管线");
                return;
            }
            Element.DeleteElement(m_pActiveView.GraphicsContainer, "cq");
            Element.AddGraphics(m_pActiveView.GraphicsContainer, m_pGeoTrack, GetDefaultSymbol(esriGeometryType.esriGeometryPolyline), "dmx");
            IElement pElement = Element.GetElementByName(m_pMapControl.ActiveView.GraphicsContainer, "cq");

            if (pElement != null)
            {
                m_pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
            }

            IFeature             pFeature;
            IGeometry            pGeo;
            IGeometry            pPipeLineGeo;
            IFeatureClass        pFeatureClass;
            IFeatureCursor       pFeaCur;
            ITopologicalOperator pTopo;
            string classify   = "";
            string startNo    = "";
            string endNo      = "";
            string material   = "";
            string coverstyle = "";
            string diameter   = "";
            string road       = "";
            double distance;

            m_IntersectPipes = new List <IntersectPipe>();



            string[] sysFields = new string[] { "Classify", "StartNo", "EndNo", "Material", "CoverStyle", "Diameter", "Road" };
            string[] fields    = new string[] { "类别", "起点号", "终点号", "材质", "埋设方式", "管径", "所在道路" };
            try
            {
                foreach (MajorClass mc in LogicDataStructureManage2D.Instance.GetAllMajorClass())
                {
                    WaitForm.Start("正在查询...", "请稍后");
                    string[] arrFc2DId = mc.Fc2D.Split(';');//将二级大类所对应的要素类ID转换为数组
                    if (arrFc2DId == null)
                    {
                        continue;
                    }

                    foreach (SubClass sc in mc.SubClasses)
                    {
                        if (!sc.Visible2D)
                        {
                            continue;
                        }
                        foreach (string fc2DId in arrFc2DId)                                                      //遍历二级子类所对应的要素类ID
                        {
                            DF2DFeatureClass dffc = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fc2DId); //根据要素类ID得到DF2DFC
                            if (dffc == null)
                            {
                                continue;
                            }
                            FacilityClass fcc = dffc.GetFacilityClass();
                            if (fcc.Name != "PipeLine")
                            {
                                continue;
                            }
                            IFeatureLayer fl = dffc.GetFeatureLayer();

                            ISpatialFilter pSpatialFilter = new SpatialFilterClass();
                            pSpatialFilter.Geometry    = m_pGeoTrack;
                            pSpatialFilter.SpatialRel  = esriSpatialRelEnum.esriSpatialRelIntersects;
                            pSpatialFilter.WhereClause = "SMSCODE =  '" + sc.Name + "'";
                            IFeatureClass fc = dffc.GetFeatureClass();
                            pFeaCur = fc.Search(pSpatialFilter, false);
                            while ((pFeature = pFeaCur.NextFeature()) != null)
                            {
                                foreach (string field in sysFields)
                                {
                                    DFDataConfig.Class.FieldInfo fi = fcc.GetFieldInfoBySystemName(field);
                                    if (fi == null)
                                    {
                                        continue;
                                    }
                                    int    index = fc.Fields.FindField(fi.Name);
                                    object obj   = pFeature.get_Value(index);
                                    switch (field)
                                    {
                                    case "Classify":
                                        classify = obj.ToString();
                                        break;

                                    case "StartNo":
                                        startNo = obj.ToString();
                                        break;

                                    case "EndNo":
                                        endNo = obj.ToString();
                                        break;

                                    case "Material":
                                        material = obj.ToString();
                                        break;

                                    case "CoverStyle":
                                        coverstyle = obj.ToString();
                                        break;

                                    case "Diameter":
                                        diameter = obj.ToString();
                                        break;

                                    case "Road":
                                        road = obj.ToString();
                                        break;
                                    }
                                }
                                IPolyline            pline    = m_pGeoTrack as IPolyline;
                                IPoint               point1   = pline.ToPoint;
                                ITopologicalOperator topo     = pFeature.Shape as ITopologicalOperator;
                                IGeometry            geo      = topo.Intersect(m_pGeoTrack, esriGeometryDimension.esriGeometry0Dimension);
                                IPointCollection     pointCol = geo as IPointCollection;
                                IPoint               point2   = pointCol.get_Point(pointCol.PointCount - 1);
                                distance = GetDistanceOfTwoPoints(point1, point2);
                                IntersectPipe interPipe = new IntersectPipe(pFeature, fl, distance, classify, startNo, endNo, material, coverstyle, diameter, road);
                                m_IntersectPipes.Add(interPipe);
                            }
                        }
                    }
                }
                if (m_IntersectPipes.Count == 0)
                {
                    return;
                }
                List <IntersectPipe> orderList = m_IntersectPipes.OrderBy(i => i.Distance).ToList <IntersectPipe>();
                DrawPipeLabels();

                int n = 0;
                foreach (IntersectPipe interPipe in orderList)
                {
                    WaitForm.SetCaption("正在输出属性,请稍后...");
                    DrawPipeInfo(interPipe, n);
                    ++n;
                }
                WaitForm.Stop();
            }
            catch (System.Exception ex)
            {
                WaitForm.Stop();
            }
        }
        public override void OnMouseDown(int button, int shift, int x, int y, double mapX, double mapY)
        {
            DF2DApplication    app = DF2DApplication.Application;
            IGraphicsContainer gc  = app.Current2DMapControl.Map as IGraphicsContainer;

            if (app == null || app.Current2DMapControl == null)
            {
                return;
            }
            m_pActiveView = app.Current2DMapControl.ActiveView;
            m_Display     = app.Current2DMapControl.ActiveView.ScreenDisplay;
            IFeatureCursor pFeaCur;
            IFeature       pFeature;
            string         classify   = "";
            string         startNo    = "";
            string         endNo      = "";
            string         material   = "";
            string         coverstyle = "";
            string         diameter   = "";
            string         road       = "";
            bool           have       = false;

            try
            {
                if (button == 1)
                {
                    IRubberBand band = new RubberRectangularPolygonClass();
                    m_pGeoTrack = band.TrackNew(m_Display, null);

                    if (m_pGeoTrack.IsEmpty)
                    {
                        IPoint searchPoint = new PointClass();
                        searchPoint.PutCoords(mapX, mapY);
                        m_pGeoTrack = DF2DPipe.Class.PublicFunction.DoBuffer(searchPoint, DF2DPipe.Class.PublicFunction.ConvertPixelsToMapUnits(m_pActiveView, GlobalValue.System_Selection_Option().Tolerate));
                        //m_ActiveView.FocusMap.SelectByShape(geo, s, false);
                    }
                    WaitForm.Start("正在查询...", "请稍后");
                    foreach (MajorClass mc in LogicDataStructureManage2D.Instance.GetAllMajorClass())
                    {
                        if (have)
                        {
                            break;
                        }
                        string[] arrFc2DId = mc.Fc2D.Split(';');//将二级大类所对应的要素类ID转换为数组
                        if (arrFc2DId == null)
                        {
                            continue;
                        }
                        foreach (SubClass sc in mc.SubClasses)
                        {
                            if (have)
                            {
                                break;
                            }
                            if (!sc.Visible2D)
                            {
                                continue;
                            }
                            foreach (string fc2DId in arrFc2DId)                                                      //遍历二级子类所对应的要素类ID
                            {
                                DF2DFeatureClass dffc = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fc2DId); //根据要素类ID得到DF2DFC
                                if (dffc == null)
                                {
                                    continue;
                                }
                                FacilityClass fcc = dffc.GetFacilityClass();
                                if (fcc.Name != "PipeLine")
                                {
                                    continue;
                                }
                                IFeatureLayer  fl             = dffc.GetFeatureLayer();
                                IFeatureClass  fc             = dffc.GetFeatureClass();
                                ISpatialFilter pSpatialFilter = new SpatialFilterClass();
                                pSpatialFilter.Geometry    = m_pGeoTrack;
                                pSpatialFilter.SpatialRel  = esriSpatialRelEnum.esriSpatialRelIntersects;
                                pSpatialFilter.WhereClause = "SMSCODE =  '" + sc.Name + "'";
                                pFeaCur  = fc.Search(pSpatialFilter, false);
                                pFeature = pFeaCur.NextFeature();
                                if (pFeature == null)
                                {
                                    continue;
                                }
                                foreach (string field in sysFields)
                                {
                                    DFDataConfig.Class.FieldInfo fi = fcc.GetFieldInfoBySystemName(field);
                                    if (fi == null)
                                    {
                                        continue;
                                    }
                                    int    index = fc.Fields.FindField(fi.Name);
                                    object obj   = pFeature.get_Value(index);
                                    switch (field)
                                    {
                                    case "Classify":
                                        classify = obj.ToString();
                                        break;

                                    case "StartNo":
                                        startNo = obj.ToString();
                                        break;

                                    case "EndNo":
                                        endNo = obj.ToString();
                                        break;

                                    case "Material":
                                        material = obj.ToString();
                                        break;

                                    case "CoverStyle":
                                        coverstyle = obj.ToString();
                                        break;

                                    case "Diameter":
                                        diameter = obj.ToString();
                                        break;

                                    case "Road":
                                        road = obj.ToString();
                                        break;
                                    }
                                }
                                m_IntersectPipe = new IntersectPipe(pFeature, fl, 0, classify, startNo, endNo, material, coverstyle, diameter, road);
                                have            = true;
                            }
                        }
                    }
                }
                if (m_IntersectPipe == null)
                {
                    XtraMessageBox.Show("请重新获取单个管线");
                    WaitForm.Stop();
                }
                WaitForm.SetCaption("正在输出属性,请稍后...");
                DrawNodeLabels(m_IntersectPipe.Feature, m_IntersectPipe);
                WaitForm.Stop();
            }
            catch (System.Exception ex)
            {
            }
        }
        private void GetArrPipe()
        {
            //Load_LyrLstToArray();
            IFeature             pFeature;
            IGeometry            pGeo;
            IGeometry            pPipeLineGeo;
            IFeatureClass        pFeatureClass;
            IFeatureCursor       pFeaCur;
            ITopologicalOperator pTopo;

            m_pArrLineLayers.Clear();
            m_pArrIntersectPnt.Clear();
            m_pArrPipes.Clear();
            string scName = "";

            foreach (MajorClass mc in LogicDataStructureManage.Instance.GetAllMajorClass())
            {
                string[] arrFc2DId = mc.Fc2D.Split(';');//将二级大类所对应的要素类ID转换为数组
                if (arrFc2DId == null)
                {
                    continue;
                }

                foreach (SubClass sc in mc.SubClasses)
                {
                    if (!sc.Visible2D)
                    {
                        continue;
                    }
                    foreach (string fc2DId in arrFc2DId)                                                      //遍历二级子类所对应的要素类ID
                    {
                        DF2DFeatureClass dffc = DF2DFeatureClassManager.Instance.GetFeatureClassByID(fc2DId); //根据要素类ID得到DF2DFC
                        if (dffc == null)
                        {
                            continue;
                        }
                        FacilityClass fcc = dffc.GetFacilityClass();
                        if (fcc.Name != "PipeLine")
                        {
                            continue;
                        }
                        IFeatureLayer fl = dffc.GetFeatureLayer();
                        m_pArrLineLayers.Add(fl);

                        ISpatialFilter pSpatialFilter = new SpatialFilterClass();
                        pSpatialFilter.Geometry    = m_pGeoTrack;
                        pSpatialFilter.SpatialRel  = esriSpatialRelEnum.esriSpatialRelIntersects;
                        pSpatialFilter.WhereClause = "SMSCODE =  '" + sc.Name + "'";
                        IFeatureClass fc = dffc.GetFeatureClass();
                        pFeaCur = fc.Search(pSpatialFilter, false);
                        while ((pFeature = pFeaCur.NextFeature()) != null)
                        {
                            m_pArrPipes.Add(pFeature);
                        }
                    }
                }
            }
            //根据交点的X坐标,将管线排序
            double           t;
            IFeature         f;
            IPointCollection p;

            double[] sortX = new double[m_pArrIntersectPnt.Count];
            for (int k = 0; k < m_pArrIntersectPnt.Count; k++)
            {
                p        = m_pArrIntersectPnt[k] as IPointCollection;
                sortX[k] = p.get_Point(0).X;
            }
            for (int j = sortX.Length - 1; j > 0; j--)
            {
                for (int i = 0; i < j; i++)
                {
                    if (sortX[i] > sortX[i + 1])
                    {
                        t            = sortX[i];
                        sortX[i]     = sortX[i + 1];
                        sortX[i + 1] = t;

                        f = m_pArrPipes[i] as IFeature;
                        m_pArrPipes[i]     = m_pArrPipes[i + 1];
                        m_pArrPipes[i + 1] = f;
                    }
                }
            }
        }