protected override void OnMouseMove(MouseEventArgs Args)
    {

      //only pass the point if the mouse button is down
      if (Args.Button.ToString() == "Left")
      {
        //pass X and Y to feedbackMovePoint to transfer to NewEnvelopeFeedback
        feedbackMovePoint = feedbackScreenDisplay.DisplayTransformation.ToMapPoint(Args.X, Args.Y) as ESRI.ArcGIS.Geometry.Point;
        NewEnvelopeFeedback.MoveTo(feedbackMovePoint);
      }
    }
    protected override void OnMouseDown(MouseEventArgs Args)
    {
      //initialize all the variables.
      feedbackEnv = new EnvelopeClass();
      feedbackStartPoint = new ESRI.ArcGIS.Geometry.PointClass();
      feedbackMovePoint = new ESRI.ArcGIS.Geometry.PointClass();
      feedbackLineSymbol = new SimpleLineSymbolClass();
      feedbackScreenDisplay = ArcMap.Document.ActiveView.ScreenDisplay;

      feedbackLineSymbol.Style = esriSimpleLineStyle.esriSLSDashDotDot;

      //initialize a new Envelope feedback class and pass it the symbol and display
      NewEnvelopeFeedback = new NewEnvelopeFeedbackClass();
      NewEnvelopeFeedback.Display = feedbackScreenDisplay;
      NewEnvelopeFeedback.Symbol = feedbackLineSymbol as ISymbol;


      //pass the start point from the mouse position, transforming it to an appropriate map point.
      feedbackStartPoint = feedbackScreenDisplay.DisplayTransformation.ToMapPoint(Args.X, Args.Y) as ESRI.ArcGIS.Geometry.Point;
      NewEnvelopeFeedback.Start(feedbackStartPoint);
    }
Ejemplo n.º 3
0
        private void MapUserIdentify(double mapX, double mapY)
        {
            try
            {
                //axMapControl1.Map.ClearSelection();
                ESRI.ArcGIS.Controls.IMapControl3 m_mapControl = (IMapControl3)axMapControl1.Object;
                IMap        pMap        = axMapControl1.Map;
                IGroupLayer pGroupLayer = new GroupLayer();

                if (pMap.LayerCount == 0)
                {
                    return;
                }
                IEnumLayer pEnumLayer;
                ILayer     pLayer;
                pEnumLayer = pMap.get_Layers(null, true);
                if (pEnumLayer == null)
                {
                    return;
                }
                pEnumLayer.Reset();
                double dCurrScale = m_mapControl.MapScale;
                for (pLayer = pEnumLayer.Next(); pLayer != null; pLayer = pEnumLayer.Next())
                {
                    if (pLayer.Visible)
                    {
                        if (pLayer is IGroupLayer)
                        {
                            continue;
                        }
                        if (pLayer.MinimumScale != 0 && dCurrScale > pLayer.MinimumScale)
                        {
                            continue;
                        }
                        if (pLayer.MaximumScale != 0 && dCurrScale < pLayer.MaximumScale)
                        {
                            continue;
                        }
                        pGroupLayer.Add(pLayer);
                    }
                }

                IPoint pPoint = new ESRI.ArcGIS.Geometry.Point();
                pPoint.X = mapX; pPoint.Y = mapY;
                IIdentifyObj        pIdObj;
                IIdentify           pIdentify = pGroupLayer as IIdentify;
                IArray              pIDArray;
                IFeatureIdentifyObj pFeatIdObj;

                IEnvelope pEnv             = pPoint.Envelope;
                IDisplayTransformation pDT = m_mapControl.ActiveView.ScreenDisplay.DisplayTransformation;
                pEnv.Expand(pDT.VisibleBounds.Width / 200, pDT.VisibleBounds.Height / 200, false);

                pIDArray = pIdentify.Identify(pEnv);

                if (pIDArray == null || pIDArray.Count == 0)
                {
                    return;
                }

                pFeatIdObj = pIDArray.get_Element(0) as IFeatureIdentifyObj;
                pIdObj     = pFeatIdObj as IIdentifyObj;

                IRowIdentifyObject pRowIdentifyObj = pFeatIdObj as IRowIdentifyObject;
                IFeature           pFeature        = pRowIdentifyObj.Row as IFeature;
                if (pFeature != null && pFeature.Shape != null && !pFeature.Shape.IsEmpty)
                {
                    //axMapControl1.FlashShape(pFeature.Shape);
                    axMapControl1.Map.SelectFeature(pIdObj.Layer, pFeature);
                    FlashFeature(axMapControl1, pFeature.Shape);
                }

                //  pIdObj.Flash(m_mapControl.ActiveView.ScreenDisplay);//The Flash method is not supported with ArcGIS Engine, use the IHookActions.DoActions() method with the esriHookActionsFlash for this functionality.
                ILayer pIdentiyLayer = pIdObj.Layer;

                DataTable  pTable      = new DataTable();
                DataColumn pDataColumn = pTable.Columns.Add();
                pDataColumn.ColumnName = "列名";
                pDataColumn            = pTable.Columns.Add();
                pDataColumn.ColumnName = "值";

                DataRow pFirestDataRow = pTable.Rows.Add();
                pFirestDataRow[0] = "所在层";
                pFirestDataRow[1] = pIdentiyLayer.Name;

                if (pIdentiyLayer is IFeatureLayer)
                {
                    IRowIdentifyObject pRowObj = pIdObj as IRowIdentifyObject;
                    //   IRow pRow = pRowObj.Row;

                    IFeature pRow    = pRowObj.Row as IFeature;
                    IFields  pFields = pRow.Fields;

                    for (int i = 0; i < pFields.FieldCount; i++)
                    {
                        IField  pField   = pFields.get_Field(i);
                        DataRow pDataRow = null;

                        /*
                         * switch (pField.Type)
                         * {
                         *  case esriFieldType.esriFieldTypeOID:
                         *      pDataRow = pTable.Rows.Add();
                         *      pDataRow[0] = pField.Name;
                         *      pDataRow[1] = pRow.OID.ToString();
                         *      break;
                         *  case esriFieldType.esriFieldTypeGeometry:
                         *      //pDataRow[0] = "Geometry";
                         *      //pDataRow[1] = QueryShapeType(pField.GeometryDef.GeometryType);;
                         *      break;
                         *  default:
                         *      pDataRow = pTable.Rows.Add();
                         *      pDataRow[0] = pField.Name;
                         *      pDataRow[1] = pRow.get_Value(i).ToString();
                         *      break;
                         * }
                         * * */

                        //////////////////////////////////////////////////
                        string sValue   = pRow.get_Value(i).ToString();
                        string strFName = pField.AliasName.ToUpper();
                        string strUName = strFName.ToUpper();
                        if (strUName == "SHAPE" || strUName == "LENGTH" || strUName == "OBJECTID" || strUName == "ID" || strUName == "FNODE_" || strUName == "TNODE_" || strUName == "LPOLY_" || strUName == "RPOLY_" || strUName == "SDXL_" || strUName == "SDXL_ID" || strUName == "OBJECTID_1" || strUName == "FID")
                        {
                            continue;
                        }
                        else if (strUName == "SHAPE.LEN" || strUName == "SHAPE_LENG")
                        {
                            strFName = "几何长度";
                        }
                        else if (strUName == "SHAPE_AREA" || strUName == "SHAPE.AREA")
                        {
                            strFName = "多边形面积";
                        }
                        else if (strUName == "HEIGHT")
                        {
                            strFName = "高程";
                        }
                        else if (strUName == "NAME")
                        {
                            strFName = "名称";
                        }
                        else if (strUName == "TYPE")
                        {
                            strFName = "类型";
                        }
                        else if (strUName == "SUBTYPE")
                        {
                            strFName = "子类型";
                        }

                        if (strUName == "LENGTH" || strUName == "SHAPE.LEN")
                        {
                            IUnitConverter myUnit = new UnitConverterClass();
                            sValue = Math.Round(myUnit.ConvertUnits((double)pRow.get_Value(i), esriUnits.esriMeters, esriUnits.esriKilometers), 2).ToString();
                            sValue = sValue.ToString() + "千米";
                        }
                        if (strUName == "SHAPE_AREA" || strUName == "SHAPE.AREA")
                        {
                            IGeometry pGeo = pRow.ShapeCopy;
                            pGeo.Project(axMapControl1.Map.SpatialReference);
                            IPolygon pPolygon = (IPolygon)pGeo;
                            IArea    pArea    = (IArea)pPolygon;
                            double   strValue = pArea.Area * 0.000001;
                            //// double strValue = Math.Abs((double)pFeature.get_Value(j)) * 10585;
                            strValue = Math.Round(strValue, 2);
                            sValue   = strValue.ToString() + "平方千米";
                        }
                        esriFieldType tFieldTypy = pField.Type;
                        if (tFieldTypy == esriFieldType.esriFieldTypeGeometry)
                        {
                            sValue = pField.GeometryDef.GeometryType.ToString();
                            sValue = sValue.Substring(12, sValue.Length - 12);
                        }

                        pDataRow    = pTable.Rows.Add();
                        pDataRow[0] = strFName;
                        pDataRow[1] = sValue;

                        //////////////////////////////////////////////////
                    }
                }
                else if (pIdentiyLayer is ITinLayer)
                {
                    ITinLayer   pTinLayer   = (ITinLayer)pIdentiyLayer;
                    ITinSurface pTinSurface = (ITinSurface)pTinLayer.Dataset;
                    if (pTinSurface == null)
                    {
                        return;
                    }
                    ITinSurfaceElement pTinSurfaceElement = pTinSurface.GetSurfaceElement(pPoint);

                    if (pTinSurfaceElement == null)
                    {
                        return;
                    }
                    IFields pFields  = pTinLayer.Dataset.Fields;
                    DataRow pDataRow = null;

                    pDataRow    = pTable.Rows.Add();
                    pDataRow[0] = "高度";
                    pDataRow[1] = pTinSurfaceElement.Elevation.ToString();

                    pDataRow    = pTable.Rows.Add();
                    pDataRow[0] = "坡度";
                    pDataRow[1] = pTinSurfaceElement.SlopeDegrees.ToString();

                    pDataRow    = pTable.Rows.Add();
                    pDataRow[0] = "方向";
                    pDataRow[1] = pTinSurfaceElement.AspectDegrees.ToString();
                }

                if (pIdentiyLayer is IRasterLayer)
                {
                    MessageBox.Show("aa");
                }
                //ShowIndetify(pTable);
                //m_pMainform.ShowIndetify(pTable);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }
        }
Ejemplo n.º 4
0
        //!在这儿进行修改,将对高程埋深数据存储在不同位置进行统一处理
        private void method_2()
        {
            IMap         map         = m_context.FocusMap;
            IEnumFeature enumFeature = (IEnumFeature)map.FeatureSelection;
            IFeature     feature     = enumFeature.Next();
            bool         isMUsing    = false;
            int          qdgcIndex   = -1;
            int          qdmsIndex   = -1;
            int          zdgcIndex   = -1;
            int          zdmsIndex   = -1;

            if (feature == null)
            {
                return;
            }
            if (feature.FeatureType != esriFeatureType.esriFTSimpleEdge)
            {
                return;
            }

            this.arrayList_1.Clear();
            this.arrayList_2.Clear();
            int num = 0;

            while (feature != null)
            {
                IPolyline egLine    = feature.Shape as IPolyline;
                IPoint    newCenter = new PointClass();
                egLine.QueryPoint(esriSegmentExtension.esriNoExtension, 0.01, true, newCenter);
                IEdgeFeature  pEgFeature    = feature as IEdgeFeature;
                IFeatureClass pClass        = feature.Class as IFeatureClass;
                INetworkClass pNetworkClass = pClass as INetworkClass;
                INetElements  network       = pNetworkClass.GeometricNetwork.Network as INetElements;
                IEnumFeature  enumFeatures  = pNetworkClass.GeometricNetwork.SearchForNetworkFeature(newCenter,
                                                                                                     esriFeatureType.esriFTSimpleEdge);

                ISimpleEdgeFeature simpleEdgeFeature = enumFeatures.Next() as ISimpleEdgeFeature;

                IFeature realFeature = null;

                int userClassID, userID, userSubID;

                network.QueryIDs(simpleEdgeFeature.EID, esriElementType.esriETEdge, out userClassID, out userID,
                                 out userSubID);
                if (pClass.FeatureClassID == userClassID)
                {
                    realFeature = pClass.GetFeature(userID);
                }
                else
                {
                    IEnumDataset dses = pNetworkClass.FeatureDataset.Subsets;
                    dses.Reset();
                    IDataset ds = dses.Next();
                    while (ds != null)
                    {
                        if (ds is IFeatureClass)
                        {
                            IFeatureClass pClass2 = ds as IFeatureClass;
                            if (pClass2.FeatureClassID == userClassID)
                            {
                                realFeature = pClass2.GetFeature(userID);
                                break;
                            }
                        }
                    }
                }

                IMAware mAware = realFeature.Shape as IMAware;
                isMUsing = mAware.MAware;
                IFeatureLayer   pLayer     = MapHelper.GetLayerByFeature(map as IBasicMap, realFeature);
                IBasicLayerInfo lineConfig =
                    PipeConfig.GetBasicLayerInfo(realFeature.Class.AliasName) as IBasicLayerInfo;


                if (!isMUsing)
                {
                    qdgcIndex =
                        realFeature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.QDGC));
                    qdmsIndex =
                        realFeature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.QDMS));
                    zdgcIndex =
                        realFeature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.ZDGC));
                    zdmsIndex =
                        realFeature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.ZDMS));
                }
                PipeLine         pipeLine        = new PipeLine();
                IPolyline        polyline        = (IPolyline)feature.Shape;
                IPointCollection pointCollection = (IPointCollection)polyline;
                int pointCount = pointCollection.PointCount;
                pipeLine.Clear();
                if (isMUsing)
                {
                    for (int i = 0; i < pointCount; i++)
                    {
                        IPoint point = new ESRI.ArcGIS.Geometry.Point();
                        if (((SortInfo)this.arrayList_0[num]).bRightDirection)
                        {
                            point = pointCollection.get_Point(i);
                        }
                        else
                        {
                            point = pointCollection.get_Point(pointCount - i - 1);
                        }

                        if (double.IsNaN(point.M))
                        {
                            pipeLine.PushBack(point.X, point.Y, point.Z, point.Z + 1.0);
                        }
                        else
                        {
                            pipeLine.PushBack(point.X, point.Y, point.Z - point.M, point.Z);
                        }
                    }
                }
                else
                {
                    double height = 0;
                    double qdgc   = GetDoubleValue(realFeature, qdgcIndex, out height);
                    double zdgc   = GetDoubleValue(realFeature, zdgcIndex, out height);
                    double qdms   = GetDoubleValue(realFeature, qdmsIndex, out height);
                    double zdms   = GetDoubleValue(realFeature, zdmsIndex, out height);
                    if (qdms == 0)
                    {
                        qdms = 1;
                    }
                    if (zdms == 0)
                    {
                        zdms = 1;
                    }
                    IPoint startPoint = pointCollection.Point[0];
                    IPoint endPoint   = pointCollection.Point[pointCollection.PointCount - 1];
                    pipeLine.PushBack(startPoint.X, startPoint.Y, qdgc - qdms, qdgc);
                    pipeLine.PushBack(endPoint.X, endPoint.Y, zdgc - zdms, zdgc);
                }
                //string text = "管线性质";
                string text = lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.GDXZ) == ""
                    ? "管线性质"
                    : lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.GDXZ);

                int    num2  = realFeature.Fields.FindField(text);
                string text2 = "";
                if (num2 != -1)
                {
                    object obj = realFeature.get_Value(num2);
                    if (obj == null || Convert.IsDBNull(obj))
                    {
                        text2 = "";
                    }
                    else
                    {
                        text2 = obj.ToString();
                    }
                }
                pipeLine.ID          = Convert.ToInt32(realFeature.get_Value(0).ToString());
                pipeLine.DatasetName = text2;
                int num3 = realFeature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.GXCZ));
                pipeLine.Material = num3 == -1 ? "" : realFeature.get_Value(num3).ToString();

                //管径
                num3 = realFeature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.GJ));
                string text3 = num3 == -1 ? "" : realFeature.get_Value(num3).ToString();

                //断面尺寸
                num3 = feature.Fields.FindField(lineConfig.GetFieldName(PipeConfigWordHelper.LineWords.DMCC));
                string text4 = num3 == -1 ? "" : realFeature.get_Value(num3).ToString();

                Color featureColor = CommonUtils.GetFeatureColor(map, realFeature.Class.AliasName, realFeature);
                pipeLine.Red   = (int)featureColor.R;
                pipeLine.Green = (int)featureColor.G;
                pipeLine.Blue  = (int)featureColor.B;
                if (text3 != "")
                {
                    pipeLine.PipeWidthHeight = text3;
                }
                if (text4 != "")
                {
                    pipeLine.PipeWidthHeight = text4;
                }
                if (pipeLine.PipeWidthHeight == null)
                {
                    pipeLine.PipeWidthHeight = "";
                }
                this.arrayList_1.Add(pipeLine);
                IFeature feature2 = (IFeature)((IEdgeFeature)realFeature).FromJunctionFeature;
                IFeature feature3 = (IFeature)((IEdgeFeature)realFeature).ToJunctionFeature;
                IFeature feature4;
                if (num == 0)
                {
                    PipePoint pipePoint = new PipePoint();
                    if (((SortInfo)this.arrayList_0[num]).bRightDirection)
                    {
                        feature4 = feature2;
                    }
                    else
                    {
                        feature4 = feature3;
                    }
                    pipePoint.nID             = Convert.ToInt32(feature4.get_Value(0));
                    pipePoint.nAtPipeSegID    = pipeLine.ID;
                    pipePoint.bstrDatasetName = text2;

                    IBasicLayerInfo pointConfig =
                        PipeConfig.GetBasicLayerInfo(feature4.Class.AliasName) as IBasicLayerInfo;
                    num3 = feature4.Fields.FindField(pointConfig.GetFieldName(PipeConfigWordHelper.PointWords.FSW));
                    if (num3 == -1)
                    {
                        pipePoint.bstrPointKind = "";
                    }
                    else
                    {
                        pipePoint.bstrPointKind = feature4.get_Value(num3).ToString();
                    }
                    Color featureColor2 = CommonUtils.GetFeatureColor(map, feature4.Class.AliasName, feature4);
                    pipePoint.Red   = (int)featureColor2.R;
                    pipePoint.Green = (int)featureColor2.G;
                    pipePoint.Blue  = (int)featureColor2.B;
                    this.arrayList_2.Add(pipePoint);
                }
                PipePoint pipePoint2 = new PipePoint();
                if (((SortInfo)this.arrayList_0[num]).bRightDirection)
                {
                    feature4 = feature3;
                }
                else
                {
                    feature4 = feature2;
                }
                pipePoint2.nID             = Convert.ToInt32(feature4.get_Value(0));
                pipePoint2.nAtPipeSegID    = pipeLine.ID;
                pipePoint2.bstrDatasetName = text2;
                IBasicLayerInfo pointConfig3 =
                    PipeConfig.GetBasicLayerInfo(feature4.Class.AliasName) as IBasicLayerInfo;
                num3 = feature4.Fields.FindField(pointConfig3.GetFieldName(PipeConfigWordHelper.PointWords.FSW));
                if (num3 == -1)
                {
                    pipePoint2.bstrPointKind = "";
                }
                else
                {
                    pipePoint2.bstrPointKind = feature4.get_Value(num3).ToString();
                }
                Color featureColor3 = CommonUtils.GetFeatureColor(map, feature4.Class.AliasName, feature4);
                pipePoint2.Red   = (int)featureColor3.R;
                pipePoint2.Green = (int)featureColor3.G;
                pipePoint2.Blue  = (int)featureColor3.B;
                this.arrayList_2.Add(pipePoint2);
                feature = enumFeature.Next();
                num++;
            }
            this.method_3(this.arrayList_2, this.arrayList_1);
            this.method_4(this.arrayList_3, this.arrayList_1);
            this.method_5(this.arrayList_4, this.arrayList_2);
            this.method_6();
            this.method_7(this.arrayList_3);
        }
Ejemplo n.º 5
0
        private void ZoekPuntOpSpoorhartlijn(IPoint Point, IList<IPolyline> PolylinesLRS, double km_begin, double km_eind, out IPoint outPoint, out bool outPointGevonden, out double outPointDistance)
        {
            try
            {
                distanceAlongCurve = 0;
                bRightSide = false;

                if (PolylinesLRS.Count == 0)
                {
                    outPoint = null;
                    outPointGevonden = false;
                    outPointDistance = double.PositiveInfinity;
                }
                else // er zijn features gevonden binnen de zoekafstand
                {
                    outPoint = null;
                    outPointGevonden = false;
                    outPointDistance = double.PositiveInfinity;

                    // Zoek het punt dat binnen de kilometertolerantie valt
                    double km_begin_mshape_tolerantie = km_begin - (this.mshape_tolerantie / 1000);
                    double km_eind_mshape_tolerantie = km_eind + (this.mshape_tolerantie / 1000);
                    foreach (IPolyline Polyline in PolylinesLRS)
                    {

                        ICurve curveLRS = Polyline as ICurve;
                        outPoint = new ESRI.ArcGIS.Geometry.Point();
                        curveLRS.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, Point as IPoint, false, outPoint, distanceAlongCurve, ref outPointDistance, bRightSide);
                        if (outPoint.M >= km_begin_mshape_tolerantie && outPoint.M < km_eind_mshape_tolerantie)
                        {
                            // punt gevonden, verlaat de loop.
                            outPointGevonden = true;
                            break;
                        }

                    }
                }

            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Er is een onverwachte fout opgetreden; raadpleeg de logfile: " + ex.Message + ": " + ex.StackTrace, "Foutmelding");
                logger.LogException(LogLevel.Trace, "FOUT", ex);
                throw;
            }
        }
Ejemplo n.º 6
0
        private void nw_query(IMapControlEvents2_OnMouseDownEvent e)
        {
            //axMapControl1
            ILayer layer = m_datasource.GetAdministrativeMap().get_Layer(m_query_area_detail);
            ILayer layer_shiyi =null;// = axMapControl1.Map.get_Layer (m_selectedLayer);
            ILayer layer_cishi = null;//= axMapControl1.Map.get_Layer(m_selectedLayer);
            getLayer(m_query_area_detail, ref layer_shiyi, ref layer_cishi);
            //resolveNameRate(layer.Name);
            //resolveNameRange(layer.Name);

            //layer_name[1];
            //
            axMapControl1.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerCrosshair;

            ESRI.ArcGIS.Geometry.IGeometry geometry = null;
            ESRI.ArcGIS.Geometry.Point pt = new ESRI.ArcGIS.Geometry.Point();
            pt.X = e.mapX;
            pt.Y = e.mapY;
            geometry = pt as ESRI.ArcGIS.Geometry.IGeometry;
               // geometry = axMapControl1.TrackRectangle();

            ISpatialFilter pSpatialFilter = new SpatialFilterClass();
            IQueryFilter pQueryFilter = pSpatialFilter as ISpatialFilter;
            //设置过滤器的Geometry
            pSpatialFilter.Geometry = geometry;
            //设置空间关系类型
            pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;//esriSpatialRelContains;

            //获取FeatureCursor游标
            IFeatureLayer featureLayer = layer as IFeatureLayer;
            //获取featureLayer的featureClass
            IFeatureClass featureClass = featureLayer.FeatureClass;
            IFeatureCursor pFeatureCursor = featureClass.Search(pQueryFilter, true);
            //遍历FeatureCursor
            IFeature pFeature = pFeatureCursor.NextFeature();

            //获取FeatureCursor游标
            IFeatureLayer featureLayer1 = layer_shiyi as IFeatureLayer;
            //获取featureLayer的featureClass
            IFeatureClass featureClass1 = featureLayer1.FeatureClass;
            IFeatureCursor pFeatureCursor1 = featureClass1.Search(pQueryFilter, true);
            //遍历FeatureCursor
            IFeature pFeature1 = pFeatureCursor1.NextFeature();

            //获取FeatureCursor游标
            IFeatureLayer featureLayer2 = layer_cishi as IFeatureLayer;
            //获取featureLayer的featureClass
            IFeatureClass featureClass2 = featureLayer2.FeatureClass;
            IFeatureCursor pFeatureCursor2 = featureClass2.Search(pQueryFilter, true);
            //遍历FeatureCursor
            IFeature pFeature2 = pFeatureCursor2.NextFeature();

            //QueryForm qf =new QueryForm(m_bin_path);
            m_qf.m_mapControl = axMapControl1;
            m_qf.m_featureLayer = featureLayer;
            m_qf.m_query_name = m_range_en;
            m_qf.m_mucao = m_mucao;
            m_qf.QueryForm_SetText( m_mucao);
            //qf.m_layername = "当前图层:" + layer.Name;

            System.Windows.Forms.ListView listView_data = m_qf.nw_getListView();
            listView_data.Items.Clear();
            m_qf.m_range = m_range;

            listView_data.Columns.Clear();
            listView_data.Columns.Add(m_range + "名", 120, HorizontalAlignment.Left);//省名,,
            listView_data.Columns.Add("适宜面积比", 120, HorizontalAlignment.Left);
            listView_data.Columns.Add("适宜面积", 120, HorizontalAlignment.Left);
            listView_data.Columns.Add("次适宜面积比", 120, HorizontalAlignment.Left);
            listView_data.Columns.Add("次适宜面积", 120, HorizontalAlignment.Left);

            string area1 = "area" + m_rate_en;
            string rate1 = "rate" + m_rate_en;
            string area2 = "area" + m_rate_en;
            string rate2 = "rate" + m_rate_en;
            if(pFeature1 != null)
            {
                for (int i = 0; i < pFeature1.Fields.FieldCount;++i )
                {
                    if (pFeature1.Fields.Field[i].Name.IndexOf("area_") > -1)
                    {
                        area1 = pFeature1.Fields.Field[i].Name;
                    }
                    else if(pFeature1.Fields.Field[i].Name.IndexOf("rate_")>-1)
                    {
                        rate1 =  pFeature1.Fields.Field[i].Name;
                    }

                }
            }
            if (pFeature2 != null)
            {
                for (int i = 0; i < pFeature2.Fields.FieldCount; ++i)
                {
                    if (pFeature2.Fields.Field[i].Name.IndexOf("area_") > -1)
                    {
                        area2 = pFeature2.Fields.Field[i].Name;
                    }
                    else if (pFeature2.Fields.Field[i].Name.IndexOf("rate_") > -1)
                    {
                        rate2 = pFeature2.Fields.Field[i].Name;
                    }

                }
            }
            System.Collections.Generic.List<IFeature> pList = new System.Collections.Generic.List<IFeature>();

            while(pFeature != null)
            {

                // ESRI.ArcGIS.Geodatabase.IField filed = pFeature.Fields.FindField("rate_shiyi");
                //ESRI.ArcGIS.Geodatabase.IRowBuffer buff = (IRowBuffer)pFeature;
                //string str = buff.Value[pFeature.Fields.FindField("NAME")].ToString();
                //ESRI.ArcGIS.Geodatabase.IRow row = pFeature.Table.GetRow(pFeature.OID);
                //string str = row.Value[].ToString();
                //double a = System.Convert.ToDouble(row.get_Value(pFeature.Fields.FindField(nw_getQueryFiledName())));
                //pList.Add()
                //pList.Add(pFeature.);

                ListViewItem lvi = new ListViewItem();
               // ESRI.ArcGIS.Geodatabase.IRowBuffer buff = (IRowBuffer)pFeature;
               m_nactcn= lvi.Text = pFeature.Value[pFeature.Fields.FindField(m_range_en)].ToString();
                if (pFeature1!= null)
                {
                    lvi.SubItems.Add(pFeature1.Value[pFeature1.Fields.FindField(rate1)].ToString());//rate_shiyi
                    lvi.SubItems.Add(System.Convert.ToDecimal(pFeature1.Value[pFeature1.Fields.FindField(area1)]).ToString("N"));//
                }

                if (pFeature2 != null)
                {
                    lvi.SubItems.Add(pFeature2.Value[pFeature2.Fields.FindField(rate2)].ToString());//rate_shiyi
                    lvi.SubItems.Add(System.Convert.ToDecimal(pFeature2.Value[pFeature2.Fields.FindField(area2)]).ToString("N"));//
                }
                bool isNotAllNull = false;
                for (int i=1;i<lvi.SubItems.Count;++i)
                {
                    if(lvi.SubItems[i].Text.Trim() != "")
                    {
                        //MessageBox.Show(lvi.SubItems[i].Text.Trim());
                        isNotAllNull = true;
                        break;
                    }
                }

                if(isNotAllNull)
                    listView_data.Items.Add(lvi);

               pFeature = pFeatureCursor.NextFeature();
                if(pFeature1 != null)
                pFeature1 = pFeatureCursor1.NextFeature();
                if (pFeature2 != null)
                pFeature2 = pFeatureCursor2.NextFeature();

            }
            if (listView_data.Items.Count == 0)
            {
                MessageBox.Show("暂无数据!");
                return;
            }
            axMapControl1.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerDefault;
            m_qf.Show();
            highLight(featureLayer);
               /*  if (pFeature != null)
            {
                axMapControl1.Map.SelectFeature(axMapControl1.get_Layer(0), pFeature);
                axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
            }
            axMapControl1.Map.SelectByShape(geometry, null, false);
             axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null);*/
        }
Ejemplo n.º 7
0
        private bool zoomToQuery(string query, int count, Double zoom)
        {
            List<datacontract.locationResult> loc =  adresLocation.getAdresLocation(query, count);

            if (loc.Count > 0)
            {
                IPoint leftXY = new ESRI.ArcGIS.Geometry.Point()
                {
                    X = loc[0].BoundingBox.LowerLeft.Lon_WGS84,
                    Y = loc[0].BoundingBox.LowerLeft.Lat_WGS84,
                    SpatialReference = wgs
                };
                IPoint toleftXY = geopuntHelper.Transform(leftXY as IGeometry, map.SpatialReference) as IPoint;
                IPoint rightXY = new ESRI.ArcGIS.Geometry.Point()
                {
                    X = loc[0].BoundingBox.UpperRight.Lon_WGS84,
                    Y = loc[0].BoundingBox.UpperRight.Lat_WGS84,
                    SpatialReference = wgs
                };
                IPoint torightXY = geopuntHelper.Transform(rightXY as IGeometry, map.SpatialReference) as IPoint;
                IEnvelope bbox = geopuntHelper.makeExtend(toleftXY.X, toleftXY.Y, torightXY.X, torightXY.Y,
                                                                                map.SpatialReference);

                IPoint XY = new ESRI.ArcGIS.Geometry.Point()
                {
                    X = loc[0].Location.Lon_WGS84,
                    Y = loc[0].Location.Lat_WGS84,
                    SpatialReference = wgs
                };
                IPoint toXY = geopuntHelper.Transform(XY as IGeometry, map.SpatialReference) as IPoint;

                //create a graphic
                IRgbColor rgb = new RgbColorClass() { Red = 255, Blue = 255, Green = 0 };
                if (graphic != null)
                {
                    IGraphicsContainer grpCont = (IGraphicsContainer)map;
                    grpCont.DeleteElement(graphic);
                    graphic = null;
                }
                graphic = geopuntHelper.AddGraphicToMap(map, toXY, rgb,
                                new RgbColorClass() { Red = 0, Blue = 0, Green = 0 }, 8, true);

                infoLabel.Text = geopuntHelper.adresTypeStringTranslate( loc[0].LocationType );

                map.MapScale = 1000;
                view.Extent = bbox;
                geopuntHelper.ZoomByRatioAndRecenter(view, 1, toXY.X, toXY.Y);

                view.Refresh();
                return true;
            }
            else return false;
        }
Ejemplo n.º 8
0
        //以AxMapC1Extent生成一个mapElement在Ax2显示
        private void drawAxMapC1Extent()
        {
            // 得到新范围
            this.Refresh();
            IEnvelope pEnv = (IEnvelope)pAxMapCtrl.Extent;

            axMapControl1.Map.SpatialReference = pAxMapCtrl.SpatialReference;            //20110802 xisheng 给小地图空间参考赋成大地图空间参考
            IGraphicsContainer pGra = axMapControl1.Map as IGraphicsContainer;

            IActiveView pAv = pGra as IActiveView;

            // 在绘制前,清除 axMapControl 中的任何图形元素

            pGra.DeleteAllElements();

            IRectangleElement pRectangleEle = new RectangleElementClass();

            IElement pEle = pRectangleEle as IElement;

            pEle.Geometry = pEnv;

            //获取比例尺来判断十字丝是否出现 20110801 xisheng start changed
            string strscale = pAxMapCtrl.Map.MapScale.ToString();

            if (strscale.Contains("."))            //判断是否包含点20110802
            {
                strscale = strscale.Substring(0, strscale.LastIndexOf("."));
            }//end
            p1.Visible = p2.Visible = p3.Visible = p4.Visible = false;
            if (Convert.ToInt32(strscale) < 5000)//比例尺大于50万
            //中心点 xisheng 20110731 十字丝
            {
                ESRI.ArcGIS.Geometry.Point p = new ESRI.ArcGIS.Geometry.Point();
                p.X = (pEnv.XMax + pEnv.XMin) / 2;
                p.Y = (pEnv.YMax + pEnv.YMin) / 2;
                int x = Convert.ToInt32(p.X);
                int y = Convert.ToInt32(p.Y);
                axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.FromMapPoint(p, out x, out y); //将地理坐标转为屏幕坐标

                p1.Location = new System.Drawing.Point(x - 11, y - 1);
                p2.Location = new System.Drawing.Point(x - 1, y - 11);
                p3.Location = new System.Drawing.Point(x + 1, y - 1);
                p4.Location = new System.Drawing.Point(x - 1, y + 1);
                p1.Visible  = p2.Visible = p3.Visible = p4.Visible = true;
            }
            //20110801 xisheng end
            // 设置鹰眼图中的红线框

            IRgbColor pColor = new RgbColorClass();

            pColor.Red = 255;

            pColor.Green = 0;

            pColor.Blue = 0;

            pColor.Transparency = 255;

            // 产生一个线符号对象

            ILineSymbol pOutline = new SimpleLineSymbolClass();

            pOutline.Width = 2;

            pOutline.Color = pColor;

            // 设置颜色属性

            pColor = new RgbColorClass();

            pColor.Red = 255;

            pColor.Green = 0;

            pColor.Blue = 0;

            pColor.Transparency = 0;

            // 设置填充符号的属性

            IFillSymbol pFillSymbol = new SimpleFillSymbolClass();

            pFillSymbol.Color = pColor;

            pFillSymbol.Outline = pOutline;

            IFillShapeElement pFillShapeEle = pEle as IFillShapeElement;

            pFillShapeEle.Symbol = pFillSymbol;

            pGra.AddElement((IElement)pFillShapeEle, 0);

            // 刷新

            pAv.Refresh();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// </summary>
        /// <param name="pt">定位点</param>
        public void Create(IActiveView pAV, IPoint pt)
        {
            int count = this.m_symbolLists.Count / this.m_colum;

            if ((double)count * this.m_colspace < (double)this.m_symbolLists.Count)
            {
                count++;
            }
            int           num               = 0;
            double        num1              = 0;
            double        height            = 0;
            IGroupElement groupElementClass = new GroupElement() as IGroupElement;

            pt.X = pt.X + 0.1;
            pt.Y = pt.Y + 0.1;
            if (this.m_Title.Length > 0)
            {
                IElement  element       = this.CreateTitleElement(pt);
                IEnvelope envelopeClass = new Envelope() as IEnvelope;
                element.QueryBounds(pAV.ScreenDisplay, envelopeClass);
                height = envelopeClass.Height;
                groupElementClass.AddElement(element);
            }
            double    x          = pt.X;
            double    y          = pt.Y - height;
            IPoint    pointClass = new ESRI.ArcGIS.Geometry.Point();
            IEnvelope envelope   = new Envelope() as IEnvelope;

            for (int i = 0; i < this.m_symbolLists.Count; i++)
            {
                ISymbol item = this.m_symbolLists[i];
                pointClass.PutCoords(x, y);
                IElement element1 = this.CreateElement(pointClass, this.m_symbolLists[i],
                                                       this.m_backsymbolLists[i] as IFillSymbol, this.m_symbolDescriptions[i]);
                element1.QueryBounds(pAV.ScreenDisplay, envelope);
                if (!(element1 is IGroupElement))
                {
                    groupElementClass.AddElement(element1);
                }
                else
                {
                    for (int j = 0; j < (element1 as IGroupElement).ElementCount; j++)
                    {
                        groupElementClass.AddElement((element1 as IGroupElement).Element[j]);
                    }
                }
                (groupElementClass as IGroupElement2).Refresh();
                num1 = (num1 > envelope.Width ? num1 : envelope.Width);
                y    = y - this.m_itemheight - this.m_rowspace;
                num++;
                if (num == count)
                {
                    y    = pt.Y - height;
                    x    = x + (num1 + this.m_colspace);
                    num  = 0;
                    num1 = 0;
                }
            }
            IEnvelope envelopeClass1 = new Envelope() as IEnvelope;

            (groupElementClass as IElement).QueryBounds(pAV.ScreenDisplay, envelopeClass1);
            envelopeClass1.Expand(0.05, 0.05, false);
            try
            {
                if (this.m_HasBorder)
                {
                    IRgbColor rgbColorClass = new RgbColor()
                    {
                        Red   = 255,
                        Blue  = 255,
                        Green = 255
                    };
                    groupElementClass.AddElement(this.CreatePolygonElement(envelopeClass1, rgbColorClass));
                }
                (groupElementClass as IElement).QueryBounds(pAV.ScreenDisplay, envelopeClass1);
                (groupElementClass as ITransform2D).Scale(envelopeClass1.UpperLeft, 1, 1);
                (pAV as IGraphicsContainer).AddElement(groupElementClass as IElement, -1);
            }
            catch (Exception exception)
            {
            }
            pAV.PartialRefresh(esriViewDrawPhase.esriViewGraphics, groupElementClass, null);
        }
        protected override void OnMouseUp(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg)
        {
            bool abortOperation = false;
            ESRI.ArcGIS.Schematic.ISchematicOperation schematicOperation = null;

            try
            {
                if (m_dockableDigit == null)
                    return;

                if (arg != null)
                {
                    m_x = arg.X;
                    m_y = arg.Y;
                }

                if (m_dockableWindow == null)
                    return;

                if (m_dockableWindow.IsVisible() == false)
                {
                    m_dockableWindow.Show(true);
                }

                ESRI.ArcGIS.SchematicControls.ISchematicTarget target = (ESRI.ArcGIS.SchematicControls.ISchematicTarget)m_schematicExtension;

                if (target != null)
                    m_schematicLayer = target.SchematicTarget;

                if (m_schematicLayer == null)
                {
                    System.Windows.Forms.MessageBox.Show("No target Layer");
                    return;
                }

                ISchematicInMemoryDiagram inMemoryDiagram;
                ISchematicInMemoryFeatureClass schematicInMemoryFeatureClass;
                ISchematicInMemoryFeatureClassContainer schematicInMemoryFeatureClassContainer;

                //Get the point
                ESRI.ArcGIS.Geometry.Point point = new ESRI.ArcGIS.Geometry.Point();

                ESRI.ArcGIS.ArcMapUI.IMxApplication mxApp;
                ESRI.ArcGIS.Display.IAppDisplay appDisplay;
                IScreenDisplay screenDisplay;
                IDisplay display;
                IDisplayTransformation transform;
                ISpatialReference spatialReference;

                inMemoryDiagram = m_schematicLayer.SchematicInMemoryDiagram;
                schematicInMemoryFeatureClassContainer = (ISchematicInMemoryFeatureClassContainer)inMemoryDiagram;

                if (schematicInMemoryFeatureClassContainer == null)
                    return;

                mxApp = (ESRI.ArcGIS.ArcMapUI.IMxApplication)m_app;

                if (mxApp == null)
                    return;

                appDisplay = mxApp.Display;

                if (appDisplay == null)
                    return;

                screenDisplay = appDisplay.FocusScreen;
                display = screenDisplay;

                if (display == null)
                    return;

                transform = display.DisplayTransformation;

                if (transform == null)
                    return;

                spatialReference = transform.SpatialReference;

                WKSPoint mapPt = new WKSPoint();
                ESRI.ArcGIS.Display.tagPOINT devPoint;
                devPoint.x = m_x;
                devPoint.y = m_y;
                transform.TransformCoords(ref mapPt, ref devPoint, 1, 1); //'esriTransformToMap

                point.SpatialReference = spatialReference;
                point.Project(spatialReference);
                point.X = mapPt.X;
                point.Y = mapPt.Y;

                schematicInMemoryFeatureClass = schematicInMemoryFeatureClassContainer.GetSchematicInMemoryFeatureClass(m_dockableDigit.FeatureClass());

                if (schematicInMemoryFeatureClass == null)
                {
                    System.Windows.Forms.MessageBox.Show("Invalid Type.");
                    return;
                }

                if (m_dockableDigit.CreateNode())
                {
                    //TestMandatoryField
                    m_dockableDigit.btnOKPanel1.Visible = false;

                    if (m_dockableDigit.ValidateFields() == false)
                    {
                        m_dockableDigit.x(m_x);
                        m_dockableDigit.y(m_y);

                        System.Windows.Forms.MessageBox.Show(m_dockableDigit.ErrorProvider1.GetError(m_dockableDigit.btnOKPanel1) + m_messageFromOK);
                        return;
                    }

                    ESRI.ArcGIS.Geometry.IGeometry geometry;

                    ISchematicInMemoryFeature schematicInMemoryFeatureNode;

                    geometry = point;

                    schematicOperation = (ESRI.ArcGIS.Schematic.ISchematicOperation) new ESRI.ArcGIS.SchematicControls.SchematicOperation();

                    //digit operation is undo(redo)able we add it in the stack
                    IMxDocument doc  = (IMxDocument)m_app.Document;
                    ESRI.ArcGIS.SystemUI.IOperationStack operationStack; 
                    operationStack = doc.OperationStack;
                    operationStack.Do(schematicOperation);
                    schematicOperation.StartOperation("Digit", m_app, m_schematicLayer, true);

                    //do abort operation
                    abortOperation = true;

                    schematicInMemoryFeatureNode = schematicInMemoryFeatureClass.CreateSchematicInMemoryFeatureNode(geometry, "");
                    //schematicInMemoryFeatureNode.UpdateStatus = esriSchematicUpdateStatus.esriSchematicUpdateStatusNew; if we want the node deleted after update
                    schematicInMemoryFeatureNode.UpdateStatus = esriSchematicUpdateStatus.esriSchematicUpdateStatusLocked;

                    abortOperation = false;
                    schematicOperation.StopOperation();

                    ISchematicFeature schematicFeature = schematicInMemoryFeatureNode;
                    m_dockableDigit.FillValue(ref schematicFeature);

                    if (m_dockableDigit.AutoClear())
                        m_dockableDigit.SelectionChanged();
                }
                else
                {
                    m_dockableDigit.btnOKPanel2.Visible = false;

                    //Get the Tolerance of ArcMap
                    Double tolerance;
                    IMxDocument mxDocument = (ESRI.ArcGIS.ArcMapUI.IMxDocument)m_app.Document;
                    ESRI.ArcGIS.esriSystem.WKSPoint point2 = new WKSPoint();
                    ESRI.ArcGIS.Display.tagPOINT devPt;

                    tolerance = mxDocument.SearchTolerancePixels;
                    devPt.x = (int)tolerance;
                    devPt.y = (int)tolerance;

                    transform.TransformCoords(ref point2, ref devPt, 1, 2);//2 <-> esriTransformSize 4 <-> esriTransformToMap

                    tolerance = point2.X * 5;//increase the tolerance value

                    IEnumSchematicFeature schematicFeatures = m_schematicLayer.GetSchematicFeaturesAtPoint(point, tolerance, false, true);

                    ISchematicFeature schematicFeatureSelected = null;
                    double distancetmp;
                    double distance = 0;
                    schematicFeatures.Reset();

                    if (schematicFeatures.Count <= 0)
                        return;

                    //pSchematicFeatures may contain several features, we are choosing the closest node.
                    ISchematicFeature schematicFeature2 = schematicFeatures.Next();

                    double dX;
                    double dY;
                    ISchematicInMemoryFeatureNode schematicInMemoryFeatureNode =  null;
                    if (schematicFeature2 != null)
                    {
                        if (schematicFeature2.SchematicElementClass.SchematicElementType == ESRI.ArcGIS.Schematic.esriSchematicElementType.esriSchematicNodeType)
                            schematicInMemoryFeatureNode = (ISchematicInMemoryFeatureNode)schematicFeature2;
                    }
                                        
                    ISchematicInMemoryFeatureNodeGeometry schematicInMemoryFeatureNodeGeometry = (ISchematicInMemoryFeatureNodeGeometry)schematicInMemoryFeatureNode;
                    dX = schematicInMemoryFeatureNodeGeometry.Position.X;
                    dY = schematicInMemoryFeatureNodeGeometry.Position.Y;
                    schematicFeatureSelected = schematicFeature2;
                    distance = SquareDistance(dX - point.X, dY - point.Y);

                    while (schematicFeature2 != null)
                    {
                        //find the closest featureNode...
                        if (schematicInMemoryFeatureNode != null)
                        {
                            schematicInMemoryFeatureNodeGeometry = (ISchematicInMemoryFeatureNodeGeometry) schematicInMemoryFeatureNode;

                            if (schematicInMemoryFeatureNodeGeometry == null)
                                continue;

                            dX = schematicInMemoryFeatureNodeGeometry.Position.X;
                            dY = schematicInMemoryFeatureNodeGeometry.Position.Y;
                            distancetmp = SquareDistance(dX - point.X, dY - point.Y);
                            
                            if (distancetmp < distance)
                            {
                                distance = distancetmp;
                                schematicFeatureSelected = schematicFeature2;
                            }
                        }

                        schematicFeature2 = schematicFeatures.Next();
                        
                        if (schematicFeature2 != null)
                        {
                            if (schematicFeature2.SchematicElementClass.SchematicElementType == ESRI.ArcGIS.Schematic.esriSchematicElementType.esriSchematicNodeType)
                                schematicInMemoryFeatureNode = (ISchematicInMemoryFeatureNode)schematicFeature2;
                        }
                    }
                    
                    if (schematicFeatureSelected == null)
                        return;

                    if (schematicFeatureSelected.SchematicElementClass.SchematicElementType != esriSchematicElementType.esriSchematicNodeType)
                        return;

                    if (m_schematicFeature1 == null)
                    {
                        m_schematicFeature1 = schematicFeatureSelected;
                        m_dockableDigit.SchematicFeature1(m_schematicFeature1);

                        if (!m_dockableDigit.CheckValidFeature(true))
                        {
                            m_schematicFeature1 = null;
                            m_dockableDigit.SchematicFeature1(m_schematicFeature1);
                            throw new Exception("Invalid starting node for this link type");
                        }

                        //Begin Feedback 
                        m_linkFbk = new NewLineFeedback();
                        m_linkFbk.Display = screenDisplay;

                        //symbol
                        ISimpleLineSymbol sLnSym;
                        IRgbColor rGB = new RgbColor();

                        sLnSym = (ESRI.ArcGIS.Display.ISimpleLineSymbol)m_linkFbk.Symbol;

                        //Make a color
                        rGB.Red = 255;
                        rGB.Green = 0;
                        rGB.Blue = 0;

                        // Setup the symbol with color and style
                        sLnSym.Color = rGB;

                        m_linkFbk.Start(point);
                        //End Feedback

                        //To know if we are in the same diagram.
                        m_schematicLayerForLink = m_schematicLayer;
                    }
                    else
                    {
                        if (m_schematicLayerForLink != m_schematicLayer)
                        {
                            System.Windows.Forms.MessageBox.Show("wrong Target layer");
                            m_schematicLayerForLink = null;
                            EndFeedBack();
                            return;
                        }
                        m_schematicFeature2 = schematicFeatureSelected;
                        m_dockableDigit.SchematicFeature2(m_schematicFeature2);

                        //TestMandatoryField
                        if (m_dockableDigit.ValidateFields() == false)
                        {
                            m_dockableDigit.x(m_x);
                            m_dockableDigit.y(m_y);

                            System.Windows.Forms.MessageBox.Show(m_dockableDigit.ErrorProvider1.GetError(m_dockableDigit.btnOKPanel2) + m_messageFromOK);
                            return;
                        }

                        if (!m_dockableDigit.CheckValidFeature(false))
                        {
                            m_schematicFeature2 = null;
                            m_dockableDigit.SchematicFeature2(m_schematicFeature2);
                            throw new Exception("Invalid End node for this link type");
                        }

                        //CreateLink
                        ISchematicInMemoryFeature schematicInMemoryFeatureLink;

                        schematicOperation = (ESRI.ArcGIS.Schematic.ISchematicOperation) new ESRI.ArcGIS.SchematicControls.SchematicOperation();

                        //digit operation is undo(redo)able we add it in the stack
                        IMxDocument doc  = (IMxDocument)m_app.Document;
                        ESRI.ArcGIS.SystemUI.IOperationStack operationStack; 
                        operationStack = doc.OperationStack;
                        operationStack.Do(schematicOperation);
                        schematicOperation.StartOperation("Digit", m_app, m_schematicLayer, true);

                        //do abort operation
                        abortOperation = true;

                        schematicInMemoryFeatureLink = schematicInMemoryFeatureClass.CreateSchematicInMemoryFeatureLink((ESRI.ArcGIS.Schematic.ISchematicInMemoryFeatureNode)m_schematicFeature1, (ESRI.ArcGIS.Schematic.ISchematicInMemoryFeatureNode)m_schematicFeature2, "");
                        //schematicInMemoryFeatureLink.UpdateStatus = esriSchematicUpdateStatus.esriSchematicUpdateStatusNew; if we want the node deleted after update
                        schematicInMemoryFeatureLink.UpdateStatus = esriSchematicUpdateStatus.esriSchematicUpdateStatusLocked;

                        abortOperation = false;
                        schematicOperation.StopOperation();

                        ISchematicFeature schematicFeature = schematicInMemoryFeatureLink;
                        m_dockableDigit.FillValue(ref schematicFeature);

                        //End Feedback
                        EndFeedBack();

                        m_schematicLayerForLink = null;

                        if (m_dockableDigit.AutoClear())
                            m_dockableDigit.SelectionChanged();

                    }
                }

                //Refresh the view and viewer windows
                RefreshView();
            }
            catch (System.Exception e)
            {
                if (abortOperation && (schematicOperation != null))
                    schematicOperation.AbortOperation();

                EndFeedBack();
                System.Windows.Forms.MessageBox.Show(e.Message);
            }

            return;
        }
Ejemplo n.º 11
0
        /// <summary>
        ///     根据坐标绘制导线点
        /// </summary>
        /// <params name="lstWpie">导线坐标(List)</params>
        /// <params name="addOrChange"></params>
        private void DrawWirePoint(List<WirePoint> lstWpie, string addOrChange)
        {
            IPoint pt = new Point();

            //找到导线点图层
            var map = DataEditCommon.g_pMap;
            const string layerName = LayerNames.DEFALUT_WIRE_PT; //“导线点”图层
            var featureLayer = LayerHelper.GetLayerByName(map, layerName);

            if (featureLayer == null)
            {
                MessageBox.Show(@"没有找到" + layerName + @"图层,将不能绘制导线点。", @"提示", MessageBoxButtons.OK);
                return;
            }

            var drawWirePt = new DrawTunnels();
            //修改导线点操作,要先删除原有导线点要素
            if (addOrChange == "CHANGE")
            {
                foreach (var t in lstWpie)
                {
                    var wirePtInfo = t;
                    DataEditCommon.DeleteFeatureByBId(featureLayer, wirePtInfo.bid);
                }
            }

            foreach (var t in lstWpie)
            {
                pt.X = t.coordinate_x;
                pt.Y = t.coordinate_y;
                pt.Z = t.coordinate_z;
                drawWirePt.CreatePoint(featureLayer, pt, t.bid, t);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Read the GeoJason File and add new Polygongs to the vector layer
        /// the name of file should be newFile.json
        /// </summary>
        /// <param name="featureLayer"></param>
        /// <param name="featureworkspace"></param>
        public void AddPolygon(IFeatureLayer featureLayer, IFeatureWorkspace featureworkspace, string dir)
        {
            try
            {
                //Define vertices
                GeoJson geoJson = new GeoJson();
                _featureInJSON = geoJson.readGeoJsonFile(dir);
                IMap map = ArcMap.Document.FocusMap;
                AddGraphicToMap(map);
                IWorkspaceEdit editWorkspace = featureworkspace as IWorkspaceEdit;
                editWorkspace.StartEditing(true);
                editWorkspace.StartEditOperation();
                for (int j = 0; j < _featureInJSON.features.Count; j++)
                {
                    IPoint pPoint1 = new ESRI.ArcGIS.Geometry.Point();
                    IPoint pPoint2 = new ESRI.ArcGIS.Geometry.Point();
                    IPoint pPoint3 = new ESRI.ArcGIS.Geometry.Point();
                    IPoint pPoint4 = new ESRI.ArcGIS.Geometry.Point();

                    pPoint1.PutCoords(_featureInJSON.features[j].geometry.rings[0, 0, 0], _featureInJSON.features[j].geometry.rings[0, 0, 1]);
                    pPoint2.PutCoords(_featureInJSON.features[j].geometry.rings[0, 1, 0], _featureInJSON.features[j].geometry.rings[0, 1, 1]);
                    pPoint3.PutCoords(_featureInJSON.features[j].geometry.rings[0, 2, 0], _featureInJSON.features[j].geometry.rings[0, 2, 1]);
                    pPoint4.PutCoords(_featureInJSON.features[j].geometry.rings[0, 3, 0], _featureInJSON.features[j].geometry.rings[0, 3, 1]);

                    IPointCollection pPolygon = new Polygon();
                    IPointCollection pPointCollection = pPolygon as IPointCollection;
                    //Add the vertices of the polygon
                    pPointCollection.AddPoints(1, ref pPoint1);
                    pPointCollection.AddPoints(1, ref pPoint2);
                    pPointCollection.AddPoints(1, ref pPoint3);
                    pPointCollection.AddPoints(1, ref pPoint4);

                    ((IPolygon)pPolygon).Close();
                    IFeature iFeature = featureLayer.FeatureClass.CreateFeature();
                    iFeature.Shape = (IPolygon)pPolygon;
                    iFeature.Store();
                    //Feature cursor used to loop through all features in feature class, optionally a query filter can be used.

                    int num = featureLayer.FeatureClass.FindField(_featureInJSON.fieldAliases.Char_count);
                    iFeature.set_Value(num, _featureInJSON.features[j].attributes.Char_count.ToString());

                    num = featureLayer.FeatureClass.FindField(_featureInJSON.fieldAliases.Filename);
                    iFeature.set_Value(num, _featureInJSON.features[j].attributes.Filename);

                    //num = featureLayer.FeatureClass.FindField(_featureInJSON.fieldAliases.Mass_centerX);
                    iFeature.set_Value(8, _featureInJSON.features[j].attributes.Mass_centerX.ToString());

                    //num = featureLayer.FeatureClass.FindField(_featureInJSON.fieldAliases.Mass_centerY);
                    iFeature.set_Value(9, _featureInJSON.features[j].attributes.Mass_centerY.ToString());

                    //num = featureLayer.FeatureClass.FindField(_featureInJSON.fieldAliases.OBJECTID);
                    //iFeature.set_Value(num, _featureInJSON.features[j].attributes.OBJECTID.ToString());

                    //num = featureLayer.FeatureClass.FindField(_featureInJSON.fieldAliases.Orientation);
                    iFeature.set_Value(4, _featureInJSON.features[j].attributes.OBJECTID.ToString());

                    //num = featureLayer.FeatureClass.FindField(_featureInJSON.fieldAliases.Susp_char_count);
                    iFeature.set_Value(7, _featureInJSON.features[j].attributes.Susp_char_count.ToString());

                    num = featureLayer.FeatureClass.FindField(_featureInJSON.fieldAliases.Susp_text);
                    iFeature.set_Value(num, _featureInJSON.features[j].attributes.Susp_text.ToString());

                    num = featureLayer.FeatureClass.FindField(_featureInJSON.fieldAliases.Text);
                    iFeature.set_Value(num, _featureInJSON.features[j].attributes.Text);

                    iFeature.Store();
                }
                IFeatureCursor fcCursor = featureLayer.FeatureClass.Update(null, true);
                //Stop the operation and provide a name to add to the operation stack.
                editWorkspace.StartEditOperation();
                //Stop editing and save the edits.
                editWorkspace.StopEditing(true);

                map.AddLayer(featureLayer);
            }
            catch (Exception e)
            {
                Log.WriteLine("AddPolygon: " + e.Message);
            }
        }
Ejemplo n.º 13
0
        public void addPoligonGeorefrenced(IFeatureLayer featureLayer, IFeatureWorkspace featureworkspace)
        {
            try
            {
                //Define vertices

                if (_rasterInfo.rasterType != "Unknown")
                    convertPolygon();

                IMap map = ArcMap.Document.FocusMap;
                AddGraphicToMap(map);
                IWorkspaceEdit editWorkspace = featureworkspace as IWorkspaceEdit;
                editWorkspace.StartEditing(true);
                editWorkspace.StartEditOperation();
                int count = 0;
                if (_rasterInfo.rasterType != "Unknown")
                    count = lngLatSet.Length;
                else
                    count = pointSet.Length;

                for (int j = 0; j < count; j++)
                {
                    IPoint pPoint1 = new ESRI.ArcGIS.Geometry.Point();
                    IPoint pPoint2 = new ESRI.ArcGIS.Geometry.Point();
                    IPoint pPoint3 = new ESRI.ArcGIS.Geometry.Point();
                    IPoint pPoint4 = new ESRI.ArcGIS.Geometry.Point();

                    if (_rasterInfo.rasterType != "Unknown")
                    {
                        pPoint1.PutCoords(lngLatSet[j].leftTopX, lngLatSet[j].leftTopY);
                        pPoint2.PutCoords(lngLatSet[j].rightTopX, lngLatSet[j].rightTopY);
                        pPoint3.PutCoords(lngLatSet[j].rightDownX, lngLatSet[j].rightDownY);
                        pPoint4.PutCoords(lngLatSet[j].leftDownX, lngLatSet[j].leftDownY);
                    }
                    else
                    {
                        // if (pointSet[j].leftTopY < 0)
                        {
                            pPoint1.PutCoords(pointSet[j].leftTopX, pointSet[j].leftTopY);
                            pPoint2.PutCoords(pointSet[j].rightTopX, pointSet[j].rightTopY);
                            pPoint3.PutCoords(pointSet[j].rightDownX, pointSet[j].rightDownY);
                            pPoint4.PutCoords(pointSet[j].leftDownX, pointSet[j].leftDownY);
                        }
                        //else if (_rasterInfo.ratserNegative<0)
                        //{
                        //    pPoint1.PutCoords(pointSet[j].leftTopX, pointSet[j].leftTopY *-1);
                        //    pPoint2.PutCoords(pointSet[j].rightTopX, pointSet[j].rightTopY*-1);
                        //    pPoint3.PutCoords(pointSet[j].rightDownX, pointSet[j].rightDownY*-1);
                        //    pPoint4.PutCoords(pointSet[j].leftDownX, pointSet[j].leftDownY*-1);
                        //}

                    }

                    IPointCollection pPolygon = new Polygon();
                    IPointCollection pPointCollection = pPolygon as IPointCollection;
                    //Add the vertices of the polygon
                    pPointCollection.AddPoints(1, ref pPoint1);
                    pPointCollection.AddPoints(1, ref pPoint2);
                    pPointCollection.AddPoints(1, ref pPoint3);
                    pPointCollection.AddPoints(1, ref pPoint4);

                    ((IPolygon)pPolygon).Close();
                    IFeature iFeature = featureLayer.FeatureClass.CreateFeature();
                    iFeature.Shape = (IPolygon)pPolygon;
                    iFeature.Store();
                    //Feature cursor used to loop through all features in feature class, optionally a query filter can be used.
                    if (_rasterInfo.rasterType != "Unknown")
                    {
                        int num = featureLayer.FeatureClass.FindField("URI");
                        iFeature.set_Value(num, lngLatSet[j].URI.ToString());
                    }
                    iFeature.Store();
                }
                IFeatureCursor fcCursor = featureLayer.FeatureClass.Update(null, true);
                //Stop the operation and provide a name to add to the operation stack.
                editWorkspace.StartEditOperation();
                //Stop editing and save the edits.
                editWorkspace.StopEditing(true);

                map.AddLayer(featureLayer);
            }
            catch (Exception e)
            {
                Log.WriteLine("AddPolygon: " + e.Message);
            }
        }
Ejemplo n.º 14
0
        public static void Snap2Point(IPoint ipoint_0, IPoint ipoint_1, esriSimpleMarkerStyle esriSimpleMarkerStyle_0,
                                      IActiveView iactiveView_0, IEngineSnapEnvironment iengineSnapEnvironment_0)
        {
            IHitTest mPPointColn;
            double   num;
            int      num1;
            int      num2;
            bool     flag;
            double   mapUnits;
            IPoint   pointClass;

            if (!Editor.UseOldSnap)
            {
                ISnappingResult snappingResult = SketchToolAssist.m_psnaper.Snap(ipoint_0);
                if (snappingResult == null)
                {
                    if (SketchToolAssist.m_pAP == null)
                    {
                        SketchToolAssist.m_pAP = new AnchorPoint()
                        {
                            Symbol = SketchShareEx.m_pSym as ISymbol
                        };
                    }
                    SketchToolAssist.m_pAP.MoveTo(SketchShareEx.m_pAnchorPoint, iactiveView_0.ScreenDisplay);
                }
                else
                {
                    SketchShareEx.m_pAnchorPoint = snappingResult.Location;
                    if (SketchToolAssist.m_pAP != null)
                    {
                        SketchToolAssist.m_pAP.MoveTo(snappingResult.Location, iactiveView_0.ScreenDisplay);
                    }
                    else
                    {
                        SketchToolAssist.AddNewAnchorPt(snappingResult.Location, esriSimpleMarkerStyle_0, iactiveView_0);
                    }
                }
            }
            else
            {
                SketchShareEx.m_pSym.Style = esriSimpleMarkerStyle_0;
                if (iengineSnapEnvironment_0 is ISnapEnvironment)
                {
                    ISnapEnvironment iengineSnapEnvironment0 = iengineSnapEnvironment_0 as ISnapEnvironment;
                    if ((iengineSnapEnvironment0 == null || !ApplicationRef.AppContext.Config.UseSnap
                        ? true
                        : !iengineSnapEnvironment0.SnapPoint(SketchShareEx.LastPoint, ipoint_0)))
                    {
                        if (ApplicationRef.AppContext.Config.IsSnapSketch)
                        {
                            mPPointColn = SketchToolAssist.m_pPointColn as IHitTest;
                            if (mPPointColn != null)
                            {
                                num      = 0;
                                num1     = 0;
                                num2     = 0;
                                flag     = false;
                                mapUnits = CommonHelper.ConvertPixelsToMapUnits(iactiveView_0,
                                                                                iengineSnapEnvironment0.SnapTolerance);
                                if (mapUnits == 0)
                                {
                                    mapUnits = 3;
                                }
                                pointClass = new ESRI.ArcGIS.Geometry.Point();
                                if (
                                    !mPPointColn.HitTest(ipoint_0, mapUnits,
                                                         esriGeometryHitPartType.esriGeometryPartVertex, pointClass, ref num, ref num1,
                                                         ref num2, ref flag))
                                {
                                    SketchShareEx.m_bSnapSuccessful = false;
                                    if (SketchToolAssist.m_pAP != null)
                                    {
                                        SketchToolAssist.m_pAP.MoveTo(ipoint_0, iactiveView_0.ScreenDisplay);
                                    }
                                    else
                                    {
                                        SketchToolAssist.AddNewAnchorPt(ipoint_0, esriSimpleMarkerStyle_0, iactiveView_0);
                                    }
                                    return;
                                }
                                ipoint_0.PutCoords(pointClass.X, pointClass.Y);
                                SketchShareEx.m_bSnapSuccessful = true;
                                if (SketchToolAssist.m_pAP != null)
                                {
                                    SketchToolAssist.m_pAP.MoveTo(ipoint_0, iactiveView_0.ScreenDisplay);
                                    return;
                                }
                                else
                                {
                                    SketchToolAssist.AddNewAnchorPt(ipoint_0, esriSimpleMarkerStyle_0, iactiveView_0);
                                    return;
                                }
                            }
                        }
                    }
                    else
                    {
                        SketchShareEx.m_bSnapSuccessful = true;
                        if (SketchToolAssist.m_pAP != null)
                        {
                            SketchToolAssist.m_pAP.MoveTo(ipoint_0, iactiveView_0.ScreenDisplay);
                        }
                        else
                        {
                            SketchToolAssist.AddNewAnchorPt(ipoint_0, esriSimpleMarkerStyle_0, iactiveView_0);
                        }
                    }
                }
                else if ((iengineSnapEnvironment_0 == null || !ApplicationRef.AppContext.Config.UseSnap
                    ? true
                    : !iengineSnapEnvironment_0.SnapPoint(ipoint_0)))
                {
                    if (ApplicationRef.AppContext.Config.IsSnapSketch)
                    {
                        mPPointColn = SketchToolAssist.m_pPointColn as IHitTest;
                        if (mPPointColn != null)
                        {
                            num      = 0;
                            num1     = 0;
                            num2     = 0;
                            flag     = false;
                            mapUnits = iengineSnapEnvironment_0.SnapTolerance;
                            if (iengineSnapEnvironment_0.SnapToleranceUnits ==
                                esriEngineSnapToleranceUnits.esriEngineSnapTolerancePixels)
                            {
                                mapUnits = CommonHelper.ConvertPixelsToMapUnits(iactiveView_0,
                                                                                iengineSnapEnvironment_0.SnapTolerance);
                            }
                            if (mapUnits == 0)
                            {
                                mapUnits = 3;
                            }
                            pointClass = new ESRI.ArcGIS.Geometry.Point();
                            if (
                                !mPPointColn.HitTest(ipoint_0, mapUnits, esriGeometryHitPartType.esriGeometryPartVertex,
                                                     pointClass, ref num, ref num1, ref num2, ref flag))
                            {
                                SketchShareEx.m_bSnapSuccessful = false;
                                if (SketchToolAssist.m_pAP != null)
                                {
                                    SketchToolAssist.m_pAP.MoveTo(ipoint_0, iactiveView_0.ScreenDisplay);
                                }
                                else
                                {
                                    SketchToolAssist.AddNewAnchorPt(ipoint_0, esriSimpleMarkerStyle_0, iactiveView_0);
                                }
                                return;
                            }
                            ipoint_0.PutCoords(pointClass.X, pointClass.Y);
                            SketchShareEx.m_bSnapSuccessful = true;
                            if (SketchToolAssist.m_pAP != null)
                            {
                                SketchToolAssist.m_pAP.MoveTo(ipoint_0, iactiveView_0.ScreenDisplay);
                                return;
                            }
                            else
                            {
                                SketchToolAssist.AddNewAnchorPt(ipoint_0, esriSimpleMarkerStyle_0, iactiveView_0);
                                return;
                            }
                        }
                    }
                }
                else
                {
                    SketchShareEx.m_bSnapSuccessful = true;
                    if (SketchToolAssist.m_pAP != null)
                    {
                        SketchToolAssist.m_pAP.MoveTo(ipoint_0, iactiveView_0.ScreenDisplay);
                    }
                    else
                    {
                        SketchToolAssist.AddNewAnchorPt(ipoint_0, esriSimpleMarkerStyle_0, iactiveView_0);
                    }
                }
            }
        }
Ejemplo n.º 15
0
        public bool Snap(IGeometry igeometry_0, IPoint ipoint_0, double double_0)
        {
            ILine  lineClass;
            double length     = 0;
            int    num        = 0;
            int    num1       = 0;
            bool   flag       = true;
            IPoint pointClass = new ESRI.ArcGIS.Geometry.Point();
            double num2       = 1000;
            bool   flag1      = false;
            object value      = Missing.Value;
            IPoint ipoint0    = ipoint_0;
            IPoint point      = null;

            point = (!(igeometry_0 is IPoint) ? ((IPointCollection)igeometry_0).Point[0] : (IPoint)igeometry_0);
            for (int i = 0; i < this.ifeatureCache_0.Count; i++)
            {
                IHitTest shape = (IHitTest)this.ifeatureCache_0.Feature[i].Shape;
                if (shape.HitTest(ipoint0, double_0, esriGeometryHitPartType.esriGeometryPartBoundary, pointClass,
                                  ref length, ref num, ref num1, ref flag))
                {
                    IGeometryCollection geometryCollection = shape as IGeometryCollection;
                    if (geometryCollection != null)
                    {
                        ISegmentCollection geometry = geometryCollection.Geometry[num] as ISegmentCollection;
                        if (geometry != null)
                        {
                            ISegment segment = geometry.Segment[num1];
                            if (segment is ICircularArc)
                            {
                                IPoint centerPoint = ((ICircularArc)segment).CenterPoint;
                                ILine  line        = new Line();
                                line.PutCoords(point, centerPoint);
                                double length1 = line.Length;
                                IConstructCircularArc circularArcClass = new CircularArc() as IConstructCircularArc;
                                circularArcClass.ConstructCircle(point, length1, true);
                                IGeometryCollection polylineClass = new Polyline() as IGeometryCollection;
                                ISegmentCollection  pathClass     = new ESRI.ArcGIS.Geometry.Path() as ISegmentCollection;
                                pathClass.AddSegment((ISegment)circularArcClass, ref value, ref value);
                                polylineClass.AddGeometry((IGeometry)pathClass, ref value, ref value);
                                ((ITopologicalOperator)polylineClass).Simplify();
                                IGeometryCollection polylineClass1    = new Polyline() as IGeometryCollection;
                                ISegmentCollection  segmentCollection = new Path() as ISegmentCollection;
                                segmentCollection.AddSegment(segment, ref value, ref value);
                                polylineClass1.AddGeometry((IGeometry)segmentCollection, ref value, ref value);
                                ((ITopologicalOperator)polylineClass1).Simplify();
                                IGeometry geometry1 =
                                    ((ITopologicalOperator)polylineClass).Intersect((IGeometry)polylineClass1,
                                                                                    esriGeometryDimension.esriGeometry0Dimension);
                                if (geometry1 != null)
                                {
                                    if (!(geometry1 is IPointCollection))
                                    {
                                        lineClass = new Line();
                                        lineClass.PutCoords((IPoint)geometry1, ipoint0);
                                        if (num2 > length)
                                        {
                                            num2       = length;
                                            pointClass = ((IPointCollection)geometry1).Point[0];
                                            ipoint_0.PutCoords(pointClass.X, pointClass.Y);
                                            flag1 = true;
                                        }
                                    }
                                    else
                                    {
                                        lineClass = new Line();
                                        ILine lineClass1 = new Line();
                                        lineClass.PutCoords(((IPointCollection)geometry1).Point[0], ipoint0);
                                        lineClass1.PutCoords(((IPointCollection)geometry1).Point[1], ipoint0);
                                        if (lineClass.Length <= lineClass1.Length)
                                        {
                                            length     = lineClass.Length;
                                            pointClass = ((IPointCollection)geometry1).Point[0];
                                        }
                                        else
                                        {
                                            length     = lineClass1.Length;
                                            pointClass = ((IPointCollection)geometry1).Point[1];
                                        }
                                        if (num2 > length)
                                        {
                                            num2       = length;
                                            pointClass = ((IPointCollection)geometry1).Point[0];
                                            ipoint_0.PutCoords(pointClass.X, pointClass.Y);
                                            flag1 = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(flag1);
        }
Ejemplo n.º 16
0
        public void Create(IActiveView pAV, IEnvelope pEnvelop)
        {
            IPoint upperLeft = pEnvelop.UpperLeft;
            int    count     = this.m_symbolLists.Count / this.m_colum;

            if ((double)count * this.m_colspace < (double)this.m_symbolLists.Count)
            {
                count++;
            }
            int    num    = 0;
            double num1   = 0;
            double height = 0;

            upperLeft.X = upperLeft.X + 0.1;
            upperLeft.Y = upperLeft.Y + 0.1;
            IGroupElement groupElementClass = new GroupElement() as IGroupElement;

            if (this.m_Title.Length > 0)
            {
                IElement  element       = this.CreateTitleElement(upperLeft);
                IEnvelope envelopeClass = new Envelope() as IEnvelope;
                element.QueryBounds(pAV.ScreenDisplay, envelopeClass);
                height = envelopeClass.Height;
                groupElementClass.AddElement(element);
            }
            double    x          = upperLeft.X;
            double    y          = upperLeft.Y - height;
            IPoint    pointClass = new ESRI.ArcGIS.Geometry.Point();
            IEnvelope envelope   = new Envelope() as IEnvelope;

            for (int i = 0; i < this.m_symbolLists.Count; i++)
            {
                ISymbol item = this.m_symbolLists[i];
                pointClass.PutCoords(x, y);
                IElement element1 = this.CreateElement(pointClass, this.m_symbolLists[i],
                                                       this.m_backsymbolLists[i] as IFillSymbol, this.m_symbolDescriptions[i]);
                element1.QueryBounds(pAV.ScreenDisplay, envelope);
                if (!(element1 is IGroupElement))
                {
                    groupElementClass.AddElement(element1);
                }
                else
                {
                    for (int j = 0; j < (element1 as IGroupElement).ElementCount; j++)
                    {
                        groupElementClass.AddElement((element1 as IGroupElement).Element[j]);
                    }
                }
                num1 = (num1 > envelope.Width ? num1 : envelope.Width);
                y    = y - this.m_itemheight - this.m_rowspace;
                num++;
                if (num == count)
                {
                    y   = upperLeft.Y - height;
                    x   = x + (num1 + this.m_colspace);
                    num = 0;
                }
            }
            (groupElementClass as IElement).QueryBounds(pAV.ScreenDisplay, envelope);
            double width   = pEnvelop.Width / envelope.Width;
            double height1 = pEnvelop.Height / envelope.Height;

            pEnvelop.Expand(-0.05, -0.05, false);
            (groupElementClass as ITransform2D).Scale(pEnvelop.UpperLeft, width, height1);
            pEnvelop.Expand(0.05, 0.05, false);
            if (this.m_HasBorder)
            {
                groupElementClass.AddElement(this.CreatePolygonElement(pEnvelop));
            }
            (pAV as IGraphicsContainer).AddElement(groupElementClass as IElement, -1);
            pAV.PartialRefresh(esriViewDrawPhase.esriViewGraphics, groupElementClass, null);
        }
Ejemplo n.º 17
0
        private ISegment method_2(ISegment isegment_0, IPoint ipoint_0)
        {
            ISegment lineClass;
            IPoint   pointClass;
            IPoint   point;
            ISegment segment;
            IPoint   x;
            double   num;
            double   num1;
            double   x1;
            double   num2;
            IPoint   fromPoint = isegment_0.FromPoint;
            IPoint   toPoint   = isegment_0.ToPoint;

            if (isegment_0.GeometryType == esriGeometryType.esriGeometryLine)
            {
                lineClass  = new Line() as ISegment;
                pointClass = new ESRI.ArcGIS.Geometry.Point();
                pointClass.PutCoords(2 * ipoint_0.X - fromPoint.X, fromPoint.Y);
                point = new ESRI.ArcGIS.Geometry.Point();
                point.PutCoords(2 * ipoint_0.X - toPoint.X, toPoint.Y);
                lineClass.FromPoint = pointClass;
                lineClass.ToPoint   = point;
                segment             = lineClass;
            }
            else if (isegment_0.GeometryType == esriGeometryType.esriGeometryCircularArc)
            {
                lineClass  = new CircularArc() as ISegment;
                pointClass = new ESRI.ArcGIS.Geometry.Point();
                pointClass.PutCoords(2 * ipoint_0.X - fromPoint.X, fromPoint.Y);
                point = new ESRI.ArcGIS.Geometry.Point();
                point.PutCoords(2 * ipoint_0.X - toPoint.X, toPoint.Y);
                x = new ESRI.ArcGIS.Geometry.Point();
                (isegment_0 as ICircularArc).QueryCenterPoint(x);
                x.X = 2 * ipoint_0.X - x.X;
                (lineClass as IConstructCircularArc).ConstructThreePoints(pointClass, x, point, false);
                segment = lineClass;
            }
            else if (isegment_0.GeometryType == esriGeometryType.esriGeometryEllipticArc)
            {
                lineClass  = new EllipticArc() as ISegment;
                pointClass = new ESRI.ArcGIS.Geometry.Point();
                pointClass.PutCoords(2 * ipoint_0.X - fromPoint.X, fromPoint.Y);
                point = new ESRI.ArcGIS.Geometry.Point();
                point.PutCoords(2 * ipoint_0.X - toPoint.X, toPoint.Y);
                x = new ESRI.ArcGIS.Geometry.Point();
                (isegment_0 as IEllipticArc).QueryCenterPoint(x);
                x.X = 2 * ipoint_0.X - x.X;
                isegment_0.Envelope.QueryCoords(out num, out num1, out x1, out num2);
                num = 2 * ipoint_0.X - num;
                x1  = 2 * ipoint_0.X - x1;
                IEnvelope envelopeClass = new Envelope() as IEnvelope;
                envelopeClass.PutCoords(num, num1, x1, num2);
                (lineClass as IConstructEllipticArc).ConstructTwoPointsEnvelope(pointClass, point, envelopeClass,
                                                                                ((isegment_0 as IEllipticArc).IsCounterClockwise
                    ? esriArcOrientation.esriArcCounterClockwise
                    : esriArcOrientation.esriArcClockwise));
                segment = lineClass;
            }
            else if (isegment_0.GeometryType != esriGeometryType.esriGeometryBezier3Curve)
            {
                segment = null;
            }
            else
            {
                lineClass  = new Line() as ISegment;
                pointClass = new ESRI.ArcGIS.Geometry.Point();
                pointClass.PutCoords(2 * ipoint_0.X - fromPoint.X, fromPoint.Y);
                point = new ESRI.ArcGIS.Geometry.Point();
                point.PutCoords(2 * ipoint_0.X - toPoint.X, toPoint.Y);
                lineClass.FromPoint = pointClass;
                lineClass.ToPoint   = point;
                segment             = lineClass;
            }
            return(segment);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// 连接表
        /// </summary>
        public IElement CreateJionTab(IActiveView pAV, IPoint Leftdown)
        {
            IGroupElement groupElementClass = new GroupElement() as IGroupElement;

            (groupElementClass as IElementProperties).Name = "接图表";
            (groupElementClass as IElementProperties).Type = "接图表";
            ILineSymbol      lineSymbol        = null;
            double           num               = this.height / 3;
            double           num1              = this.width / 3;
            double           num2              = 0.3;
            object           missing           = System.Type.Missing;
            IElement         lineElementClass  = new LineElement();
            IElement         element           = new LineElement();
            IElement         lineElementClass1 = new LineElement();
            IElement         element1          = new LineElement();
            IElement         lineElementClass2 = new LineElement();
            IPolyline        polylineClass     = new Polyline() as IPolyline;
            IPolyline        polyline          = new Polyline() as IPolyline;
            IPolyline        polylineClass1    = new Polyline() as IPolyline;
            IPolyline        polyline1         = new Polyline() as IPolyline;
            IPolyline        polylineClass2    = new Polyline() as IPolyline;
            IPointCollection pointCollection   = polylineClass as IPointCollection;
            IPoint           pointClass        = new ESRI.ArcGIS.Geometry.Point();
            IPoint           point             = new ESRI.ArcGIS.Geometry.Point();
            IPoint           pointClass1       = new ESRI.ArcGIS.Geometry.Point();
            IPoint           point1            = new ESRI.ArcGIS.Geometry.Point();

            try
            {
                lineSymbol = this.LineSymbol;
                (lineElementClass as ILineElement).Symbol  = lineSymbol;
                (element as ILineElement).Symbol           = lineSymbol;
                (lineElementClass1 as ILineElement).Symbol = lineSymbol;
                (element1 as ILineElement).Symbol          = lineSymbol;
                (lineElementClass2 as ILineElement).Symbol = lineSymbol;
                point.PutCoords(Leftdown.X, Leftdown.Y + num2);
                pointClass.PutCoords(Leftdown.X, Leftdown.Y + num2 + this.height);
                pointClass1.PutCoords(Leftdown.X + this.width, Leftdown.Y + num2);
                point1.PutCoords(Leftdown.X + this.width, Leftdown.Y + num2 + this.height);
                pointCollection.AddPoint(pointClass, ref missing, ref missing);
                pointCollection.AddPoint(point, ref missing, ref missing);
                pointCollection.AddPoint(pointClass1, ref missing, ref missing);
                pointCollection.AddPoint(point1, ref missing, ref missing);
                pointCollection.AddPoint(pointClass, ref missing, ref missing);
                lineElementClass.Geometry = polylineClass;
                groupElementClass.AddElement(lineElementClass);
                IPoint pointClass2 = new ESRI.ArcGIS.Geometry.Point();
                IPoint point2      = new ESRI.ArcGIS.Geometry.Point();
                pointClass2.PutCoords(pointClass.X, pointClass.Y - num);
                point2.PutCoords(point1.X, point1.Y - num);
                pointCollection = polyline as IPointCollection;
                pointCollection.AddPoint(pointClass2, ref missing, ref missing);
                pointCollection.AddPoint(point2, ref missing, ref missing);
                element.Geometry = polyline;
                groupElementClass.AddElement(element);
                pointClass2.PutCoords(pointClass.X, pointClass.Y - num * 2);
                point2.PutCoords(point1.X, point1.Y - num * 2);
                pointCollection = polylineClass1 as IPointCollection;
                pointCollection.AddPoint(pointClass2, ref missing, ref missing);
                pointCollection.AddPoint(point2, ref missing, ref missing);
                lineElementClass1.Geometry = polylineClass1;
                groupElementClass.AddElement(lineElementClass1);
                pointClass2.PutCoords(pointClass.X + num1, pointClass.Y);
                point2.PutCoords(pointClass.X + num1, point.Y);
                pointCollection = polyline1 as IPointCollection;
                pointCollection.AddPoint(pointClass2, ref missing, ref missing);
                pointCollection.AddPoint(point2, ref missing, ref missing);
                element1.Geometry = polyline1;
                groupElementClass.AddElement(element1);
                pointClass2.PutCoords(pointClass.X + num1 * 2, pointClass.Y);
                point2.PutCoords(pointClass.X + num1 * 2, point.Y);
                pointCollection = polylineClass2 as IPointCollection;
                pointCollection.AddPoint(pointClass2, ref missing, ref missing);
                pointCollection.AddPoint(point2, ref missing, ref missing);
                lineElementClass2.Geometry = polylineClass2;
                groupElementClass.AddElement(lineElementClass2);
                IPolygon          polygonClass          = new Polygon() as IPolygon;
                IElement          polygonElementClass   = new PolygonElement();
                IPolygonElement   polygonElement        = polygonElementClass as IPolygonElement;
                ISimpleFillSymbol simpleFillSymbolClass = new SimpleFillSymbol();
                IFillShapeElement fillShapeElement      = polygonElement as IFillShapeElement;
                IRgbColor         rgbColorClass         = new RgbColor()
                {
                    Red   = 0,
                    Green = 0,
                    Blue  = 0
                };
                simpleFillSymbolClass.Outline = this.LineSymbol;
                simpleFillSymbolClass.Color   = rgbColorClass;
                simpleFillSymbolClass.Style   = esriSimpleFillStyle.esriSFSBackwardDiagonal;
                fillShapeElement.Symbol       = simpleFillSymbolClass;
                pointCollection = polygonClass as IPointCollection;
                pointClass2.PutCoords(pointClass.X + num1, pointClass.Y - num);
                pointCollection.AddPoint(pointClass2, ref missing, ref missing);
                pointClass2.PutCoords(pointClass.X + num1 * 2, pointClass.Y - num);
                pointCollection.AddPoint(pointClass2, ref missing, ref missing);
                pointClass2.PutCoords(pointClass.X + num1 * 2, pointClass.Y - num * 2);
                pointCollection.AddPoint(pointClass2, ref missing, ref missing);
                pointClass2.PutCoords(pointClass.X + num1, pointClass.Y - num * 2);
                pointCollection.AddPoint(pointClass2, ref missing, ref missing);
                polygonClass.Close();
                polygonElementClass.Geometry = polygonClass;
                groupElementClass.AddElement(polygonElementClass);
                IEnvelope envelope      = polygonClass.Envelope;
                IEnvelope envelopeClass = new Envelope() as IEnvelope;
                this.m_pTextElementList.Add(
                    this.CreateJionTabTextElement(pAV, this.Row1Col1Text, pointClass.X + num1 / 2, pointClass.Y - num / 2,
                                                  envelope) as ITextElement);
                this.m_pTextElementAdd.Add(true);
                groupElementClass.AddElement(this.m_pTextElementList[0] as IElement);
                this.m_pTextElementList.Add(
                    this.CreateJionTabTextElement(pAV, this.Row1Col2Text, pointClass.X + 1.5 * num1,
                                                  pointClass.Y - 0.5 * num, envelope) as ITextElement);
                this.m_pTextElementAdd.Add(true);
                groupElementClass.AddElement(this.m_pTextElementList[1] as IElement);
                this.m_pTextElementList.Add(
                    this.CreateJionTabTextElement(pAV, this.Row1Col3Text, pointClass.X + 2.5 * num1,
                                                  pointClass.Y - 0.5 * num, envelope) as ITextElement);
                this.m_pTextElementAdd.Add(true);
                groupElementClass.AddElement(this.m_pTextElementList[2] as IElement);
                this.m_pTextElementList.Add(
                    this.CreateJionTabTextElement(pAV, this.Row2Col1Text, pointClass.X + num1 / 2, pointClass.Y - 1.5 * num,
                                                  envelope) as ITextElement);
                this.m_pTextElementAdd.Add(true);
                groupElementClass.AddElement(this.m_pTextElementList[3] as IElement);
                this.m_pTextElementList.Add(null);
                this.m_pTextElementAdd.Add(false);
                this.m_pTextElementList.Add(
                    this.CreateJionTabTextElement(pAV, this.Row2Col3Text, pointClass.X + 2.5 * num1,
                                                  pointClass.Y - 1.5 * num, envelope) as ITextElement);
                this.m_pTextElementAdd.Add(true);
                groupElementClass.AddElement(this.m_pTextElementList[5] as IElement);
                this.m_pTextElementList.Add(
                    this.CreateJionTabTextElement(pAV, this.Row3Col1Text, pointClass.X + num1 / 2, pointClass.Y - 2.5 * num,
                                                  envelope) as ITextElement);
                this.m_pTextElementAdd.Add(true);
                groupElementClass.AddElement(this.m_pTextElementList[6] as IElement);
                this.m_pTextElementList.Add(
                    this.CreateJionTabTextElement(pAV, this.Row3Col2Text, pointClass.X + 1.5 * num1,
                                                  pointClass.Y - 2.5 * num, envelope) as ITextElement);
                this.m_pTextElementAdd.Add(true);
                groupElementClass.AddElement(this.m_pTextElementList[7] as IElement);
                this.m_pTextElementList.Add(
                    this.CreateJionTabTextElement(pAV, this.Row3Col3Text, pointClass.X + 2.5 * num1,
                                                  pointClass.Y - 2.5 * num, envelope) as ITextElement);
                this.m_pTextElementAdd.Add(true);
                groupElementClass.AddElement(this.m_pTextElementList[8] as IElement);
            }
            catch (Exception exception)
            {
            }
            this.m_pGroupElement = groupElementClass as IElement;
            return(this.m_pGroupElement);
        }
Ejemplo n.º 19
0
        private ISegment method_3(ISegment isegment_0, IPoint ipoint_0)
        {
            ISegment lineClass;
            IPoint   pointClass;
            IPoint   point;
            ISegment segment;
            double   num;
            double   y;
            double   num1;
            double   y1;
            IPoint   fromPoint = isegment_0.FromPoint;
            IPoint   toPoint   = isegment_0.ToPoint;

            if (isegment_0.GeometryType == esriGeometryType.esriGeometryLine)
            {
                lineClass  = new Line() as ISegment;
                pointClass = new ESRI.ArcGIS.Geometry.Point();
                pointClass.PutCoords(fromPoint.X, 2 * ipoint_0.Y - fromPoint.Y);
                point = new ESRI.ArcGIS.Geometry.Point();
                point.PutCoords(toPoint.X, 2 * ipoint_0.Y - toPoint.Y);
                lineClass.FromPoint = pointClass;
                lineClass.ToPoint   = point;
                segment             = lineClass;
            }
            else if (isegment_0.GeometryType == esriGeometryType.esriGeometryCircularArc)
            {
                lineClass  = new CircularArc() as ISegment;
                pointClass = new ESRI.ArcGIS.Geometry.Point();
                pointClass.PutCoords(fromPoint.X, 2 * ipoint_0.Y - fromPoint.Y);
                point = new ESRI.ArcGIS.Geometry.Point();
                point.PutCoords(toPoint.X, 2 * ipoint_0.Y - toPoint.Y);
                IPoint pointClass1 = new ESRI.ArcGIS.Geometry.Point();
                (isegment_0 as ICircularArc).QueryCenterPoint(pointClass1);
                pointClass1.Y = 2 * ipoint_0.Y - pointClass1.Y;
                (lineClass as IConstructCircularArc).ConstructThreePoints(pointClass, pointClass1, point, false);
                segment = lineClass;
            }
            else if (isegment_0.GeometryType == esriGeometryType.esriGeometryEllipticArc)
            {
                lineClass  = new EllipticArc() as ISegment;
                pointClass = new ESRI.ArcGIS.Geometry.Point();
                pointClass.PutCoords(fromPoint.X, 2 * ipoint_0.Y - fromPoint.Y);
                point = new ESRI.ArcGIS.Geometry.Point();
                point.PutCoords(toPoint.X, 2 * ipoint_0.Y - toPoint.Y);
                isegment_0.Envelope.QueryCoords(out num, out y, out num1, out y1);
                y  = 2 * ipoint_0.Y - y;
                y1 = 2 * ipoint_0.Y - y1;
                IEnvelope envelopeClass = new Envelope() as IEnvelope;
                envelopeClass.PutCoords(num, y, num1, y1);
                (lineClass as IConstructEllipticArc).ConstructTwoPointsEnvelope(pointClass, point, envelopeClass,
                                                                                ((isegment_0 as IEllipticArc).IsCounterClockwise
                    ? esriArcOrientation.esriArcCounterClockwise
                    : esriArcOrientation.esriArcClockwise));
                segment = lineClass;
            }
            else if (isegment_0.GeometryType != esriGeometryType.esriGeometryBezier3Curve)
            {
                segment = null;
            }
            else
            {
                lineClass  = new Line() as ISegment;
                pointClass = new ESRI.ArcGIS.Geometry.Point();
                pointClass.PutCoords(fromPoint.X, 2 * ipoint_0.Y - fromPoint.Y);
                point = new ESRI.ArcGIS.Geometry.Point();
                point.PutCoords(toPoint.X, 2 * ipoint_0.Y - toPoint.Y);
                lineClass.FromPoint = pointClass;
                lineClass.ToPoint   = point;
                segment             = lineClass;
            }
            return(segment);
        }
Ejemplo n.º 20
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (this.textBox1.Text == null)
     {
         MessageBox.Show(@"坐标值不能为空:请依次输入坐标的XY值,其间用逗号隔开");
     }
     else
     {
         string text = this.textBox1.Text;
         int    num  = text.IndexOf(",", StringComparison.Ordinal);
         if (num < 0)
         {
             MessageBox.Show(@"请输入分隔符 , !");
         }
         else
         {
             string[] array = text.Split(new char[]
             {
                 ','
             });
             if (array[0] == string.Empty)
             {
                 MessageBox.Show(@"X坐标不能为空!");
             }
             else
             {
                 string value = array[0];
                 if (array[1] == string.Empty)
                 {
                     MessageBox.Show(@"Y坐标不能为空!");
                 }
                 else
                 {
                     string value2 = array[1];
                     double num2   = 0.0;
                     double num3   = 0.0;
                     try
                     {
                         num2 = Convert.ToDouble(value);
                         num3 = Convert.ToDouble(value2);
                     }
                     catch (Exception)
                     {
                         MessageBox.Show(@"输入的坐标值有误,请检查!");
                         return;
                     }
                     IPoint point = new ESRI.ArcGIS.Geometry.Point();
                     point.X = (num2);
                     point.Y = (num3);
                     IEnvelope envelope = new Envelope() as IEnvelope;
                     decimal   value3   = this.numericUpDown1.Value / 2m;
                     double    num4     = Convert.ToDouble(value3);
                     double    num5     = m_context.ActiveView.Extent.Height / m_context.ActiveView.Extent.Width;
                     envelope.PutCoords(num2 - num4, num3 - num4 * num5, num2 + num4, num3 + num4 * num5);
                     m_context.ActiveView.Extent = (envelope);
                     m_context.ActiveView.Refresh();
                 }
             }
         }
     }
 }
Ejemplo n.º 21
0
        private void method_2(IComplexEdgeFeature icomplexEdgeFeature_0)
        {
            ILineMovePointFeedback lineMovePointFeedbackClass;
            int       oID       = (icomplexEdgeFeature_0 as IFeature).OID;
            IGeometry shapeCopy = (icomplexEdgeFeature_0 as IFeature).ShapeCopy;

            if (this.imoveGeometryFeedback_0 == null)
            {
                this.imoveGeometryFeedback_0 = new MoveGeometryFeedback()
                {
                    Display = this.iscreenDisplay_0
                };
            }
            this.imoveGeometryFeedback_0.AddGeometry(shapeCopy);
            for (int i = 0; i < icomplexEdgeFeature_0.JunctionFeatureCount; i++)
            {
                IJunctionFeature junctionFeature = icomplexEdgeFeature_0.JunctionFeature[i];
                if (junctionFeature is ISimpleJunctionFeature)
                {
                    int    eID              = (junctionFeature as ISimpleJunctionFeature).EID;
                    IPoint point            = (junctionFeature as IFeature).ShapeCopy as IPoint;
                    int    edgeFeatureCount = (junctionFeature as ISimpleJunctionFeature).EdgeFeatureCount;
                    for (int j = 0; j < edgeFeatureCount; j++)
                    {
                        IEdgeFeature edgeFeature = (junctionFeature as ISimpleJunctionFeature).EdgeFeature[j];
                        if ((edgeFeature as IFeature).OID != oID && !this.iset_0.Find(edgeFeature) &&
                            !this.iset_1.Find(edgeFeature))
                        {
                            this.iset_1.Add(edgeFeature);
                            shapeCopy = (edgeFeature as IFeature).Shape;
                            IPoint point1 = null;
                            if (!(edgeFeature is ISimpleEdgeFeature))
                            {
                                IHitTest shape      = (edgeFeature as IFeature).Shape as IHitTest;
                                IPoint   pointClass = new ESRI.ArcGIS.Geometry.Point();
                                double   num        = 0;
                                int      num1       = -1;
                                int      num2       = -1;
                                bool     flag       = false;
                                if (shape.HitTest(point, 0, esriGeometryHitPartType.esriGeometryPartVertex, pointClass,
                                                  ref num, ref num1, ref num2, ref flag))
                                {
                                    lineMovePointFeedbackClass = new LineMovePointFeedback()
                                    {
                                        Display = this.iscreenDisplay_0
                                    };
                                    int pointCount = 0;
                                    for (int k = 0; k < num1; k++)
                                    {
                                        IPath geometry = (IPath)((IGeometryCollection)shape).Geometry[k];
                                        pointCount = pointCount + (geometry as IPointCollection).PointCount;
                                    }
                                    num2 = num2 + pointCount;
                                    lineMovePointFeedbackClass.Start(shape as IPolyline, num2, point);
                                    this.ilist_0.Add(lineMovePointFeedbackClass);
                                    this.ilist_1.Add(point);
                                }
                            }
                            else
                            {
                                lineMovePointFeedbackClass = new LineMovePointFeedback()
                                {
                                    Display = this.iscreenDisplay_0
                                };
                                if (edgeFeature.FromJunctionEID != eID)
                                {
                                    point1 =
                                        (shapeCopy as IPointCollection).Point[
                                            (shapeCopy as IPointCollection).PointCount - 1];
                                    lineMovePointFeedbackClass.Start(shapeCopy as IPolyline,
                                                                     (shapeCopy as IPointCollection).PointCount - 1, point1);
                                }
                                else
                                {
                                    point1 = (shapeCopy as IPointCollection).Point[0];
                                    lineMovePointFeedbackClass.Start(shapeCopy as IPolyline, 0, point1);
                                }
                                this.ilist_0.Add(lineMovePointFeedbackClass);
                                this.ilist_1.Add(point1);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 22
0
        public bool HandleCommand(string string_0)
        {
            bool flag;

            char[]         chrArray;
            string[]       strArrays;
            double         num;
            double         num1;
            IPoint         pointClass;
            IEnvelope      envelope;
            int            selectionCount;
            double         mapUnits;
            IFeatureLayer  featureLayer;
            IFeature       hitLineFeature;
            IWorkspaceEdit workspace;
            IPolyline      polyline;

            if (!this.bool_0)
            {
                try
                {
                    if (string_0 == "ESC")
                    {
                        this._appContext.ShowCommandString("取消延长线操作", CommandTipsType.CTTActiveEnd);
                        this._appContext.ClearCurrentTool();
                        this.bool_0 = true;
                        flag        = true;
                        return(flag);
                    }
                    else if (this.int_0 == 0)
                    {
                        string_0 = string_0.Trim();
                        if (string_0.Length != 0)
                        {
                            chrArray  = new char[] { ',' };
                            strArrays = string_0.Split(chrArray);
                            if ((int)strArrays.Length < 2)
                            {
                                this._appContext.ShowCommandString("输入不正确", CommandTipsType.CTTLog);
                                this.ShowCommandLine();
                            }
                            else
                            {
                                num        = 0;
                                num1       = 0;
                                pointClass = new ESRI.ArcGIS.Geometry.Point();
                                num        = Convert.ToDouble(strArrays[0]);
                                pointClass.PutCoords(num, Convert.ToDouble(strArrays[1]));
                                if (this.idisplayFeedback_0 == null)
                                {
                                    mapUnits =
                                        CommonHelper.ConvertPixelsToMapUnits(
                                            this._appContext.MapControl.Map as IActiveView, 6);
                                    hitLineFeature = Editor.GetHitLineFeature(this._appContext.MapControl.Map,
                                                                              pointClass, mapUnits, out featureLayer);
                                    if (hitLineFeature == null)
                                    {
                                        this.idisplayFeedback_0 = new NewEnvelopeFeedback()
                                        {
                                            Display = (this._appContext.MapControl.Map as IActiveView).ScreenDisplay
                                        };
                                        (this.idisplayFeedback_0 as INewEnvelopeFeedback).Start(pointClass);
                                        this.double_0 = pointClass.X;
                                        this._appContext.ShowCommandString("指定下一个角点:", CommandTipsType.CTTCommandTip);
                                    }
                                    else
                                    {
                                        this.int_0 = 1;
                                        this._appContext.MapControl.Map.SelectFeature(featureLayer, hitLineFeature);
                                        (this._appContext.MapControl.Map as IActiveView).PartialRefresh(
                                            esriViewDrawPhase.esriViewGeoSelection, null, null);
                                        this.ShowCommandLine();
                                    }
                                }
                                else
                                {
                                    envelope = (this.idisplayFeedback_0 as INewEnvelopeFeedback).Stop();
                                    this.idisplayFeedback_0 = null;
                                    this.double_1           = pointClass.X;
                                    this.method_2(envelope);
                                    if (this.method_1())
                                    {
                                        this.int_0 = 1;
                                    }
                                    IAppContext appContext = this._appContext;
                                    selectionCount = this._appContext.MapControl.Map.SelectionCount;
                                    appContext.ShowCommandString(string.Concat("找到", selectionCount.ToString(), "个对象"),
                                                                 CommandTipsType.CTTLog);
                                    this.ShowCommandLine();
                                }
                            }
                        }
                        else
                        {
                            if (this.method_1())
                            {
                                this.int_0 = 1;
                            }
                            this.ShowCommandLine();
                        }
                    }
                    else if (this.int_0 == 1)
                    {
                        if (string_0.Length == 0)
                        {
                            this.int_0 = 2;
                            if (this.int_1 != 1)
                            {
                                this._appContext.ShowCommandString("不产生交点", CommandTipsType.CTTLog);
                            }
                            else
                            {
                                this._appContext.ShowCommandString("产生交点", CommandTipsType.CTTLog);
                            }
                        }
                        else if (string_0.ToUpper() == "Y")
                        {
                            this.int_0 = 2;
                            this.int_1 = 1;
                            this._appContext.ShowCommandString("产生交点", CommandTipsType.CTTLog);
                        }
                        else if (string_0.ToUpper() != "N")
                        {
                            this.int_0 = 2;
                            if (this.int_1 != 1)
                            {
                                this._appContext.ShowCommandString("不产生交点", CommandTipsType.CTTLog);
                            }
                            else
                            {
                                this._appContext.ShowCommandString("产生交点", CommandTipsType.CTTLog);
                            }
                            this.HandleCommand(string_0);
                            flag = true;
                            return(flag);
                        }
                        else
                        {
                            this.int_0 = 2;
                            this.int_1 = 0;
                            this._appContext.ShowCommandString("不产生交点", CommandTipsType.CTTLog);
                        }
                        this.ShowCommandLine();
                    }
                    else if (this.int_0 == 2)
                    {
                        chrArray  = new char[] { ',' };
                        strArrays = string_0.Split(chrArray);
                        if ((int)strArrays.Length >= 2)
                        {
                            num        = 0;
                            num1       = 0;
                            pointClass = new ESRI.ArcGIS.Geometry.Point();
                            num        = Convert.ToDouble(strArrays[0]);
                            pointClass.PutCoords(num, Convert.ToDouble(strArrays[1]));
                            if (this.idisplayFeedback_0 == null)
                            {
                                mapUnits =
                                    CommonHelper.ConvertPixelsToMapUnits(
                                        this._appContext.MapControl.Map as IActiveView, 6);
                                hitLineFeature = Editor.GetHitLineFeature(this._appContext.MapControl.Map, pointClass,
                                                                          mapUnits, out featureLayer);
                                if (hitLineFeature == null)
                                {
                                    this.idisplayFeedback_0 = new NewEnvelopeFeedback()
                                    {
                                        Display = (this._appContext.MapControl.Map as IActiveView).ScreenDisplay
                                    };
                                    (this.idisplayFeedback_0 as INewEnvelopeFeedback).Start(pointClass);
                                    this.double_0 = pointClass.X;
                                    this._appContext.ShowCommandString("指定下一个角点:", CommandTipsType.CTTCommandTip);
                                }
                                else
                                {
                                    polyline = null;
                                    polyline = (this.int_1 != 0
                                        ? Editor.ExtendPolyLineEx(this._appContext.MapControl.Map, hitLineFeature.Shape)
                                        : Editor.ExtendPolyLine(this._appContext.MapControl.Map, hitLineFeature.Shape));
                                    if (polyline != null && !polyline.IsEmpty &&
                                        (polyline as IPointCollection).PointCount > 1)
                                    {
                                        (polyline as ITopologicalOperator).Simplify();
                                        workspace = (hitLineFeature.Class as IDataset).Workspace as IWorkspaceEdit;
                                        workspace.StartEditOperation();
                                        hitLineFeature.Shape = polyline;
                                        hitLineFeature.Store();
                                        workspace.StopEditOperation();
                                        this._appContext.MapControl.ActiveView.Refresh();
                                    }
                                    this.ShowCommandLine();
                                }
                            }
                            else
                            {
                                envelope = (this.idisplayFeedback_0 as INewEnvelopeFeedback).Stop();
                                this.idisplayFeedback_0 = null;
                                this.double_1           = pointClass.X;
                                IAppContext application = this._appContext;
                                selectionCount = this._appContext.MapControl.Map.SelectionCount;
                                application.ShowCommandString(string.Concat("找到", selectionCount.ToString(), "个对象"),
                                                              CommandTipsType.CTTLog);
                                mapUnits =
                                    CommonHelper.ConvertPixelsToMapUnits(
                                        this._appContext.MapControl.Map as IActiveView, 6);
                                IList <IFeature> intersectsLineFeatures =
                                    Editor.GetIntersectsLineFeatures(this._appContext.MapControl.Map, envelope);
                                workspace = null;
                                for (int i = 0; i < intersectsLineFeatures.Count; i++)
                                {
                                    IWorkspaceEdit workspaceEdit =
                                        (intersectsLineFeatures[i].Class as IDataset).Workspace as IWorkspaceEdit;
                                    if (workspaceEdit.IsBeingEdited())
                                    {
                                        if (workspace == null)
                                        {
                                            workspace = workspaceEdit;
                                            workspace.StartEditOperation();
                                        }
                                        polyline = null;
                                        polyline = (this.int_1 != 0
                                            ? Editor.ExtendPolyLineEx(this._appContext.MapControl.Map,
                                                                      intersectsLineFeatures[i].Shape)
                                            : Editor.ExtendPolyLine(this._appContext.MapControl.Map,
                                                                    intersectsLineFeatures[i].Shape));
                                        if (polyline != null && !polyline.IsEmpty &&
                                            (polyline as IPointCollection).PointCount > 1)
                                        {
                                            (polyline as ITopologicalOperator).Simplify();
                                            intersectsLineFeatures[i].Shape = polyline;
                                            intersectsLineFeatures[i].Store();
                                        }
                                    }
                                }
                                if (workspace != null)
                                {
                                    workspace.StopEditOperation();
                                    this._appContext.MapControl.ActiveView.Refresh();
                                }
                                this.ShowCommandLine();
                            }
                        }
                    }
                }
                catch
                {
                    this._appContext.ShowCommandString("输入不正确", CommandTipsType.CTTLog);
                    this.ShowCommandLine();
                    flag = true;
                    return(flag);
                }
                flag = true;
            }
            else
            {
                flag = false;
            }
            return(flag);
        }
Ejemplo n.º 23
0
        private void method_1(IEdgeFeature iedgeFeature_0)
        {
            int                    edgeFeatureCount;
            int                    i;
            IEdgeFeature           edgeFeature;
            IPoint                 shape;
            ILineMovePointFeedback lineMovePointFeedbackClass;
            IHitTest               hitTest;
            IPoint                 pointClass;
            double                 num;
            int                    num1;
            int                    num2;
            bool                   flag;
            int                    pointCount;
            int                    j;
            IPath                  geometry;

            if (!(iedgeFeature_0 is IComplexEdgeFeature))
            {
                int       oID       = (iedgeFeature_0 as IFeature).OID;
                IGeometry shapeCopy = (iedgeFeature_0 as IFeature).ShapeCopy;
                if (this.imoveGeometryFeedback_0 == null)
                {
                    this.imoveGeometryFeedback_0 = new MoveGeometryFeedback()
                    {
                        Display = this.iscreenDisplay_0
                    };
                }
                this.imoveGeometryFeedback_0.AddGeometry(shapeCopy);
                int fromJunctionEID = iedgeFeature_0.FromJunctionEID;
                IJunctionFeature fromJunctionFeature = iedgeFeature_0.FromJunctionFeature;
                if (fromJunctionFeature is ISimpleJunctionFeature)
                {
                    edgeFeatureCount = (fromJunctionFeature as ISimpleJunctionFeature).EdgeFeatureCount;
                    for (i = 0; i < edgeFeatureCount; i++)
                    {
                        edgeFeature = (fromJunctionFeature as ISimpleJunctionFeature).EdgeFeature[i];
                        if ((edgeFeature as IFeature).OID != oID && !this.iset_0.Find(edgeFeature) &&
                            !this.iset_1.Find(edgeFeature))
                        {
                            this.iset_1.Add(edgeFeature);
                            shapeCopy = (edgeFeature as IFeature).Shape;
                            if (!(edgeFeature is ISimpleEdgeFeature))
                            {
                                shape      = (fromJunctionFeature as IFeature).Shape as IPoint;
                                hitTest    = shapeCopy as IHitTest;
                                pointClass = new ESRI.ArcGIS.Geometry.Point();
                                num        = 0;
                                num1       = -1;
                                num2       = -1;
                                flag       = false;
                                if (hitTest.HitTest(shape, 0, esriGeometryHitPartType.esriGeometryPartVertex, pointClass,
                                                    ref num, ref num1, ref num2, ref flag))
                                {
                                    lineMovePointFeedbackClass = new LineMovePointFeedback()
                                    {
                                        Display = this.iscreenDisplay_0
                                    };
                                    pointCount = 0;
                                    for (j = 0; j < num1; j++)
                                    {
                                        geometry   = (IPath)((IGeometryCollection)hitTest).Geometry[j];
                                        pointCount = pointCount + (geometry as IPointCollection).PointCount;
                                    }
                                    num2 = num2 + pointCount;
                                    lineMovePointFeedbackClass.Start(hitTest as IPolyline, num2, shape);
                                    this.ilist_0.Add(lineMovePointFeedbackClass);
                                    this.ilist_1.Add(shape);
                                }
                            }
                            else
                            {
                                shape = null;
                                lineMovePointFeedbackClass = new LineMovePointFeedback()
                                {
                                    Display = this.iscreenDisplay_0
                                };
                                if (edgeFeature.FromJunctionEID != fromJunctionEID)
                                {
                                    shape =
                                        (shapeCopy as IPointCollection).Point[
                                            (shapeCopy as IPointCollection).PointCount - 1];
                                    lineMovePointFeedbackClass.Start(shapeCopy as IPolyline,
                                                                     (shapeCopy as IPointCollection).PointCount - 1, shape);
                                }
                                else
                                {
                                    shape = (shapeCopy as IPointCollection).Point[0];
                                    lineMovePointFeedbackClass.Start(shapeCopy as IPolyline, 0, shape);
                                }
                                this.ilist_0.Add(lineMovePointFeedbackClass);
                                this.ilist_1.Add(shape);
                            }
                        }
                    }
                }
                fromJunctionEID = iedgeFeature_0.ToJunctionEID;
                IJunctionFeature toJunctionFeature = iedgeFeature_0.ToJunctionFeature;
                if (toJunctionFeature is ISimpleJunctionFeature)
                {
                    edgeFeatureCount = (toJunctionFeature as ISimpleJunctionFeature).EdgeFeatureCount;
                    for (i = 0; i < edgeFeatureCount; i++)
                    {
                        edgeFeature = (toJunctionFeature as ISimpleJunctionFeature).EdgeFeature[i];
                        if ((edgeFeature as IFeature).OID != oID && !this.iset_0.Find(edgeFeature) &&
                            !this.iset_1.Find(edgeFeature))
                        {
                            this.iset_1.Add(edgeFeature);
                            shape = null;
                            lineMovePointFeedbackClass = new LineMovePointFeedback()
                            {
                                Display = this.iscreenDisplay_0
                            };
                            shapeCopy = (edgeFeature as IFeature).Shape;
                            if (!(edgeFeature is ISimpleEdgeFeature))
                            {
                                IPoint point = (toJunctionFeature as IFeature).Shape as IPoint;
                                hitTest    = shapeCopy as IHitTest;
                                pointClass = new ESRI.ArcGIS.Geometry.Point();
                                num        = 0;
                                num1       = -1;
                                num2       = -1;
                                flag       = false;
                                if (hitTest.HitTest(point, 0, esriGeometryHitPartType.esriGeometryPartVertex, pointClass,
                                                    ref num, ref num1, ref num2, ref flag))
                                {
                                    lineMovePointFeedbackClass = new LineMovePointFeedback()
                                    {
                                        Display = this.iscreenDisplay_0
                                    };
                                    pointCount = 0;
                                    for (j = 0; j < num1; j++)
                                    {
                                        geometry   = (IPath)((IGeometryCollection)hitTest).Geometry[j];
                                        pointCount = pointCount + (geometry as IPointCollection).PointCount;
                                    }
                                    num2 = num2 + pointCount;
                                    lineMovePointFeedbackClass.Start(hitTest as IPolyline, num2, point);
                                    this.ilist_0.Add(lineMovePointFeedbackClass);
                                    this.ilist_1.Add(point);
                                }
                            }
                            else
                            {
                                if (edgeFeature.FromJunctionEID != fromJunctionEID)
                                {
                                    shape =
                                        (shapeCopy as IPointCollection).Point[
                                            (shapeCopy as IPointCollection).PointCount - 1];
                                    lineMovePointFeedbackClass.Start(shapeCopy as IPolyline,
                                                                     (shapeCopy as IPointCollection).PointCount - 1, shape);
                                }
                                else
                                {
                                    shape = (shapeCopy as IPointCollection).Point[0];
                                    lineMovePointFeedbackClass.Start(shapeCopy as IPolyline, 0, shape);
                                }
                                this.ilist_0.Add(lineMovePointFeedbackClass);
                                this.ilist_1.Add(shape);
                            }
                        }
                    }
                }
            }
            else
            {
                this.method_2(iedgeFeature_0 as IComplexEdgeFeature);
            }
        }
Ejemplo n.º 24
0
 //�ƶ�Ԫ��
 public void fMoveElement(double mapX, double mapY)
 {
     IEnvelope pEnv;
     IGeometry m_geometry;
     IPoint pt;
     if (m_elementToMove != null)
     {
         m_geometry = m_elementToMove.Geometry;
         pEnv = m_geometry.Envelope;
         pt = new ESRI.ArcGIS.Geometry.Point();
         pt.X = mapX;
         pt.Y = mapY;
         pEnv.CenterAt(pt);
         m_elementToMove.Geometry = pEnv;
        m_pagelayoutControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, null);
       //  m_pagelayoutControl.ActiveView.Refresh();
     }
 }
Ejemplo n.º 25
0
 public bool Snap2Point2(IPoint ipoint_1, IPoint ipoint_2, esriSimpleMarkerStyle esriSimpleMarkerStyle_0)
 {
     if (!Editor.UseOldSnap)
     {
         ISnappingResult snappingResult = SketchToolAssist.m_psnaper.Snap(ipoint_1);
         if (snappingResult == null)
         {
             if (this.ianchorPoint_0 == null)
             {
                 this.ianchorPoint_0 = new AnchorPoint()
                 {
                     Symbol = this.isimpleMarkerSymbol_0 as ISymbol
                 };
             }
             this.ianchorPoint_0.MoveTo(ipoint_1, this.iactiveView_0.ScreenDisplay);
             this.bool_0 = false;
         }
         else
         {
             ipoint_2    = snappingResult.Location;
             this.bool_0 = true;
             if (this.ianchorPoint_0 != null)
             {
                 this.ianchorPoint_0.MoveTo(snappingResult.Location, this.iactiveView_0.ScreenDisplay);
             }
             else
             {
                 this.method_1(snappingResult.Location, esriSimpleMarkerStyle_0);
             }
         }
     }
     else
     {
         ISimpleMarkerSymbol isimpleMarkerSymbol0 = this.isimpleMarkerSymbol_0;
         isimpleMarkerSymbol0.Style = esriSimpleMarkerStyle_0;
         if (ipoint_2 == null)
         {
             ipoint_2 = new ESRI.ArcGIS.Geometry.Point();
         }
         ipoint_2.PutCoords(ipoint_1.X, ipoint_1.Y);
         if (this.iengineSnapEnvironment_0 is SnapEnvironment)
         {
             if ((!ApplicationRef.AppContext.Config.UseSnap
                 ? true
                 : !(this.iengineSnapEnvironment_0 as SnapEnvironment).SnapPoint(ipoint_1, ipoint_2)))
             {
                 this.bool_0 = false;
                 if (this.ianchorPoint_0 != null)
                 {
                     this.ianchorPoint_0.Symbol = (ISymbol)isimpleMarkerSymbol0;
                     this.ianchorPoint_0.MoveTo(ipoint_1, this.iactiveView_0.ScreenDisplay);
                 }
                 else
                 {
                     this.method_1(ipoint_1, esriSimpleMarkerStyle_0);
                 }
             }
             else
             {
                 this.bool_0 = true;
                 if (this.ianchorPoint_0 != null)
                 {
                     this.ianchorPoint_0.Symbol = (ISymbol)isimpleMarkerSymbol0;
                     this.ianchorPoint_0.MoveTo(ipoint_2, this.iactiveView_0.ScreenDisplay);
                 }
                 else
                 {
                     this.method_1(ipoint_2, esriSimpleMarkerStyle_0);
                 }
             }
         }
         else if ((this.iengineSnapEnvironment_0 == null || !ApplicationRef.AppContext.Config.UseSnap
             ? true
             : !this.iengineSnapEnvironment_0.SnapPoint(ipoint_2)))
         {
             this.bool_0 = false;
             if (this.ianchorPoint_0 != null)
             {
                 this.ianchorPoint_0.Symbol = (ISymbol)isimpleMarkerSymbol0;
                 this.ianchorPoint_0.MoveTo(ipoint_1, this.iactiveView_0.ScreenDisplay);
             }
             else
             {
                 this.method_1(ipoint_1, esriSimpleMarkerStyle_0);
             }
         }
         else
         {
             this.bool_0 = true;
             if (this.ianchorPoint_0 != null)
             {
                 this.ianchorPoint_0.Symbol = (ISymbol)isimpleMarkerSymbol0;
                 this.ianchorPoint_0.MoveTo(ipoint_2, this.iactiveView_0.ScreenDisplay);
             }
             else
             {
                 this.method_1(ipoint_2, esriSimpleMarkerStyle_0);
             }
         }
     }
     return(this.bool_0);
 }
Ejemplo n.º 26
0
        public static IPolygon GetPolyGonFromFile(string path)
        {
            IPolygon pGon = null;

            if (path.EndsWith(".mdb"))
            {
                string            errmsg       = "";
                IWorkspaceFactory pwf          = new ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactoryClass();
                IWorkspace        pworkspace   = pwf.OpenFromFile(path, 0);
                IEnumDataset      pEnumdataset = pworkspace.get_Datasets(esriDatasetType.esriDTFeatureClass);
                pEnumdataset.Reset();
                IDataset pDataset = pEnumdataset.Next();
                while (pDataset != null)
                {
                    IFeatureClass pFeatureclass = pDataset as IFeatureClass;
                    if (pFeatureclass.ShapeType != esriGeometryType.esriGeometryPolygon && pFeatureclass.ShapeType != esriGeometryType.esriGeometryPolyline)
                    {
                        pDataset = pEnumdataset.Next();
                        continue;
                    }
                    else if (pFeatureclass.ShapeType == esriGeometryType.esriGeometryPolygon)
                    {
                        IFeatureCursor pCursor  = pFeatureclass.Search(null, false);
                        IFeature       pFeature = pCursor.NextFeature();
                        if (pFeature != null)
                        {
                            pGon = pFeature.Shape as IPolygon;
                            break;
                        }
                        else
                        {
                            pDataset = pEnumdataset.Next();
                            continue;
                        }
                    }
                    else if (pFeatureclass.ShapeType == esriGeometryType.esriGeometryPolyline)
                    {
                        IFeatureCursor pCursor  = pFeatureclass.Search(null, false);
                        IFeature       pFeature = pCursor.NextFeature();
                        if (pFeature != null)
                        {
                            IPolyline pPolyline = pFeature.Shape as IPolyline;
                            pGon = GetPolygonFormLine(pPolyline);
                            if (pGon.IsClosed == false)
                            {
                                errmsg   = "选择的要素不能构成封闭多边形!";
                                pGon     = null;
                                pDataset = pEnumdataset.Next();
                                continue;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                if (pGon == null)
                {
                    IEnumDataset pEnumdataset1 = pworkspace.get_Datasets(esriDatasetType.esriDTFeatureDataset);
                    pEnumdataset1.Reset();
                    pDataset = pEnumdataset1.Next();
                    while (pDataset != null)
                    {
                        IFeatureDataset pFeatureDataset = pDataset as IFeatureDataset;
                        IEnumDataset    pEnumDataset2   = pFeatureDataset.Subsets;
                        pEnumDataset2.Reset();
                        IDataset pDataset1 = pEnumDataset2.Next();
                        while (pDataset1 != null)
                        {
                            if (pDataset1 is IFeatureClass)
                            {
                                IFeatureClass pFeatureclass = pDataset1 as IFeatureClass;
                                if (pFeatureclass.ShapeType != esriGeometryType.esriGeometryPolygon && pFeatureclass.ShapeType != esriGeometryType.esriGeometryPolyline)
                                {
                                    pDataset1 = pEnumDataset2.Next();
                                    continue;
                                }
                                else if (pFeatureclass.ShapeType == esriGeometryType.esriGeometryPolygon)
                                {
                                    IFeatureCursor pCursor  = pFeatureclass.Search(null, false);
                                    IFeature       pFeature = pCursor.NextFeature();
                                    if (pFeature != null)
                                    {
                                        pGon = pFeature.Shape as IPolygon;
                                        break;
                                    }
                                    else
                                    {
                                        pDataset1 = pEnumDataset2.Next();
                                        continue;
                                    }
                                }
                                else if (pFeatureclass.ShapeType == esriGeometryType.esriGeometryPolyline)
                                {
                                    IFeatureCursor pCursor  = pFeatureclass.Search(null, false);
                                    IFeature       pFeature = pCursor.NextFeature();
                                    if (pFeature != null)
                                    {
                                        IPolyline pPolyline = pFeature.Shape as IPolyline;
                                        pGon = GetPolygonFormLine(pPolyline);
                                        if (pGon.IsClosed == false)
                                        {
                                            errmsg    = "选择的要素不能构成封闭多边形!";
                                            pGon      = null;
                                            pDataset1 = pEnumDataset2.Next();
                                            continue;
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        if (pGon != null)
                        {
                            break;
                        }
                        pDataset = pEnumdataset1.Next();
                    }
                }
                if (pGon == null)
                {
                    if (errmsg != "")
                    {
                        System.Windows.Forms.MessageBox.Show(errmsg, "提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
                    }
                    else
                    {
                        System.Windows.Forms.MessageBox.Show("请选择一个包含面要素和线要素的文件", "提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
                    }
                    return(pGon);
                }
            }
            else if (path.EndsWith(".shp"))
            {
                IWorkspaceFactory pwf               = new ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass();
                string            filepath          = System.IO.Path.GetDirectoryName(path);
                string            filename          = path.Substring(path.LastIndexOf("\\") + 1);
                IFeatureWorkspace pFeatureworkspace = (IFeatureWorkspace)pwf.OpenFromFile(filepath, 0);
                IFeatureClass     pFeatureclass     = pFeatureworkspace.OpenFeatureClass(filename);
                if (pFeatureclass.ShapeType == esriGeometryType.esriGeometryPolygon)
                {
                    IFeatureCursor pCursor  = pFeatureclass.Search(null, false);
                    IFeature       pFeature = pCursor.NextFeature();
                    if (pFeature != null)
                    {
                        pGon = pFeature.Shape as IPolygon;
                    }
                }
                else if (pFeatureclass.ShapeType == esriGeometryType.esriGeometryPolyline)
                {
                    IFeatureCursor pCursor  = pFeatureclass.Search(null, false);
                    IFeature       pFeature = pCursor.NextFeature();
                    if (pFeature != null)
                    {
                        IPolyline pPolyline = pFeature.Shape as IPolyline;
                        pGon = GetPolygonFormLine(pPolyline);
                        if (pGon.IsClosed == false)
                        {
                            System.Windows.Forms.MessageBox.Show("选择的线要素不能构成封闭多边形!", "提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
                            return(null);
                        }
                    }
                }
                else
                {
                    System.Windows.Forms.MessageBox.Show("请选择一个面或者线要素文件!", "提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
                    return(null);
                }
            }
            else if (path.EndsWith(".txt"))
            {
                string txtpath = path;
                System.IO.StreamReader smRead = new System.IO.StreamReader(txtpath, System.Text.Encoding.Default); //设置路径
                string line;

                IPointCollection pc = pGon as IPointCollection;
                double           x, y;
                while ((line = smRead.ReadLine()) != null)
                {
                    if (line.IndexOf(",") > 0)
                    {
                        try
                        {
                            x = double.Parse(line.Substring(0, line.IndexOf(",")));
                            y = double.Parse(line.Substring(line.IndexOf(",") + 1));
                        }
                        catch
                        {
                            System.Windows.Forms.MessageBox.Show("文本文件格式不正确!", "提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
                            smRead.Close();
                            return(null);
                        }
                        IPoint tmpPoint = new ESRI.ArcGIS.Geometry.Point();
                        tmpPoint.X = x;
                        tmpPoint.Y = y;
                        object ep = System.Reflection.Missing.Value;

                        pc.AddPoint(tmpPoint, ref ep, ref ep);
                    }
                }
                smRead.Close();
                ICurve pCurve = pGon as ICurve;
                if (pCurve.IsClosed == false)
                {
                    System.Windows.Forms.MessageBox.Show("导入点坐标不能构成封闭多边形!", "提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
                    return(null);
                }
            }
            else if (path.EndsWith("gdb"))
            {
                string            errmsg       = "";
                IWorkspaceFactory pwf          = new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass();
                IWorkspace        pworkspace   = pwf.OpenFromFile(path.Substring(0, path.LastIndexOf("\\")), 0);
                IEnumDataset      pEnumdataset = pworkspace.get_Datasets(esriDatasetType.esriDTFeatureClass);
                pEnumdataset.Reset();
                IDataset pDataset = pEnumdataset.Next();
                while (pDataset != null)
                {
                    IFeatureClass pFeatureclass = pDataset as IFeatureClass;
                    if (pFeatureclass.ShapeType != esriGeometryType.esriGeometryPolygon && pFeatureclass.ShapeType != esriGeometryType.esriGeometryPolyline)
                    {
                        pDataset = pEnumdataset.Next();
                        continue;
                    }
                    else if (pFeatureclass.ShapeType == esriGeometryType.esriGeometryPolygon)
                    {
                        IFeatureCursor pCursor  = pFeatureclass.Search(null, false);
                        IFeature       pFeature = pCursor.NextFeature();
                        if (pFeature != null)
                        {
                            pGon = pFeature.Shape as IPolygon;
                            break;
                        }
                        else
                        {
                            pDataset = pEnumdataset.Next();
                            continue;
                        }
                    }
                    else if (pFeatureclass.ShapeType == esriGeometryType.esriGeometryPolyline)
                    {
                        IFeatureCursor pCursor  = pFeatureclass.Search(null, false);
                        IFeature       pFeature = pCursor.NextFeature();
                        if (pFeature != null)
                        {
                            IPolyline pPolyline = pFeature.Shape as IPolyline;
                            pGon = GetPolygonFormLine(pPolyline);
                            if (pGon.IsClosed == false)
                            {
                                errmsg   = "选择的要素不能构成封闭多边形!";
                                pGon     = null;
                                pDataset = pEnumdataset.Next();
                                continue;
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                if (pGon == null)
                {
                    IEnumDataset pEnumdataset1 = pworkspace.get_Datasets(esriDatasetType.esriDTFeatureDataset);
                    pEnumdataset1.Reset();
                    pDataset = pEnumdataset1.Next();
                    while (pDataset != null)
                    {
                        IFeatureDataset pFeatureDataset = pDataset as IFeatureDataset;
                        IEnumDataset    pEnumDataset2   = pFeatureDataset.Subsets;
                        pEnumDataset2.Reset();
                        IDataset pDataset1 = pEnumDataset2.Next();
                        while (pDataset1 != null)
                        {
                            if (pDataset1 is IFeatureClass)
                            {
                                IFeatureClass pFeatureclass = pDataset1 as IFeatureClass;
                                if (pFeatureclass.ShapeType != esriGeometryType.esriGeometryPolygon && pFeatureclass.ShapeType != esriGeometryType.esriGeometryPolyline)
                                {
                                    pDataset1 = pEnumDataset2.Next();
                                    continue;
                                }
                                else if (pFeatureclass.ShapeType == esriGeometryType.esriGeometryPolygon)
                                {
                                    IFeatureCursor pCursor  = pFeatureclass.Search(null, false);
                                    IFeature       pFeature = pCursor.NextFeature();
                                    if (pFeature != null)
                                    {
                                        pGon = pFeature.Shape as IPolygon;
                                        break;
                                    }
                                    else
                                    {
                                        pDataset1 = pEnumDataset2.Next();
                                        continue;
                                    }
                                }
                                else if (pFeatureclass.ShapeType == esriGeometryType.esriGeometryPolyline)
                                {
                                    IFeatureCursor pCursor  = pFeatureclass.Search(null, false);
                                    IFeature       pFeature = pCursor.NextFeature();
                                    if (pFeature != null)
                                    {
                                        IPolyline pPolyline = pFeature.Shape as IPolyline;
                                        pGon = GetPolygonFormLine(pPolyline);
                                        if (pGon.IsClosed == false)
                                        {
                                            errmsg    = "选择的要素不能构成封闭多边形!";
                                            pGon      = null;
                                            pDataset1 = pEnumDataset2.Next();
                                            continue;
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        if (pGon != null)
                        {
                            break;
                        }
                        pDataset = pEnumdataset1.Next();
                    }
                }
                if (pGon == null)
                {
                    if (errmsg != "")
                    {
                        System.Windows.Forms.MessageBox.Show(errmsg, "提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
                    }
                    else
                    {
                        System.Windows.Forms.MessageBox.Show("请选择一个包含面要素和线要素的文件", "提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
                    }
                    return(pGon);
                }
            }
            return(pGon);
        }
Ejemplo n.º 27
0
        private bool TestGeometryHit(double tolerance, IPoint pPoint, IFeature pFeature, ref IPoint pHitPoint, ref double hitDist, ref int partIndex, ref int vertexIndex, ref int vertexOffset, ref bool vertexHit)
        {
            // Function returns true if a feature's shape is hit and further defines
            // if a vertex lies within the tolorance
            bool bRetVal = false;
            IGeometry pGeom = (IGeometry)pFeature.Shape;

            IHitTest pHitTest = (IHitTest)pGeom;
            pHitPoint = new ESRI.ArcGIS.Geometry.Point();
            bool bTrue = true;
            // ��鶥���Ƿ񱻵��
            if (pHitTest.HitTest(pPoint, tolerance, esriGeometryHitPartType.esriGeometryPartVertex, pHitPoint, ref hitDist, ref partIndex, ref vertexIndex, ref bTrue))
            {
                bRetVal = true;
                vertexHit = true;
            }
            // ���߽��Ƿ񱻵��
            else if (pHitTest.HitTest(pPoint, tolerance, esriGeometryHitPartType.esriGeometryPartBoundary, pHitPoint, ref hitDist, ref partIndex, ref vertexIndex, ref bTrue))
            {
                bRetVal = true;
                vertexHit = false;
            }

            // ͳ��vertexOffset������Ŀ
            if (partIndex > 0)
            {
                IGeometryCollection pGeomColn = (IGeometryCollection)pGeom;
                vertexOffset = 0;
                for (int i = 0; i < partIndex; i++)
                {
                    IPointCollection pPointColn = (IPointCollection)pGeomColn.get_Geometry(i);
                    vertexOffset = vertexOffset + pPointColn.PointCount;
                }
            }
            return bRetVal;
        }
Ejemplo n.º 28
0
        public bool Snap(IGeometry igeometry_0, IPoint ipoint_0, double double_0)
        {
            bool   flag;
            double num        = 0;
            int    num1       = 0;
            int    num2       = 0;
            bool   flag1      = true;
            IPoint pointClass = new ESRI.ArcGIS.Geometry.Point();
            bool   flag2      = false;
            IPoint ipoint0    = ipoint_0;
            IPoint igeometry0 = null;

            if (igeometry_0 is IPoint)
            {
                igeometry0 = (IPoint)igeometry_0;
            }
            else if (igeometry_0 != null)
            {
                igeometry0 = ((IPointCollection)igeometry_0).Point[0];
            }
            int num3 = 0;

            while (true)
            {
                if (num3 < this.ifeatureCache_0.Count)
                {
                    IHitTest shape = (IHitTest)this.ifeatureCache_0.Feature[num3].Shape;
                    if (shape.HitTest(ipoint0, double_0, esriGeometryHitPartType.esriGeometryPartBoundary, pointClass,
                                      ref num, ref num1, ref num2, ref flag1))
                    {
                        ILine segment =
                            ((ISegmentCollection)((IGeometryCollection)shape).Geometry[num1]).Segment[num2] as ILine;
                        if (segment != null)
                        {
                            ILine lineClass = new Line();
                            lineClass.PutCoords(segment.FromPoint, igeometry0);
                            double angle = lineClass.Angle;
                            if (angle < 0)
                            {
                                angle = angle + 6.28318530717959;
                            }
                            double angle1 = segment.Angle;
                            if (angle1 < 0)
                            {
                                angle1 = angle1 + 6.28318530717959;
                            }
                            double num4 = angle1 - angle;
                            if (num4 < 0)
                            {
                                num4 = num4 + 6.28318530717959;
                            }
                            double num5 = Math.Cos(num4) * lineClass.Length;
                            if (num5 <= segment.Length)
                            {
                                IPoint point = new Point()
                                {
                                    X = segment.FromPoint.X + num5 * Math.Cos(segment.Angle),
                                    Y = segment.FromPoint.Y + num5 * Math.Sin(segment.Angle),
                                    Z = pointClass.Z
                                };
                                ipoint_0.PutCoords(point.X, point.Y);
                                flag = true;
                                break;
                            }
                        }
                    }
                    num3++;
                }
                else
                {
                    flag = flag2;
                    break;
                }
            }
            return(flag);
        }
        protected override void OnMouseUp(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg)
        {
            bool abortOperation = false;

            ESRI.ArcGIS.Schematic.ISchematicOperation schematicOperation = null;

            try
            {
                if (m_dockableDigit == null)
                {
                    return;
                }

                if (arg != null)
                {
                    m_x = arg.X;
                    m_y = arg.Y;
                }

                if (m_dockableWindow == null)
                {
                    return;
                }

                if (m_dockableWindow.IsVisible() == false)
                {
                    m_dockableWindow.Show(true);
                }

                ESRI.ArcGIS.SchematicControls.ISchematicTarget target = (ESRI.ArcGIS.SchematicControls.ISchematicTarget)m_schematicExtension;

                if (target != null)
                {
                    m_schematicLayer = target.SchematicTarget;
                }

                if (m_schematicLayer == null)
                {
                    System.Windows.Forms.MessageBox.Show("No target Layer");
                    return;
                }

                ISchematicInMemoryDiagram               inMemoryDiagram;
                ISchematicInMemoryFeatureClass          schematicInMemoryFeatureClass;
                ISchematicInMemoryFeatureClassContainer schematicInMemoryFeatureClassContainer;

                //Get the point
                ESRI.ArcGIS.Geometry.Point point = new ESRI.ArcGIS.Geometry.Point();

                ESRI.ArcGIS.ArcMapUI.IMxApplication mxApp;
                ESRI.ArcGIS.Display.IAppDisplay     appDisplay;
                IScreenDisplay         screenDisplay;
                IDisplay               display;
                IDisplayTransformation transform;
                ISpatialReference      spatialReference;

                inMemoryDiagram = m_schematicLayer.SchematicInMemoryDiagram;
                schematicInMemoryFeatureClassContainer = (ISchematicInMemoryFeatureClassContainer)inMemoryDiagram;

                if (schematicInMemoryFeatureClassContainer == null)
                {
                    return;
                }

                mxApp = (ESRI.ArcGIS.ArcMapUI.IMxApplication)m_app;

                if (mxApp == null)
                {
                    return;
                }

                appDisplay = mxApp.Display;

                if (appDisplay == null)
                {
                    return;
                }

                screenDisplay = appDisplay.FocusScreen;
                display       = screenDisplay;

                if (display == null)
                {
                    return;
                }

                transform = display.DisplayTransformation;

                if (transform == null)
                {
                    return;
                }

                spatialReference = transform.SpatialReference;

                WKSPoint mapPt = new WKSPoint();
                ESRI.ArcGIS.Display.tagPOINT devPoint;
                devPoint.x = m_x;
                devPoint.y = m_y;
                transform.TransformCoords(ref mapPt, ref devPoint, 1, 1); //'esriTransformToMap

                point.SpatialReference = spatialReference;
                point.Project(spatialReference);
                point.X = mapPt.X;
                point.Y = mapPt.Y;

                schematicInMemoryFeatureClass = schematicInMemoryFeatureClassContainer.GetSchematicInMemoryFeatureClass(m_dockableDigit.FeatureClass());

                if (schematicInMemoryFeatureClass == null)
                {
                    System.Windows.Forms.MessageBox.Show("Invalid Type.");
                    return;
                }

                if (m_dockableDigit.CreateNode())
                {
                    //TestMandatoryField
                    m_dockableDigit.btnOKPanel1.Visible = false;

                    if (m_dockableDigit.ValidateFields() == false)
                    {
                        m_dockableDigit.x(m_x);
                        m_dockableDigit.y(m_y);

                        System.Windows.Forms.MessageBox.Show(m_dockableDigit.ErrorProvider1.GetError(m_dockableDigit.btnOKPanel1) + m_messageFromOK);
                        return;
                    }

                    ESRI.ArcGIS.Geometry.IGeometry geometry;

                    ISchematicInMemoryFeature schematicInMemoryFeatureNode;

                    geometry = point;

                    schematicOperation = (ESRI.ArcGIS.Schematic.ISchematicOperation) new ESRI.ArcGIS.SchematicControls.SchematicOperation();

                    //digit operation is undo(redo)able we add it in the stack
                    IMxDocument doc = (IMxDocument)m_app.Document;
                    ESRI.ArcGIS.SystemUI.IOperationStack operationStack;
                    operationStack = doc.OperationStack;
                    operationStack.Do(schematicOperation);
                    schematicOperation.StartOperation("Digit", m_app, m_schematicLayer, true);

                    //do abort operation
                    abortOperation = true;

                    schematicInMemoryFeatureNode = schematicInMemoryFeatureClass.CreateSchematicInMemoryFeatureNode(geometry, "");
                    //schematicInMemoryFeatureNode.UpdateStatus = esriSchematicUpdateStatus.esriSchematicUpdateStatusNew; if we want the node deleted after update
                    schematicInMemoryFeatureNode.UpdateStatus = esriSchematicUpdateStatus.esriSchematicUpdateStatusLocked;

                    abortOperation = false;
                    schematicOperation.StopOperation();

                    ISchematicFeature schematicFeature = schematicInMemoryFeatureNode;
                    m_dockableDigit.FillValue(ref schematicFeature);

                    if (m_dockableDigit.AutoClear())
                    {
                        m_dockableDigit.SelectionChanged();
                    }
                }
                else
                {
                    m_dockableDigit.btnOKPanel2.Visible = false;

                    //Get the Tolerance of ArcMap
                    Double      tolerance;
                    IMxDocument mxDocument = (ESRI.ArcGIS.ArcMapUI.IMxDocument)m_app.Document;
                    ESRI.ArcGIS.esriSystem.WKSPoint point2 = new WKSPoint();
                    ESRI.ArcGIS.Display.tagPOINT    devPt;

                    tolerance = mxDocument.SearchTolerancePixels;
                    devPt.x   = (int)tolerance;
                    devPt.y   = (int)tolerance;

                    transform.TransformCoords(ref point2, ref devPt, 1, 2); //2 <-> esriTransformSize 4 <-> esriTransformToMap

                    tolerance = point2.X * 5;                               //increase the tolerance value

                    IEnumSchematicFeature schematicFeatures = m_schematicLayer.GetSchematicFeaturesAtPoint(point, tolerance, false, true);

                    ISchematicFeature schematicFeatureSelected = null;
                    double            distancetmp;
                    double            distance = 0;
                    schematicFeatures.Reset();

                    if (schematicFeatures.Count <= 0)
                    {
                        return;
                    }

                    //pSchematicFeatures may contain several features, we are choosing the closest node.
                    ISchematicFeature schematicFeature2 = schematicFeatures.Next();

                    double dX;
                    double dY;
                    ISchematicInMemoryFeatureNode schematicInMemoryFeatureNode = null;
                    if (schematicFeature2 != null)
                    {
                        if (schematicFeature2.SchematicElementClass.SchematicElementType == ESRI.ArcGIS.Schematic.esriSchematicElementType.esriSchematicNodeType)
                        {
                            schematicInMemoryFeatureNode = (ISchematicInMemoryFeatureNode)schematicFeature2;
                        }
                    }

                    ISchematicInMemoryFeatureNodeGeometry schematicInMemoryFeatureNodeGeometry = (ISchematicInMemoryFeatureNodeGeometry)schematicInMemoryFeatureNode;
                    dX = schematicInMemoryFeatureNodeGeometry.Position.X;
                    dY = schematicInMemoryFeatureNodeGeometry.Position.Y;
                    schematicFeatureSelected = schematicFeature2;
                    distance = SquareDistance(dX - point.X, dY - point.Y);

                    while (schematicFeature2 != null)
                    {
                        //find the closest featureNode...
                        if (schematicInMemoryFeatureNode != null)
                        {
                            schematicInMemoryFeatureNodeGeometry = (ISchematicInMemoryFeatureNodeGeometry)schematicInMemoryFeatureNode;

                            if (schematicInMemoryFeatureNodeGeometry == null)
                            {
                                continue;
                            }

                            dX          = schematicInMemoryFeatureNodeGeometry.Position.X;
                            dY          = schematicInMemoryFeatureNodeGeometry.Position.Y;
                            distancetmp = SquareDistance(dX - point.X, dY - point.Y);

                            if (distancetmp < distance)
                            {
                                distance = distancetmp;
                                schematicFeatureSelected = schematicFeature2;
                            }
                        }

                        schematicFeature2 = schematicFeatures.Next();

                        if (schematicFeature2 != null)
                        {
                            if (schematicFeature2.SchematicElementClass.SchematicElementType == ESRI.ArcGIS.Schematic.esriSchematicElementType.esriSchematicNodeType)
                            {
                                schematicInMemoryFeatureNode = (ISchematicInMemoryFeatureNode)schematicFeature2;
                            }
                        }
                    }

                    if (schematicFeatureSelected == null)
                    {
                        return;
                    }

                    if (schematicFeatureSelected.SchematicElementClass.SchematicElementType != esriSchematicElementType.esriSchematicNodeType)
                    {
                        return;
                    }

                    if (m_schematicFeature1 == null)
                    {
                        m_schematicFeature1 = schematicFeatureSelected;
                        m_dockableDigit.SchematicFeature1(m_schematicFeature1);

                        if (!m_dockableDigit.CheckValidFeature(true))
                        {
                            m_schematicFeature1 = null;
                            m_dockableDigit.SchematicFeature1(m_schematicFeature1);
                            throw new Exception("Invalid starting node for this link type");
                        }

                        //Begin Feedback
                        m_linkFbk         = new NewLineFeedback();
                        m_linkFbk.Display = screenDisplay;

                        //symbol
                        ISimpleLineSymbol sLnSym;
                        IRgbColor         rGB = new RgbColor();

                        sLnSym = (ESRI.ArcGIS.Display.ISimpleLineSymbol)m_linkFbk.Symbol;

                        //Make a color
                        rGB.Red   = 255;
                        rGB.Green = 0;
                        rGB.Blue  = 0;

                        // Setup the symbol with color and style
                        sLnSym.Color = rGB;

                        m_linkFbk.Start(point);
                        //End Feedback

                        //To know if we are in the same diagram.
                        m_schematicLayerForLink = m_schematicLayer;
                    }
                    else
                    {
                        if (m_schematicLayerForLink != m_schematicLayer)
                        {
                            System.Windows.Forms.MessageBox.Show("wrong Target layer");
                            m_schematicLayerForLink = null;
                            EndFeedBack();
                            return;
                        }
                        m_schematicFeature2 = schematicFeatureSelected;
                        m_dockableDigit.SchematicFeature2(m_schematicFeature2);

                        //TestMandatoryField
                        if (m_dockableDigit.ValidateFields() == false)
                        {
                            m_dockableDigit.x(m_x);
                            m_dockableDigit.y(m_y);

                            System.Windows.Forms.MessageBox.Show(m_dockableDigit.ErrorProvider1.GetError(m_dockableDigit.btnOKPanel2) + m_messageFromOK);
                            return;
                        }

                        if (!m_dockableDigit.CheckValidFeature(false))
                        {
                            m_schematicFeature2 = null;
                            m_dockableDigit.SchematicFeature2(m_schematicFeature2);
                            throw new Exception("Invalid End node for this link type");
                        }

                        //CreateLink
                        ISchematicInMemoryFeature schematicInMemoryFeatureLink;

                        schematicOperation = (ESRI.ArcGIS.Schematic.ISchematicOperation) new ESRI.ArcGIS.SchematicControls.SchematicOperation();

                        //digit operation is undo(redo)able we add it in the stack
                        IMxDocument doc = (IMxDocument)m_app.Document;
                        ESRI.ArcGIS.SystemUI.IOperationStack operationStack;
                        operationStack = doc.OperationStack;
                        operationStack.Do(schematicOperation);
                        schematicOperation.StartOperation("Digit", m_app, m_schematicLayer, true);

                        //do abort operation
                        abortOperation = true;

                        schematicInMemoryFeatureLink = schematicInMemoryFeatureClass.CreateSchematicInMemoryFeatureLink((ESRI.ArcGIS.Schematic.ISchematicInMemoryFeatureNode)m_schematicFeature1, (ESRI.ArcGIS.Schematic.ISchematicInMemoryFeatureNode)m_schematicFeature2, "");
                        //schematicInMemoryFeatureLink.UpdateStatus = esriSchematicUpdateStatus.esriSchematicUpdateStatusNew; if we want the node deleted after update
                        schematicInMemoryFeatureLink.UpdateStatus = esriSchematicUpdateStatus.esriSchematicUpdateStatusLocked;

                        abortOperation = false;
                        schematicOperation.StopOperation();

                        ISchematicFeature schematicFeature = schematicInMemoryFeatureLink;
                        m_dockableDigit.FillValue(ref schematicFeature);

                        //End Feedback
                        EndFeedBack();

                        m_schematicLayerForLink = null;

                        if (m_dockableDigit.AutoClear())
                        {
                            m_dockableDigit.SelectionChanged();
                        }
                    }
                }

                //Refresh the view and viewer windows
                RefreshView();
            }
            catch (System.Exception e)
            {
                if (abortOperation && (schematicOperation != null))
                {
                    schematicOperation.AbortOperation();
                }

                EndFeedBack();
                System.Windows.Forms.MessageBox.Show(e.Message);
            }

            return;
        }
Ejemplo n.º 30
0
 private void btnAnalyse_Click(object obj, EventArgs eventArgs)
 {
     if (this.MapControl != null)
     {
         this.igeometryCollection_0.RemoveGeometries(0, this.igeometryCollection_0.GeometryCount);
         SearchAffixAnalyDlg.DeleteAllElements(this.m_iApp.ActiveView);
         ((IFeatureSelection)this.ifeatureLayer_0).Clear();
         IFeatureClass  featureClass  = this.ifeatureLayer_0.FeatureClass;
         ISpatialFilter spatialFilter = new SpatialFilter();
         string         text          = "";
         int            count         = this.list_0.Count;
         int            num           = 1;
         foreach (string current in this.list_0)
         {
             text += this.string_0;
             text += " = '";
             text += current;
             text += "'";
             if (num < count)
             {
                 text += " OR ";
             }
             num++;
         }
         if (this.txBoxX.Text == "" || this.txBoxY.Text == "")
         {
             MessageBox.Show("请设置搜索中心点坐标!");
         }
         else if (this.txBoxRadius.Text == "")
         {
             MessageBox.Show("请设置查找半径!");
         }
         else
         {
             if (this.list_0.Count != 0)
             {
             }
             this.m_iApp.ActiveView.Refresh();
             IPoint point = new ESRI.ArcGIS.Geometry.Point();
             double num2  = 0.0;
             if (this.txBoxX.Text == "")
             {
                 point.X = (0.0);
             }
             else
             {
                 point.X = (Convert.ToDouble(this.txBoxX.Text.Trim()));
             }
             if (this.txBoxY.Text == "")
             {
                 point.Y = (0.0);
             }
             else
             {
                 point.Y = (Convert.ToDouble(this.txBoxY.Text.Trim()));
             }
             SearchAffixAnalyDlg.NewBasePointElement(this.m_iApp.ActiveView, point);
             if (this.txBoxRadius.Text != "")
             {
                 num2 = Convert.ToDouble(this.txBoxRadius.Text.Trim());
             }
             ITopologicalOperator topologicalOperator = (ITopologicalOperator)point;
             IGeometry            geometry            = topologicalOperator.Buffer(num2);
             spatialFilter.Geometry    = (geometry);
             spatialFilter.SpatialRel  = (esriSpatialRelEnum)(1);
             spatialFilter.WhereClause = (text);
             if (this.list_0.Count > 0)
             {
                 IFeatureCursor featureCursor = featureClass.Search(spatialFilter, false);
                 for (IFeature feature = featureCursor.NextFeature();
                      feature != null;
                      feature = featureCursor.NextFeature())
                 {
                     object missing = Type.Missing;
                     this.igeometryCollection_0.AddGeometry(feature.ShapeCopy, ref missing, ref missing);
                     SearchAffixAnalyDlg.NewPointElement(this.m_iApp.ActiveView, feature.ShapeCopy as IPoint);
                     this.method_7(this.m_iApp.ActiveView, point, feature.Shape as IPoint);
                 }
                 IRgbColor rgbColor = new RgbColor();
                 rgbColor.Red   = (255);
                 rgbColor.Green = (0);
                 rgbColor.Blue  = (0);
                 IRgbColor rgbColor2 = new RgbColor();
                 rgbColor2.Red   = (0);
                 rgbColor2.Green = (255);
                 rgbColor2.Blue  = (0);
                 this.method_9(this.m_iApp.ActiveView, point, num2, false, rgbColor);
                 this.method_9(this.m_iApp.ActiveView, point, num2 / 2.0, false, rgbColor2);
                 this.FlashDstItem();
                 //featureCursor = featureClass.Search(spatialFilter, false);
                 ((IFeatureSelection)this.ifeatureLayer_0).SelectFeatures(spatialFilter,
                                                                          esriSelectionResultEnum.esriSelectionResultNew, false);
                 //this.m_iApp.SetResult(featureCursor, (IFeatureSelection)this.ifeatureLayer_0);
             }
             if (this.checAnaPipeline.Checked)
             {
                 ILayer layer =
                     (IFeatureLayer)
                     CommonUtils.GetLayerByName(this.m_iApp.FocusMap, this.LayerBox.Text.Replace("点", "线"));
                 if (layer != null)
                 {
                     spatialFilter            = new SpatialFilter();
                     topologicalOperator      = (ITopologicalOperator)point;
                     geometry                 = topologicalOperator.Buffer(num2);
                     spatialFilter.Geometry   = (geometry);
                     spatialFilter.SpatialRel = (esriSpatialRelEnum)(1);
                     IFeatureCursor featureCursor2 = (layer as IFeatureLayer).FeatureClass.Search(spatialFilter,
                                                                                                  false);
                     for (IFeature feature = featureCursor2.NextFeature();
                          feature != null;
                          feature = featureCursor2.NextFeature())
                     {
                         object missing = Type.Missing;
                         this.method_5(point, feature);
                     }
                     featureCursor2 = (layer as IFeatureLayer).FeatureClass.Search(spatialFilter, false);
                     ((IFeatureSelection)layer).SelectFeatures(spatialFilter,
                                                               esriSelectionResultEnum.esriSelectionResultNew, false);
                     // this.m_iApp.SetResult(featureCursor2, (IFeatureSelection)layer);
                 }
             }
         }
     }
 }
Ejemplo n.º 31
0
        // this code runs when user presses the mouse button down on the map
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            try
            {
                //get the current document
                IMxDocument arcMxDoc = clsGlobals.arcApplication.Document as IMxDocument;

                //get the focus map (the active data frame)
                IMap arcMapp = arcMxDoc.FocusMap;

                // get active view (can be data frame in either page layout or data view)
                IActiveView arcActiveView = arcMapp as IActiveView;


                // make sure the user has selected a layer in the toc
                if (arcMxDoc.SelectedLayer == null)
                {
                    MessageBox.Show("Please select the roads layer in ArcMap's TOC.", "Select Layer in TOC", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (!(arcMxDoc.SelectedLayer is IFeatureLayer))
                {
                    MessageBox.Show("Please select a polygon or line layer in the TOC.", "Must be Polygon or Line Layer", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                //cast the selected layer as a feature layer
                IGeoFeatureLayer pGFlayer = (IGeoFeatureLayer)arcMxDoc.SelectedLayer;

                //check if the feaure layer is a polygon or line layer
                if (pGFlayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPolygon & pGFlayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPolyline)
                {
                    MessageBox.Show("Please select a polygon or line layer.", "Must be Polygon or Line Layer", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                // set classic snapping to true
                //IEditProperties4 arcEditProperties4 = clsGlobals.arcEditor as IEditProperties4;
                //arcEditProperties4.ClassicSnapping = true;

                // set some variables for capturing where the user's click location
                ISnapEnvironment arcSnapEnvironment = clsGlobals.arcEditor as ISnapEnvironment;
                //Boolean snapped = arcSnapEnvironment.SnapPoint()


                IPoint arcSplitPoint = new ESRI.ArcGIS.Geometry.Point();
                arcSplitPoint = m_Position; // m_Position is set in the MouseMove event

                // the section of code below that is commented out was used before i converted over to gettting the snapping environment from the mouse movement event
                // don't need it anymore, could be useful if i don't get the snapping point from the mouse movement event
                //////IScreenDisplay arcScreenDisplay = arcActiveView.ScreenDisplay;
                //////IDisplayTransformation arcDisplayTransformation = arcScreenDisplay.DisplayTransformation;

                //////// snap to existing snap environment
                //////arcSnapEnvironment.SnapPoint(m_Position);

                ////////arcSnapEnvironment.SnapPoint(arcSplitPoint);

                //////// get the x and y from the user's mouse click - these are variables that are passed in via the OnMouseDown click event
                //////arcSplitPoint = arcDisplayTransformation.ToMapPoint(X, Y);

                // see if the there's anyintersecting segments with a coordinate address to use values in the new number assignments
                IContentsView   arcContentsView = arcMxDoc.CurrentContentsView;
                IFeatureLayer   arcFeatLayer    = (IFeatureLayer)arcContentsView.SelectedItem;
                IFeatureClass   arcFeatClass    = arcFeatLayer.FeatureClass;
                List <IFeature> listFeatures    = new List <IFeature>();
                listFeatures = checkForIntersectingSegments(arcSplitPoint, 1, arcFeatClass);

                // get the objectid of the selected feature - so we can exclude it from the intesecting search below
                string strSelectedOID = arcSelectedFeature.get_Value(arcSelectedFeature.Fields.FindField("OBJECTID")).ToString();
                isNumeric_StName  = false;
                isNumeric_ACSName = false;

                // if see there are any features intersecting (there is always 1 - it's the selected feature to split, so we need to check if it's more than 1)
                if (listFeatures.Count > 1)
                {
                    bool blnUseCoordinateAddress;

                    // loop through the intesecting features to see if any have coordinate address to use
                    for (int i = 0; i < listFeatures.Count; i++)
                    {
                        // ignore the ifeature that's the selected one - we don't need to check for coordinate values for the selected
                        if (strSelectedOID != listFeatures[i].OID.ToString())
                        {
                            // check if street name is acs/coordinate (numberic)
                            isNumeric_StName = int.TryParse(listFeatures[i].get_Value(listFeatures[i].Fields.FindField("STREETNAME")).ToString(), out intStreetName);

                            isNumeric_ACSName = int.TryParse(listFeatures[i].get_Value(listFeatures[i].Fields.FindField("ACSNAME")).ToString(), out intACSName);

                            // if the value is numeric then capture the number and proceed
                            if (isNumeric_StName == true)
                            {
                                //MessageBox.Show(intStreetName.ToString());
                                break; // breaks from "for loop"
                            }
                            if (isNumeric_ACSName == true)
                            {
                                //MessageBox.Show(intACSName.ToString());
                                break; // breaks from "for loop"
                            }
                        }
                    }
                }

                // call the split centerline method
                doCenterlineSplit(arcSelectedFeature, arcSplitPoint);

                // expand the envelope
                IEnvelope arcEnvelope = arcSelectedFeature.Extent;
                arcEnvelope.Expand(1.2, 1.2, true);
                // if the parent arc is horizontal or vertical, refresh the full screen
                if (arcEnvelope.Width < arcMxDoc.ActivatedView.Extent.Width / 100)
                {
                    arcEnvelope = arcMxDoc.ActivatedView.Extent;
                }
                if (arcEnvelope.Height < arcMxDoc.ActivatedView.Extent.Height / 100)
                {
                    arcEnvelope = arcMxDoc.ActivatedView.Extent;
                }
                //arcActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography & esriViewDrawPhase.esriViewGeoSelection, null, arcEnvelope);

                // deativate the tool
                clsGlobals.arcApplication.CurrentTool = null;
                arcMapp.ClearSelection();
                arcActiveView.Refresh();
                arcActiveView.Refresh();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error Message: " + Environment.NewLine + ex.Message + Environment.NewLine + Environment.NewLine +
                                "Error Source: " + Environment.NewLine + ex.Source + Environment.NewLine + Environment.NewLine +
                                "Error Location:" + Environment.NewLine + ex.StackTrace,
                                "UTRANS Editor tool error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Ejemplo n.º 32
0
        private void Create_Click(object sender, EventArgs e)
        {
            try
            {
                IWorkspaceFactory pShpWksFact = new ShapefileWorkspaceFactory();
                IFeatureWorkspace pFeatWks;
                pFeatWks = (IFeatureWorkspace)pShpWksFact.OpenFromFile(filePath, 0);
                const string strShapeFieldName = "Shape";
                //定义属性字段
                IFields pFields = new Fields();
                IFieldsEdit pFieldsEdit;
                pFieldsEdit = pFields as IFieldsEdit;
                IField pField = new Field();
                IFieldEdit pFieldEdit = new Field() as IFieldEdit;
                pFieldEdit.Name_2 = strShapeFieldName;
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
                pField = pFieldEdit as IField;
                //定义几何属性
                IGeometryDef pGeomDef = new GeometryDef();
                IGeometryDefEdit pGeomDefEdit = new GeometryDef() as IGeometryDefEdit;
                pGeomDefEdit = pGeomDef as IGeometryDefEdit;
                switch (shpTypeComboBox.Text)
                {
                    case "Point":
                        pGeomDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
                        break;
                    case "Polyline":
                        pGeomDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolyline;
                        break;
                    case "Polygon":
                        pGeomDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
                        break;
                }

                pGeomDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
                pGeomDefEdit.SpatialReference_2 = new UnknownCoordinateSystem() as ISpatialReference;
                pFieldEdit.GeometryDef_2 = pGeomDef;
                pFieldsEdit.AddField(pField);
                pFields = pFieldsEdit as IFields;
                IFeatureClass pFeatureClass;
                pFeatureClass = pFeatWks.CreateFeatureClass(fileName, pFields, null, null,
                    esriFeatureType.esriFTSimple, strShapeFieldName, "");
                //添加属性字段
                for (int i = 0; i < addFieldListBox.Items.Count; i++)
                {
                    IField pfield = new Field();
                    IFieldEdit pfieldEdit = new Field() as IFieldEdit;
                    pfieldEdit.Name_2 = addFieldListBox.Items[i].ToString();
                    pfieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                    pfield = pfieldEdit as IField;
                    pFeatureClass.AddField(pfield);
                }
                //绘制点
                for (int i = 0; i < excelDataGridViewX.Rows.Count - 1; i++)
                {
                    DataGridViewRow dataRow = excelDataGridViewX.Rows[i];
                    double pointX, pointY;
                    pointX = double.Parse(dataRow.Cells[xComboBoxEx.Text].Value.ToString());
                    pointY = double.Parse(dataRow.Cells[yComboBoxEx.Text].Value.ToString());

                    IPoint pPoint = new ESRI.ArcGIS.Geometry.Point() as IPoint;
                    pPoint.PutCoords(pointX, pointY);
                    IFeature pFeature = pFeatureClass.CreateFeature();
                    pFeature.Shape = pPoint;
                    //为该点添加属性值
                    for (int j = 0; j < addFieldListBox.Items.Count; j++)
                    {
                        string fieldName = addFieldListBox.Items[j].ToString();
                        pFeature.set_Value(pFeature.Fields.FindField(fieldName),
                            dataRow.Cells[fieldName].Value.ToString());
                    }
                    pFeature.Store();
                }
                //添加新建的数据至Map中
                axMapControl.AddShapeFile(filePath, fileName);
                this.Hide();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 33
0
        /// <summary>
        /// Export CurrentList to .shp
        /// </summary>
        /// <param name="path">path to target shapefile</param>
        private void CurrentListAsShapefile(string path)
        {
            if (CurrentList.Count == 0)
            {
                throw new Exception("Current list is empty.");
            }

            // Create fields
            List <Field> fields = new List <Field>();
            List <KeyValuePair <string, string> > properties = CurrentList[0].GetPropertyList();
            int additionalFieldColumnIndexShapefile          = 0;

            for (int column = 1; column <= properties.Count; column++) //
            {
                string name = properties[column - 1].Key;
                int    length;
                if (name == "additional")
                {
                    additionalFieldColumnIndexShapefile = column + 1;
                    length = 16;
                }
                else
                {
                    length = 100;
                }
                fields.Add(GeoHelper.CreateField(name, name == "additional" ? esriFieldType.esriFieldTypeDouble : esriFieldType.esriFieldTypeString, length));
            }

            // Create spatial reference
            ISpatialReferenceFactory    srFactory            = new SpatialReferenceEnvironment();
            SpatialReferenceEnvironment pSpatialReferenceEnv = default(SpatialReferenceEnvironment);
            ISpatialReference2          pSpatialReference    = default(ISpatialReference2);
            //IGeographicCoordinateSystem cs = srFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);

            // Add data
            string filePath = "";
            string fileName = "";

            FileUtil.ExtractFileNameFromFullPath(path, ref filePath, ref fileName);
            GeoHelper.CreateShpFile(filePath, fileName, fields.ToArray(), pSpatialReference, (featureClass) =>
            {
                for (int i = 0; i < CurrentList.Count; i++)
                {
                    POI poi = CurrentList[i];

                    List <KeyValuePair <string, string> > _properties = poi.GetPropertyList();

                    IPoint point = new ESRI.ArcGIS.Geometry.Point();
                    point.X      = poi._lon ?? 0;
                    point.Y      = poi._lat ?? 0;

                    IFeature feature = featureClass.CreateFeature();
                    feature.Shape    = point;

                    // Attributes table record column index starts at 2
                    for (int column = 2; column <= _properties.Count + 1; column++) //
                    {
                        string value = _properties[column - 2].Value;
                        if (additionalFieldColumnIndexShapefile == column)
                        {
                            if (value == null)
                            {
                                value = "0";
                            }
                            feature.set_Value(column, double.Parse(value));
                        }
                        else
                        {
                            feature.set_Value(column, value);
                        }
                    }

                    feature.Store();
                }

                return(true);
            });
        }
Ejemplo n.º 34
0
        public IElement CreateElement(IActiveView pAV, IPoint pt)
        {
            IElement element;
            double   num   = 0;
            int      count = this.m_symbolLists.Count / this.m_colum;

            if (count * this.m_colum < this.m_symbolLists.Count)
            {
                count++;
            }
            int           num1              = 0;
            double        num2              = 0;
            double        height            = 0;
            double        y                 = pt.Y + 0.1;
            IGroupElement groupElementClass = new GroupElement() as IGroupElement;
            IEnvelope     envelopeClass     = new Envelope() as IEnvelope;

            envelopeClass.PutCoords(pt.X + 0.1, pt.Y + 0.1, pt.X + 0.1, pt.Y + 0.1);
            IRgbColor rgbColorClass = new RgbColor()
            {
                Red   = 255,
                Blue  = 255,
                Green = 255
            };
            IElement element1 = this.CreatePolygonElement(envelopeClass, rgbColorClass);

            groupElementClass.AddElement(element1);
            pt.X = pt.X + 0.1;
            pt.Y = pt.Y + 0.1;
            IElement element2 = null;

            if (this.m_Title.Length > 0)
            {
                element2 = this.CreateTitleElement(pt);
                IEnvelope envelope = new Envelope() as IEnvelope;
                element2.QueryBounds(pAV.ScreenDisplay, envelope);
                height = envelope.Height;
                groupElementClass.AddElement(element2);
            }
            double        x              = pt.X;
            double        mItemheight    = pt.Y - height - this.m_rowspace;
            IPoint        pointClass     = new ESRI.ArcGIS.Geometry.Point();
            IEnvelope     envelopeClass1 = new Envelope() as IEnvelope;
            List <double> nums           = new List <double>();
            List <double> nums1          = new List <double>();

            if (height > 0)
            {
                nums.Add(mItemheight + this.m_rowspace / 2);
            }
            bool flag = false;

            for (int i = 0; i < this.m_symbolLists.Count; i++)
            {
                ISymbol item = this.m_symbolLists[i];
                pointClass.PutCoords(x, mItemheight);
                element = this.CreateElement(pointClass, this.m_symbolLists[i], this.m_backsymbolLists[i] as IFillSymbol,
                                             this.m_symbolDescriptions[i]);
                element.QueryBounds(pAV.ScreenDisplay, envelopeClass1);
                if (!(element is IGroupElement))
                {
                    groupElementClass.AddElement(element);
                }
                else
                {
                    int elementCount = (element as IGroupElement).ElementCount;
                    for (int j = 0; j < (element as IGroupElement).ElementCount; j++)
                    {
                        groupElementClass.AddElement((element as IGroupElement).Element[j]);
                    }
                }
                num2        = (num2 > envelopeClass1.Width ? num2 : envelopeClass1.Width);
                mItemheight = mItemheight - this.m_itemheight - this.m_rowspace;
                num1++;
                if (num1 == count)
                {
                    mItemheight = pt.Y - height - this.m_rowspace;
                    nums1.Add(x + this.m_itemwidth + this.m_space / 2);
                    x = x + (num2 + this.m_colspace);
                    nums1.Add(x - this.m_colspace / 2);
                    num1 = 0;
                    num2 = 0;
                    flag = true;
                }
                else if (!flag)
                {
                    nums.Add(mItemheight + this.m_rowspace / 2);
                }
            }
            if (num1 != count)
            {
                mItemheight = pt.Y - height - this.m_rowspace;
                nums1.Add(x + this.m_itemwidth + this.m_space / 2);
                x = x + (num2 + this.m_colspace);
                nums1.Add(x - this.m_colspace / 2);
            }
            IEnvelope envelope1 = new Envelope() as IEnvelope;

            (groupElementClass as IElement).QueryBounds(pAV.ScreenDisplay, envelope1);
            (groupElementClass as IElement).Activate(pAV.ScreenDisplay);
            envelope1.Expand(0.05, 0.05, false);
            try
            {
                if (!this.m_HasBorder)
                {
                    groupElementClass.DeleteElement(element1);
                }
                else
                {
                    IRgbColor rgbColorClass1 = new RgbColor()
                    {
                        Red   = 255,
                        Blue  = 255,
                        Green = 255
                    };
                    (groupElementClass as IGroupElement3).ReplaceElement(element1,
                                                                         this.CreatePolygonElement(envelope1, rgbColorClass1));
                }
                (groupElementClass as IElement).QueryBounds(pAV.ScreenDisplay, envelope1);
                if (this.m_isdrawline)
                {
                    foreach (double num3 in nums)
                    {
                        element = this.CreateLineElement(envelope1.XMin, num3, envelope1.XMax, num3);
                        groupElementClass.AddElement(element);
                    }
                    double yMax = envelope1.YMax;
                    if (nums.Count > 0)
                    {
                        if (height > 0)
                        {
                            yMax = nums[0];
                        }
                    }
                    if (nums1.Count > 0)
                    {
                        nums1.RemoveAt(nums1.Count - 1);
                    }
                    foreach (double num3 in nums1)
                    {
                        element = this.CreateLineElement(num3, envelope1.YMin, num3, yMax);
                        groupElementClass.AddElement(element);
                    }
                    (groupElementClass as IElement).QueryBounds(pAV.ScreenDisplay, envelope1);
                }
                this.m_pEnvelop = envelope1;
            }
            catch (Exception exception)
            {
            }
            if (element2 != null)
            {
                IPoint point = new ESRI.ArcGIS.Geometry.Point();
                point.PutCoords((envelope1.XMin + envelope1.XMax) / 2, y);
                element2.Geometry = point;
                (element2 as ITextElement).Symbol = this.FontStyle(20, esriTextHorizontalAlignment.esriTHACenter,
                                                                   esriTextVerticalAlignment.esriTVATop);
            }
            (groupElementClass as IElementProperties).Name = "图例";
            (groupElementClass as IElement).Geometry       = envelope1;
            return(groupElementClass as IElement);
        }
Ejemplo n.º 35
0
        public bool HandleCommand(string string_1)
        {
            bool flag;

            if (!this.bool_0)
            {
                try
                {
                    string_1 = string_1.Trim();
                    if (string_1.Length != 0)
                    {
                        string[] strArrays  = string_1.Split(new char[] { ',' });
                        double   num        = 0;
                        double   num1       = 0;
                        IPoint   pointClass = new ESRI.ArcGIS.Geometry.Point();
                        if ((int)strArrays.Length < 2)
                        {
                            this._appContext.ShowCommandString("输入不正确", CommandTipsType.CTTLog);
                            flag = true;
                            return(flag);
                        }
                        else
                        {
                            num = Convert.ToDouble(strArrays[0]);
                            pointClass.PutCoords(num, Convert.ToDouble(strArrays[1]));
                            if ((int)strArrays.Length == 3)
                            {
                                num1         = Convert.ToDouble(strArrays[2]);
                                pointClass.Z = num1;
                            }
                            this.int_0  = 1;
                            this.bool_0 = true;
                            if (SketchShareEx.LastPoint != null)
                            {
                                int    pointCount = SketchToolAssist.m_pPointColn.PointCount;
                                IPoint point      = SketchToolAssist.m_pPointColn.Point[pointCount - 2];
                                IPoint point1     = SketchToolAssist.m_pPointColn.Point[pointCount - 1];
                                IPoint gD         = CommonHelper.GetGD(point, point1, pointClass);
                                gD.Z = num1;
                                SketchShareEx.SketchMouseDown(gD, this._appContext.MapControl.Map as IActiveView,
                                                              Editor.CurrentEditTemplate.FeatureLayer);
                            }
                            SketchShareEx.SketchMouseDown(pointClass, this._appContext.MapControl.Map as IActiveView,
                                                          Editor.CurrentEditTemplate.FeatureLayer);
                        }
                    }
                    else
                    {
                        flag = false;
                        return(flag);
                    }
                }
                catch
                {
                    this._appContext.ShowCommandString("输入不正确", CommandTipsType.CTTLog);
                    flag = true;
                    return(flag);
                }
                if (this.icommandFlow_0 == null)
                {
                    this.ShowCommandLine();
                }
                else
                {
                    this.icommandFlow_0.ShowCommandLine();
                }
                flag = true;
            }
            else
            {
                flag = false;
            }
            return(flag);
        }
Ejemplo n.º 36
0
        public static string GetXMQMC(AxMapControl _mapControl, IMapControlEvents2_OnMouseDownEvent e)
        {
            string xzqmc = "";
            try
            {

                if (_mapControl.Map.LayerCount == 0)
                {
                    return xzqmc;
                }
                IIdentify pIdentify = _mapControl.Map.get_Layer(0) as IIdentify; //通过图层获取 IIdentify 实例
                IPoint pPoint = new ESRI.ArcGIS.Geometry.Point(); //新建点来选择
                IArray pIDArray;
                IIdentifyObj pIdObj;
                pPoint.PutCoords(e.mapX, e.mapY);      //定义点
                int delta = 500;
                IEnvelope envelope = new EnvelopeClass();
                envelope.XMin = e.mapX - delta;
                envelope.XMax = e.mapX + delta;
                envelope.YMin = e.mapY - delta;
                envelope.YMax = e.mapY + delta;
                IGeometry geo = envelope as IGeometry;
                IZAware zAware = geo as IZAware;
                zAware.ZAware = true;

                pIDArray = pIdentify.Identify(geo);       //通过点获取数组,用点一般只能选择一个元素
                if (pIDArray != null)
                {
                    //取得要素
                    pIdObj = pIDArray.get_Element(0) as IIdentifyObj;       //取得要素
                    pIdObj.Flash(_mapControl.ActiveView.ScreenDisplay);     //闪烁效果
                    IRowIdentifyObject rowIdentify = pIdObj as IRowIdentifyObject;
                    IFeature feature = rowIdentify.Row as IFeature;
                    if (feature != null)
                    {
                        IFields fields = feature.Fields;
                        int xmqmcFieldIndex = fields.FindField("XZQMC");
                        xzqmc = Convert.ToString(feature.get_Value(xmqmcFieldIndex));
                    }
                }
                else
                {
                    //MessageBox.Show("Nothing!");
                }
            }
            catch
            {
            }
            return xzqmc;
        }
Ejemplo n.º 37
0
        protected void DrawSymbol(int int_0, Rectangle rectangle_0, object object_1)
        {
            IDisplayTransformation displayTransformation = new DisplayTransformation() as IDisplayTransformation;
            IEnvelope envelope = new Envelope() as ESRI.ArcGIS.Geometry.IEnvelope;

            envelope.PutCoords((double)rectangle_0.Left, (double)rectangle_0.Top, (double)rectangle_0.Right,
                               (double)rectangle_0.Bottom);
            tagRECT tagRECT;

            tagRECT.left   = rectangle_0.Left;
            tagRECT.right  = rectangle_0.Right;
            tagRECT.bottom = rectangle_0.Bottom;
            tagRECT.top    = rectangle_0.Top;
            displayTransformation.set_DeviceFrame(ref tagRECT);
            displayTransformation.Bounds = envelope;
            if (this.double_0 < 1.0 && object_1 is ILineSymbol)
            {
                displayTransformation.Resolution = 48.0 / this.double_0;
            }
            else
            {
                displayTransformation.Resolution = 96.0;
            }
            displayTransformation.ReferenceScale = 1.0;
            displayTransformation.ScaleRatio     = this.double_0;
            if (object_1 is IMarkerSymbol)
            {
                IStyleGalleryClass styleGalleryClass = new MarkerSymbolStyleGalleryClass();
                tagRECT            tagRECT2          = default(tagRECT);
                tagRECT2.left   = rectangle_0.Left;
                tagRECT2.right  = rectangle_0.Right;
                tagRECT2.top    = rectangle_0.Top;
                tagRECT2.bottom = rectangle_0.Bottom;
                styleGalleryClass.Preview(object_1, int_0, ref tagRECT2);
            }
            else if (object_1 is ILineSymbol)
            {
                IStyleGalleryClass styleGalleryClass = new LineSymbolStyleGalleryClass();
                tagRECT            tagRECT2          = default(tagRECT);
                tagRECT2.left   = rectangle_0.Left;
                tagRECT2.right  = rectangle_0.Right;
                tagRECT2.top    = rectangle_0.Top;
                tagRECT2.bottom = rectangle_0.Bottom;
                styleGalleryClass.Preview(object_1, int_0, ref tagRECT2);
            }
            else if (object_1 is IFillSymbol)
            {
                IStyleGalleryClass styleGalleryClass = new FillSymbolStyleGalleryClass();
                tagRECT            tagRECT2          = default(tagRECT);
                tagRECT2.left   = rectangle_0.Left;
                tagRECT2.right  = rectangle_0.Right;
                tagRECT2.top    = rectangle_0.Top;
                tagRECT2.bottom = rectangle_0.Bottom;
                styleGalleryClass.Preview(object_1, int_0, ref tagRECT2);
            }
            else
            {
                ISymbol symbol;
                if (object_1 is IColorRamp)
                {
                    IGradientFillSymbol gradientFillSymbol = new GradientFillSymbol();
                    ILineSymbol         outline            = gradientFillSymbol.Outline;
                    outline.Width = 0.0;
                    gradientFillSymbol.Outline            = outline;
                    gradientFillSymbol.ColorRamp          = (IColorRamp)object_1;
                    gradientFillSymbol.GradientAngle      = 180.0;
                    gradientFillSymbol.GradientPercentage = 1.0;
                    gradientFillSymbol.IntervalCount      = 100;
                    gradientFillSymbol.Style = esriGradientFillStyle.esriGFSLinear;
                    symbol = (ISymbol)gradientFillSymbol;
                }
                else if (object_1 is IColor)
                {
                    symbol = (ISymbol) new ColorSymbol
                    {
                        Color = (IColor)object_1
                    };
                }
                else if (object_1 is IAreaPatch)
                {
                    symbol = new SimpleFillSymbol() as ISymbol;
                    IRgbColor rgbColor = new RgbColor();
                    rgbColor.Red   = 227;
                    rgbColor.Green = 236;
                    rgbColor.Blue  = 19;
                    ((IFillSymbol)symbol).Color = rgbColor;
                }
                else if (object_1 is ILinePatch)
                {
                    symbol = new SimpleLineSymbol() as ISymbol;
                }
                else
                {
                    if (object_1 is INorthArrow)
                    {
                        IStyleGalleryClass styleGalleryClass = new NorthArrowStyleGalleryClass();
                        tagRECT            tagRECT2          = default(tagRECT);
                        tagRECT2.left   = rectangle_0.Left;
                        tagRECT2.right  = rectangle_0.Right;
                        tagRECT2.top    = rectangle_0.Top;
                        tagRECT2.bottom = rectangle_0.Bottom;
                        styleGalleryClass.Preview(object_1, int_0, ref tagRECT2);
                        return;
                    }
                    if (object_1 is ILegendItem)
                    {
                        IStyleGalleryClass styleGalleryClass = new LegendItemStyleGalleryClass();
                        tagRECT            tagRECT2          = default(tagRECT);
                        tagRECT2.left   = rectangle_0.Left;
                        tagRECT2.right  = rectangle_0.Right;
                        tagRECT2.top    = rectangle_0.Top;
                        tagRECT2.bottom = rectangle_0.Bottom;
                        styleGalleryClass.Preview(object_1, int_0, ref tagRECT2);
                        return;
                    }
                    if (object_1 is ILabelStyle)
                    {
                        IStyleGalleryClass styleGalleryClass = new LabelStyleGalleryClass();
                        tagRECT            tagRECT2          = default(tagRECT);
                        tagRECT2.left   = rectangle_0.Left;
                        tagRECT2.right  = rectangle_0.Right;
                        tagRECT2.top    = rectangle_0.Top;
                        tagRECT2.bottom = rectangle_0.Bottom;
                        styleGalleryClass.Preview(object_1, int_0, ref tagRECT2);
                        return;
                    }
                    if (object_1 is IMapSurround)
                    {
                        MapSurroundDraw mapSurroundDraw = new MapSurroundDraw(object_1 as IMapSurround);
                        mapSurroundDraw.Draw(int_0, rectangle_0, 96.0, this.double_0);
                        return;
                    }
                    if (object_1 is IBackground)
                    {
                        IDisplay display = new ScreenDisplay();
                        display.StartDrawing(int_0, 0);
                        display.DisplayTransformation = displayTransformation;
                        IGeometry geometry = ((IBackground)object_1).GetGeometry(display, envelope);
                        ((IBackground)object_1).Draw(display, geometry);
                        display.FinishDrawing();
                        return;
                    }
                    if (object_1 is IShadow)
                    {
                        ShadowDraw shadowDraw = new ShadowDraw(object_1 as IShadow);
                        shadowDraw.Draw(int_0, rectangle_0, 96.0, this.double_0);
                        return;
                    }
                    if (object_1 is IRepresentationMarker)
                    {
                        RepresentationMarkerDraw representationMarkerDraw =
                            new RepresentationMarkerDraw(object_1 as IRepresentationMarker);
                        representationMarkerDraw.Draw(int_0, rectangle_0, 96.0, this.double_0);
                        return;
                    }
                    if (object_1 is IRepresentationRuleItem)
                    {
                        try
                        {
                            RepresentationRuleDraw representationRuleDraw = new RepresentationRuleDraw(object_1);
                            IRepresentationRule    representationRule     =
                                (object_1 as IRepresentationRuleItem).RepresentationRule;
                            IBasicSymbol arg_61E_0 = representationRule.get_Layer(0);
                            representationRuleDraw.Draw(int_0, rectangle_0, 96.0, this.double_0);
                            return;
                        }
                        catch
                        {
                            return;
                        }
                    }
                    if (object_1 is IBorder)
                    {
                        IDisplay display = new ScreenDisplay();
                        display.StartDrawing(int_0, 0);
                        display.DisplayTransformation = displayTransformation;
                        IPointCollection pointCollection = new Polyline();
                        object           value           = System.Reflection.Missing.Value;
                        IPoint           point           = new ESRI.ArcGIS.Geometry.Point();
                        point.PutCoords((double)(rectangle_0.X + 4), (double)rectangle_0.Top);
                        pointCollection.AddPoint(point, ref value, ref value);
                        point.PutCoords((double)(rectangle_0.X + 4), (double)rectangle_0.Bottom);
                        pointCollection.AddPoint(point, ref value, ref value);
                        point.PutCoords((double)(rectangle_0.Right - 4), (double)rectangle_0.Bottom);
                        pointCollection.AddPoint(point, ref value, ref value);
                        IGeometry geometry = ((IBorder)object_1).GetGeometry(display, (IGeometry)pointCollection);
                        ((IBorder)object_1).Draw(display, geometry);
                        display.FinishDrawing();
                        return;
                    }
                    if (object_1 is IMapGrid)
                    {
                        IDisplay display = new ScreenDisplay();
                        display.StartDrawing(int_0, 0);
                        display.DisplayTransformation = displayTransformation;
                        IPointCollection pointCollection = new Polyline();
                        object           value           = System.Reflection.Missing.Value;
                        IPoint           point           = new ESRI.ArcGIS.Geometry.Point();
                        point.PutCoords((double)(rectangle_0.X + 4), (double)rectangle_0.Top);
                        pointCollection.AddPoint(point, ref value, ref value);
                        point.PutCoords((double)(rectangle_0.X + 4), (double)rectangle_0.Bottom);
                        pointCollection.AddPoint(point, ref value, ref value);
                        point.PutCoords((double)(rectangle_0.Right - 4), (double)rectangle_0.Bottom);
                        pointCollection.AddPoint(point, ref value, ref value);
                        IMapFrame mapFrame = new MapFrame() as IMapFrame;
                        IMap      map      = new Map();
                        mapFrame.Map = map;
                        (map as IActiveView).Extent = (pointCollection as IGeometry).Envelope;
                        (object_1 as IMapGrid).Draw(display, mapFrame);
                        display.FinishDrawing();
                        return;
                    }
                    return;
                }
                if (symbol is IPictureFillSymbol || symbol is IPictureLineSymbol)
                {
                    symbol.SetupDC(int_0, displayTransformation);
                }
                else
                {
                    symbol.SetupDC(int_0, displayTransformation);
                }
                if (symbol is IMarkerSymbol)
                {
                    this.method_0((IMarkerSymbol)symbol, rectangle_0);
                }
                else if (symbol is ILineSymbol)
                {
                    this.method_1((ILineSymbol)symbol, rectangle_0);
                }
                else if (symbol is IFillSymbol)
                {
                    this.method_2((IFillSymbol)symbol, rectangle_0);
                }
                else if (symbol is ITextSymbol)
                {
                    this.method_3((ITextSymbol)symbol, rectangle_0);
                }
                symbol.ResetDC();
            }
        }
Ejemplo n.º 38
0
        public IElement addTitleToLayout(IMxDocument pMxDoc,double S, double x, double y,  IGraphicsContainer pGc, bool b, string texto)
        {
            ITextElement pTxtElem;
            ITextSymbol pTxtSym = default(ITextSymbol);
            IRgbColor myColor = default(IRgbColor);
            stdole.IFontDisp myFont;
            IElement pElem;
            IEnvelope pEnv;
            IPoint pPoint = default(IPoint);
            try{
                // pGc.Reset()
                //Set the font and color properties
                //for the title
                myFont = (stdole.IFontDisp)new stdole.StdFont();
                myFont.Name = "Times New Roman";
                myFont.Bold = b;
               // myFont.Size = S;
                myColor = new RgbColor();
                myColor.Red = 0;
                myColor.Green = 0;
                myColor.Blue = 0;
                ///''''''''''''''''''''''''''''''
                //Create a text element
                pTxtElem = (ITextElement)new TextElement();

                //Create a text symbol
                pTxtSym = new TextSymbol();
                pTxtSym.Color = myColor;
                pTxtSym.Font = myFont;
                pTxtSym.Size = S;
                //Set symbol property
                pTxtElem.Symbol = pTxtSym;

                //set the text property to be the layer's name (Uppercase)
                pTxtElem.Text = texto;

                //Create an envelope for the TextElements Geometry
                pEnv = (IEnvelope)new Envelope();
                pPoint = new ESRI.ArcGIS.Geometry.Point();

                pPoint.X = x;
                pPoint.Y = y;
                pEnv.LowerLeft = pPoint;
                pPoint.X = 1;
                pPoint.Y = 1;
                pEnv.UpperRight = pPoint;
                //set the text elements geomtery
                pElem = (IElement)pTxtElem;
                pElem.Geometry = pEnv;

                //Add the element to the graphics container
                pGc.AddElement(pElem, 1);
                pMxDoc.ActiveView.Refresh();
                return (pElem);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message, "clsMapTools.addTitleToLayout");
                MessageBox.Show("Error: " + ex.StackTrace);
                return null ;
            }
        }
Ejemplo n.º 39
0
        private void method_1(ILineSymbol ilineSymbol_0, Rectangle rectangle_0)
        {
            if (ilineSymbol_0 is IPictureLineSymbol)
            {
                if (((IPictureLineSymbol)ilineSymbol_0).Picture == null)
                {
                    return;
                }
            }
            else if (ilineSymbol_0 is IMarkerLineSymbol || ilineSymbol_0 is IHashLineSymbol)
            {
                ITemplate template = ((ILineProperties)ilineSymbol_0).Template;
                if (template != null)
                {
                    bool flag = false;
                    int  i    = 0;
                    while (i < template.PatternElementCount)
                    {
                        double num;
                        double num2;
                        template.GetPatternElement(i, out num, out num2);
                        if (num + num2 <= 0.0)
                        {
                            i++;
                        }
                        else
                        {
                            flag = true;
IL_89:
                            if (flag)
                            {
                                object           value           = System.Reflection.Missing.Value;
                                IPointCollection pointCollection = new Polyline();
                                IPoint           point           = new ESRI.ArcGIS.Geometry.Point();
                                if (this.bool_1)
                                {
                                    point.PutCoords((double)(rectangle_0.Left + 2), (double)(rectangle_0.Bottom + 2));
                                    pointCollection.AddPoint(point, ref value, ref value);
                                    point.PutCoords((double)((rectangle_0.Width - 4) / 3 + rectangle_0.Left + 2),
                                                    (double)(rectangle_0.Top - 2));
                                    pointCollection.AddPoint(point, ref value, ref value);
                                    point.PutCoords((double)((rectangle_0.Width - 4) / 3 * 2 + rectangle_0.Left + 2),
                                                    (double)(rectangle_0.Bottom + 2));
                                    pointCollection.AddPoint(point, ref value, ref value);
                                    point.PutCoords((double)(rectangle_0.Right - 2), (double)(rectangle_0.Top - 2));
                                    pointCollection.AddPoint(point, ref value, ref value);
                                }
                                else
                                {
                                    point.PutCoords((double)(rectangle_0.Left + 3),
                                                    (double)((rectangle_0.Bottom + rectangle_0.Top) / 2));
                                    pointCollection.AddPoint(point, ref value, ref value);
                                    point.PutCoords((double)(rectangle_0.Right - 3),
                                                    (double)((rectangle_0.Bottom + rectangle_0.Top) / 2));
                                    pointCollection.AddPoint(point, ref value, ref value);
                                }
                                ((ISymbol)ilineSymbol_0).Draw((IGeometry)pointCollection);
                            }
                            return;
                        }
                    }
                }
            }
        }
Ejemplo n.º 40
0
        //地图鼠标下落事件
        private void axMapControl_1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            //添加点
            if (axMapControl_1.MousePointer == esriControlsMousePointer.esriPointerCrosshair && axMapControl_1.CurrentTool == null && e.button
                == 1)
            {
                //获取图层名
                string StrBZLyrName = Cbx_LyrNameEdit.EditValue.ToString();
                //添加点坐标
                IPoint pntAdd = new ESRI.ArcGIS.Geometry.Point();
                pntAdd.X = e.mapX;
                pntAdd.Y = e.mapY;

                //获取查询图层ID
                int iLyr = 0;
                for (int i = 0; i < axMapControl_1.LayerCount; i++)
                {
                    if (axMapControl_1.get_Layer(i).Name == StrBZLyrName)
                    {
                        iLyr = i;
                        break;
                    }
                }

                //得到要添加地物的图层
                IFeatureLayer l = axMapControl_1.Map.get_Layer(iLyr) as IFeatureLayer;

                //获取要素图层的要素类对象
                IFeatureClass fc = l.FeatureClass;

                //定义一个编辑的工作空间
                IWorkspaceEdit w = (fc as IDataset).Workspace as IWorkspaceEdit;
                IFeatureBuffer f = fc.CreateFeatureBuffer();
                //定义一个插入的要素Cursor
                IFeatureCursor cur = fc.Insert(true);

                //开始事务操作
                w.StartEditing(false);
                //开始编辑
                w.StartEditOperation();

                //创建一个地物
                f.Shape = pntAdd;
                //插入地物
                cur.InsertFeature(f);

                //结束编辑
                w.StopEditOperation();
                //结束事务操作
                w.StopEditing(true);

                //刷新地图
                IActiveView pActiveView = axMapControl_1.Map as IActiveView;
                pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, axMapControl_1.Map.get_Layer(iLyr), null);
            }
            //删除点
            if (axMapControl_1.MousePointer == esriControlsMousePointer.esriPointerHotLink && axMapControl_1.CurrentTool == null && e.button == 1)
            {
                //获取预标记图层名称
                string StrBZLyrName = Cbx_LyrNameEdit.EditValue.ToString();

                //获取鼠标点击的地图坐标
                IPoint pntDel = new ESRI.ArcGIS.Geometry.Point();
                pntDel.X = e.mapX;
                pntDel.Y = e.mapY;

                //获取编辑图层索引号
                int iLyr = 0;
                for (int i = 0; i < axMapControl_1.LayerCount; i++)
                {
                    if (axMapControl_1.get_Layer(i).Name == StrBZLyrName)
                    {
                        iLyr = i;
                        break;
                    }
                }

                //获取图层FeatureLayer对象
                IFeatureLayer layer = axMapControl_1.Map.get_Layer(iLyr) as IFeatureLayer;

                //FindFeature为寻找空间要素自定义函数
                IFeature feature = FindFeature(layer, pntDel);
                if (feature != null)
                {
                    //获取预删除对象FID
                    string        fFID         = feature.get_Value(0).ToString();
                    IFeatureClass fc           = layer.FeatureClass;
                    IQueryFilter  pQueryFilter = new QueryFilterClass();
                    //查询条件为空表示删除所有点
                    pQueryFilter.WhereClause = "fid=" + fFID;
                    ITable pTable = fc as ITable;

                    IWorkspaceEdit w = (fc as IDataset).Workspace as IWorkspaceEdit;
                    //开始事务操作
                    w.StartEditing(false);
                    //开始编辑
                    w.StartEditOperation();
                    pTable.DeleteSearchedRows(pQueryFilter);
                    //结束编辑
                    w.StopEditOperation();
                    //结束事务操作
                    w.StopEditing(true);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(pQueryFilter);
                    //刷新地图
                    //IActiveView pActiveView = axMapControl_1.Map as IActiveView;
                    //  pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, axMapControl_1.Map.get_Layer(iLyr), null);
                    axMapControl_1.Refresh();
                }
            }
        }
        /// <summary>
        /// Saves the spatial and attribute data to a geodatabase.
        /// </summary>
        /// <param name="featureMemberElements">The root node of the feature element list</param>
        /// <param name="envelope"></param>
        public void SaveFeatureMembers(IEnumerable <XElement> featureMemberElements, IEnvelope envelope)
        {
            // ReSharper disable PossibleMultipleEnumeration

            if ((featureMemberElements != null) && featureMemberElements.Any())
            {
                if (FeatureClass == null)
                {
                    IMappedFeature feature = CreateMappedFeature(null);
                    XName          name    = feature.Name;

                    foreach (var featureMemberElement in featureMemberElements)
                    {
                        IEnumerable <XElement> mappedFeatureElements = featureMemberElement.Descendants(name);

                        foreach (var mappedFeatureElement in mappedFeatureElements)
                        {
                            CreateMappedFeature(mappedFeatureElement);
                        }
                    }

                    if (FeatureClass != null)
                    {
                        var featureLayer = _layer as FeatureLayer;

                        if (featureLayer != null)
                        {
                            featureLayer.FeatureClass = FeatureClass;
                        }
                    }
                }

                IMappedFeature    mapFeature          = CreateMappedFeature(null);
                var               fieldIds            = mapFeature.Fields.ToDictionary(field => FeatureClass.FindField(field.Key), field => field.Key);
                string            idField             = mapFeature.ObjectId;
                XName             objectName          = mapFeature.Name;
                IFeatureWorkspace featureWorkspace    = _cycloMediaGroupLayer.FeatureWorkspace;
                var               workspaceEdit       = featureWorkspace as IWorkspaceEdit;
                var               spatialCacheManager = featureWorkspace as ISpatialCacheManager3;

                if (workspaceEdit != null)
                {
                    var exists = new Dictionary <string, IFeature>();

                    if (FeatureClass != null)
                    {
                        ISpatialFilter spatialFilter = new SpatialFilterClass
                        {
                            Geometry      = envelope,
                            GeometryField = FeatureClass.ShapeFieldName,
                            SpatialRel    = esriSpatialRelEnum.esriSpatialRelContains,
                            SubFields     = idField
                        };

                        workspaceEdit.StartEditing(false);
                        var existsResult = FeatureClass.Search(spatialFilter, false);
                        var existsCount  = FeatureClass.FeatureCount(spatialFilter);
                        var imId         = existsResult.FindField(idField);
                        // ReSharper disable UseIndexedProperty

                        for (int i = 0; i < existsCount; i++)
                        {
                            IFeature feature  = existsResult.NextFeature();
                            var      recValue = feature.get_Value(imId) as string;

                            if ((recValue != null) && (!exists.ContainsKey(recValue)))
                            {
                                exists.Add(recValue, feature);
                            }
                        }
                    }

                    if (FeatureClass != null)
                    {
                        foreach (XElement featureMemberElement in featureMemberElements)
                        {
                            IEnumerable <XElement> mappedFeatureElements = featureMemberElement.Descendants(objectName);

                            foreach (var mappedFeatureElement in mappedFeatureElements)
                            {
                                IMappedFeature mappedFeature = CreateMappedFeature(mappedFeatureElement);

                                if (mappedFeature.Shape != null)
                                {
                                    if (mappedFeature.Shape.Type == ShapeType.Point)
                                    {
                                        if (!exists.ContainsKey((string)mappedFeature.FieldToItem(idField)))
                                        {
                                            var shapePoint = mappedFeature.Shape as ShapePoint;

                                            if ((shapePoint != null) && Filter(mappedFeature))
                                            {
                                                IPoint point = new Point();
                                                point.PutCoords(shapePoint.X, shapePoint.Y);
                                                IFeature feature = FeatureClass.CreateFeature();
                                                feature.Shape = point;

                                                foreach (var fieldId in fieldIds)
                                                {
                                                    feature.set_Value(fieldId.Key, mappedFeature.FieldToItem(fieldId.Value));
                                                }

                                                feature.Store();
                                            }
                                        }
                                        else
                                        {
                                            if (Filter(mappedFeature))
                                            {
                                                exists.Remove((string)mappedFeature.FieldToItem(idField));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    foreach (var feature in exists)
                    {
                        feature.Value.Delete();
                    }

                    workspaceEdit.StopEditing(true);

                    if ((spatialCacheManager != null) && (envelope != null))
                    {
                        spatialCacheManager.FillCache(envelope);
                    }
                    // ReSharper restore UseIndexedProperty
                }
            }

            // ReSharper restore PossibleMultipleEnumeration
        }
Ejemplo n.º 42
0
        private bool addMarkerAtAdres(string Adres)
        {
            datacontract.locationResult loc = getAdres(Adres);
            IPoint fromXY; IPoint toXY;
            IRgbColor innerClr; IRgbColor outlineClr;

            if (loc != null )
            {
                fromXY = new ESRI.ArcGIS.Geometry.Point()
                {
                    X = loc.Location.Lon_WGS84,
                    Y = loc.Location.Lat_WGS84,
                    SpatialReference = wgs
                };
                toXY = geopuntHelper.Transform(fromXY as IGeometry, map.SpatialReference) as IPoint;

                innerClr = new RgbColor() { Red = 255, Blue = 0, Green = 255 };
                outlineClr = new RgbColor() { Red = 0, Blue = 0, Green = 0 };
                geopuntHelper.AddGraphicToMap(map, toXY, innerClr, outlineClr, 12, false);
                geopuntHelper.AddTextElement(map , toXY, loc.FormattedAddress);

                infoLabel.Text = geopuntHelper.adresTypeStringTranslate(loc.LocationType);

                view.Refresh();
                return true;
            }
            return false;
        }
Ejemplo n.º 43
0
        private Image SymbolToBitmap(IGradientFillSymbol iSymbol, int iStyle, int iWidth, int iHeight)
        {
            IntPtr    iHDC      = new IntPtr();
            Bitmap    iBitmap   = new Bitmap(iWidth, iHeight);
            Graphics  iGraphics = System.Drawing.Graphics.FromImage(iBitmap);
            tagRECT   itagRECT;
            IEnvelope iEnvelope = new EnvelopeClass() as IEnvelope;
            IDisplayTransformation iDisplayTransformation;
            IPoint iPoint;
            IGeometryCollection iPolyline;
            IGeometryCollection iPolygon;
            IRing iRing;
            ISegmentCollection iSegmentCollection;
            IGeometry          iGeometry = null;
            object             Missing   = Type.Missing;

            iEnvelope.PutCoords(0, 0, iWidth, iHeight);
            itagRECT.left          = 0;
            itagRECT.right         = iWidth;
            itagRECT.top           = 0;
            itagRECT.bottom        = iHeight;
            iDisplayTransformation = new DisplayTransformationClass();
            iDisplayTransformation.VisibleBounds = iEnvelope;
            iDisplayTransformation.Bounds        = iEnvelope;
            iDisplayTransformation.set_DeviceFrame(ref itagRECT);
            iDisplayTransformation.Resolution = iGraphics.DpiX / 100000;
            iHDC = iGraphics.GetHdc();
            //获取Geometry;

            if (iSymbol is ESRI.ArcGIS.Display.IMarkerSymbol)
            {
                switch (iStyle)
                {
                case 0:
                    iPoint = new ESRI.ArcGIS.Geometry.Point();
                    iPoint.PutCoords(iWidth / 2, iHeight / 2);
                    iGeometry = iPoint;
                    break;

                default:
                    break;
                }
            }
            else
            {
                if (iSymbol is ESRI.ArcGIS.Display.ILineSymbol)
                {
                    iSegmentCollection = new ESRI.ArcGIS.Geometry.Path() as ISegmentCollection;
                    iPolyline          = new ESRI.ArcGIS.Geometry.Polyline() as IGeometryCollection;
                    switch (iStyle)
                    {
                    case 0:
                        iSegmentCollection.AddSegment(CreateLine(0, iHeight / 2, iWidth, iHeight / 2) as ISegment, ref Missing, ref Missing);

                        iPolyline.AddGeometry(iSegmentCollection as IGeometry, ref Missing, ref Missing);
                        iGeometry = iPolyline as IGeometry;
                        break;

                    case 1:
                        iSegmentCollection.AddSegment(CreateLine(0, iHeight / 4, iWidth / 4, 3 * iHeight / 4) as ISegment, ref Missing, ref Missing);
                        iSegmentCollection.AddSegment(CreateLine(iWidth / 4, 3 * iHeight / 4, 3 * iWidth / 4, iHeight / 4) as ISegment, ref Missing, ref Missing);
                        iSegmentCollection.AddSegment(CreateLine(3 * iWidth / 4, iHeight / 4, iWidth, 3 * iHeight / 4) as ISegment, ref Missing, ref Missing);
                        iPolyline.AddGeometry(iSegmentCollection as IGeometry, ref Missing, ref Missing);
                        iGeometry = iPolyline as IGeometry;
                        break;

                    default:
                        break;
                    }
                }
                else
                if (iSymbol is ESRI.ArcGIS.Display.IFillSymbol)
                {
                    iSegmentCollection = new ESRI.ArcGIS.Geometry.Ring() as ISegmentCollection;
                    iPolygon           = new ESRI.ArcGIS.Geometry.Polygon() as IGeometryCollection;
                    switch (iStyle)
                    {
                    case 0:
                        iSegmentCollection.AddSegment(CreateLine(5, iHeight - 5, iWidth - 6, iHeight - 5) as ISegment, ref Missing, ref Missing);
                        iSegmentCollection.AddSegment(CreateLine(iWidth - 6, iHeight - 5, iWidth - 6, 6) as ISegment, ref Missing, ref Missing);
                        iSegmentCollection.AddSegment(CreateLine(iWidth - 6, 6, 5, 6) as ISegment, ref Missing, ref Missing);
                        iRing = iSegmentCollection as IRing;
                        iRing.Close();
                        iPolygon.AddGeometry(iSegmentCollection as IGeometry, ref Missing, ref Missing);
                        iGeometry = iPolygon as IGeometry;
                        break;

                    default:
                        break;
                    }
                }
                else
                if (iSymbol is ESRI.ArcGIS.Display.ISimpleTextSymbol)
                {
                    switch (iStyle)
                    {
                    case 0:
                        iPoint = new ESRI.ArcGIS.Geometry.Point();
                        iPoint.PutCoords(iWidth / 2, iHeight / 2);
                        iGeometry = iPoint;
                        break;

                    default:
                        break;
                    }
                }
            }////////////////////////
            if (iGeometry == null)
            {
                MessageBox.Show("几何对象不符合!", "错误");
                return(null);
            }
            ISymbol pOutputSymbol = iSymbol as ISymbol;

            pOutputSymbol.SetupDC(iHDC.ToInt32(), iDisplayTransformation);
            pOutputSymbol.Draw(iGeometry);
            pOutputSymbol.ResetDC();
            iGraphics.ReleaseHdc(iHDC);
            iGraphics.Dispose();
            return(iBitmap);
        }
Ejemplo n.º 44
0
        private void method_0(int int_0, Rectangle rectangle_0, double double_0, double double_1)
        {
            IDisplayTransformation displayTransformation = new DisplayTransformation() as IDisplayTransformation;
            IEnvelope envelope = new Envelope() as IEnvelope;

            envelope.PutCoords((double)rectangle_0.Left, (double)rectangle_0.Top, (double)rectangle_0.Right,
                               (double)rectangle_0.Bottom);
            tagRECT tagRECT;

            tagRECT.left   = rectangle_0.Left;
            tagRECT.right  = rectangle_0.Right;
            tagRECT.bottom = rectangle_0.Bottom;
            tagRECT.top    = rectangle_0.Top;
            displayTransformation.set_DeviceFrame(ref tagRECT);
            displayTransformation.Bounds         = envelope;
            displayTransformation.Resolution     = double_0;
            displayTransformation.ReferenceScale = 1.0;
            displayTransformation.ScaleRatio     = double_1;
            ISymbol symbol = this.m_pStyle as ISymbol;

            symbol.SetupDC(int_0, displayTransformation);
            if (symbol is IPictureLineSymbol)
            {
                if (((IPictureLineSymbol)symbol).Picture == null)
                {
                    return;
                }
            }
            else if (symbol is IMarkerLineSymbol || symbol is IHashLineSymbol)
            {
                ITemplate template = ((ILineProperties)symbol).Template;
                if (template != null)
                {
                    bool flag = false;
                    int  i    = 0;
                    while (i < template.PatternElementCount)
                    {
                        double num;
                        double num2;
                        template.GetPatternElement(i, out num, out num2);
                        if (num + num2 <= 0.0)
                        {
                            i++;
                        }
                        else
                        {
                            flag = true;
IL_140:
                            if (flag)
                            {
                                object           value           = System.Reflection.Missing.Value;
                                IPointCollection pointCollection = new Polyline();
                                IPoint           point           = new ESRI.ArcGIS.Geometry.Point();
                                if (this.bool_0)
                                {
                                    point.PutCoords((double)(rectangle_0.Left + 2), (double)(rectangle_0.Bottom + 2));
                                    pointCollection.AddPoint(point, ref value, ref value);
                                    point.PutCoords((double)((rectangle_0.Width - 4) / 3 + rectangle_0.Left + 2),
                                                    (double)(rectangle_0.Top - 2));
                                    pointCollection.AddPoint(point, ref value, ref value);
                                    point.PutCoords((double)((rectangle_0.Width - 4) / 3 * 2 + rectangle_0.Left + 2),
                                                    (double)(rectangle_0.Bottom + 2));
                                    pointCollection.AddPoint(point, ref value, ref value);
                                    point.PutCoords((double)(rectangle_0.Right - 2), (double)(rectangle_0.Top - 2));
                                    pointCollection.AddPoint(point, ref value, ref value);
                                }
                                else
                                {
                                    point.PutCoords((double)(rectangle_0.Left + 3),
                                                    (double)((rectangle_0.Bottom + rectangle_0.Top) / 2));
                                    pointCollection.AddPoint(point, ref value, ref value);
                                    point.PutCoords((double)(rectangle_0.Right - 3),
                                                    (double)((rectangle_0.Bottom + rectangle_0.Top) / 2));
                                    pointCollection.AddPoint(point, ref value, ref value);
                                }
                                symbol.Draw((IGeometry)pointCollection);
                                symbol.ResetDC();
                            }
                            return;
                        }
                    }
                    ;
                }
            }
        }
Ejemplo n.º 45
0
        private void KalibreerVormpuntenOpBasisVanSpoorhartlijn(IFeatureSelection FeatureSelectionMShape)
        {
            #region Bepaal de overlappende extent van raaien en selectie
            IGeoDataset GeoDatasetMShape = flMShape as IGeoDataset;
            IGeoDataset GeodatasetLRS = fcLRS as IGeoDataset;

            IEnvelope pQueryingGeometryFullExtent = GeoDatasetMShape.Extent;
            pQueryingGeometryFullExtent.Union(GeodatasetLRS.Extent);
            pQueryingGeometryFullExtent.Expand(10000, 10000, false);
            #endregion Bepaal de overlappende extent van raaien en selectie

            int featurecount = FeatureSelectionMShape.SelectionSet.Count;
            int featurecounter = 0;

            ICursor SelectionCursor = null;

            if (featurecount == 0)
            {
                SelectionCursor = ((FeatureSelectionMShape as IFeatureLayer).FeatureClass.Search(null, false)) as ICursor;
                featurecount = (FeatureSelectionMShape as IFeatureLayer).FeatureClass.FeatureCount(null);
            }
            else
            {
                FeatureSelectionMShape.SelectionSet.Search(null, false, out SelectionCursor);
            }

            IPolyline Polyline = null;
            IPolygon buffer = null;
            IPointCollection PointCollection = null;

            IList<IPolyline> PolylinesLRS = null;

            try
            {

                IFeature feature = SelectionCursor.NextRow() as IFeature;
                while (feature != null)
                {

                    Polyline = feature.ShapeCopy as IPolyline;
                    PointCollection = Polyline as IPointCollection;

                    #region lees de begin- en eindkilometrering en het selectie criterium
                    double m_begin = (Polyline as IPointCollection).get_Point(0).M;
                    double m_eind = (Polyline as IPointCollection).get_Point((Polyline as IPointCollection).PointCount - 1).M;
                    string sleutel1 = Convert.ToString(feature.get_Value(feature.Fields.FindField(this.mshape_sleutel1)));
                    string sleutel2 = null;
                    if (this.mshape_sleutel2 != "")
                    {
                        sleutel2 = Convert.ToString(feature.get_Value(feature.Fields.FindField(this.mshape_sleutel2)));
                    }

                    #endregion

                    // Selecteer alle LRS lijnen binnen de zoekafstand
                    ISpatialFilter SpatialFilter = new SpatialFilter();
                    IQueryFilter QueryFilter = SpatialFilter;

                    buffer = (Polyline as ITopologicalOperator).Buffer(Properties.Settings.Default.mshape_maxafstand) as IPolygon;

                    SpatialFilter.Geometry = buffer;
                    SpatialFilter.GeometryField = fcLRS.ShapeFieldName;
                    string whereclauseLRS = Properties.Settings.Default.lrs_selectie;
                    SpatialFilter.WhereClause = string.Format(whereclauseLRS, sleutel1, sleutel2);
                    SpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelEnvelopeIntersects;

                    ESRI.ArcGIS.Geodatabase.IFeatureCursor featureCursor = fcLRS.Search(QueryFilter, false);

                    try
                    {
                        PolylinesLRS = new List<IPolyline>();
                        IFeature featureLRS = featureCursor.NextFeature();
                        while (featureLRS != null)
                        {
                            PolylinesLRS.Add(featureLRS.ShapeCopy as IPolyline);
                            featureLRS = featureCursor.NextFeature();
                        }

                    }
                    catch
                    {
                        throw;
                    }
                    finally
                    {
                        ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(featureCursor);
                    }

                    // Controleer of er een spoorhartlijn (LRS) in de buurt ligt. Zo niet, dan evt. markeren
                    if ((PolylinesLRS.Count == 0) && (this.MarkeerLijnBuitenZoekAfstand))
                    {
                        _ArcObjectsHelper.AddGraphicToMap(ArcMap.Document.FocusMap, Polyline, this.KleurLijnBuitenZoekAfstand, this.KleurLijnBuitenZoekAfstand);
                        // Als er geen spoorhartlijn (LRS) in de buurt ligt, dan hoeven ook niet alle vormpunten doorlopen te worden.
                        continue; // while (feature != null)
                    }

                    #region Doorloop alle vormpunten en werk de vormpunten bij
                    bool bUpdated = false;
                    bool bNietMonotoon = false;
                    bool outPointGevonden = false;
                    double pDistance = 0;

                    for (int i = 1; i < PointCollection.PointCount-1; i++) // sla het eerste en het laatste punt over
                    {
                        // zoek de dichtstbijzijnde feature, eventueel aangevuld met geocode in een queryfilter
                        IPoint Point = PointCollection.get_Point(i);
                        IPoint outPoint = new ESRI.ArcGIS.Geometry.Point();
                        outPointGevonden = false;
                        pDistance = double.PositiveInfinity;
                        bUpdated = false;

                        this.ZoekPuntOpSpoorhartlijn(Point, PolylinesLRS, m_begin, m_eind, out outPoint, out outPointGevonden, out pDistance);
                        if (this.LogVormpunten)
                        {
                            if (outPointGevonden)
                            { this._ArcObjectsHelper.LogRecord(logtable, feature.OID, i, Point.X, Point.Y, Point.M, outPoint.X, outPoint.Y, outPoint.M); }
                            else
                            { this._ArcObjectsHelper.LogRecord(logtable, feature.OID, i, Point.X, Point.Y, Point.M, Point.X, Point.Y, Point.M); }
                        }

                        // Als er een punt gevonden is, binnen de zoekafstand en binnen het kilometerinterval
                        if (outPointGevonden)
                        {
                            if (Math.Abs((Point as IPoint).M - outPoint.M) > (this.VerschilVormpuntMetAfwijking / 1000))
                            {
                                if (MarkeerVormpuntMetAfwijking)
                                { _ArcObjectsHelper.AddGraphicToMap(ArcMap.Document.FocusMap, Point, this.KleurVormpuntMetAfwijking, this.KleurVormpuntMetAfwijking); }
                            }

                            if ((pDistance > this.AfstandVormpuntBuitenZoekAfstand) && (this.MarkeerVormpuntBuitenZoekAfstand))
                            { _ArcObjectsHelper.AddGraphicToMap(ArcMap.Document.FocusMap, Point, this.KleurVormpuntBuitenZoekAfstand, this.KleurVormpuntBuitenZoekAfstand); }

                            Point.M = outPoint.M;

                            PointCollection.UpdatePoint(i, Point);
                            bUpdated = true;
                        }
                        else if ((!outPointGevonden) && (outPoint != null)) // er is wel een punt gevonden, maar niet binnen het kilometerinterval.
                        {
                            // Als er een punt buiten het kilometerinterval gevonden is, binnen de zoekafstand, markeer het punt dan
                            if ((this.MarkeerVormpuntMetAfwijking) && (Math.Abs((Point as IPoint).M - outPoint.M) > (this.VerschilVormpuntMetAfwijking / 1000)))
                            { _ArcObjectsHelper.AddGraphicToMap(ArcMap.Document.FocusMap, Point, this.KleurVormpuntMetAfwijking, this.KleurVormpuntMetAfwijking); }

                            if ((this.MarkeerVormpuntBuitenInterval) && !(between(m_begin, m_eind, outPoint.M, (TolerantieVormpuntBuitenInterval / 1000))))
                            { _ArcObjectsHelper.AddGraphicToMap(ArcMap.Document.FocusMap, Point, this.KleurVormpuntBuitenInterval, this.KleurVormpuntBuitenInterval); }

                            if ((pDistance > this.AfstandVormpuntBuitenZoekAfstand) && (this.MarkeerVormpuntBuitenZoekAfstand))
                            { _ArcObjectsHelper.AddGraphicToMap(ArcMap.Document.FocusMap, Point, this.KleurVormpuntBuitenZoekAfstand, this.KleurVormpuntBuitenZoekAfstand); }

                        }
                        else if (!outPointGevonden) // er is geen punt gevonden binnen de zoekafstand
                        {
                            if (this.MarkeerVormpuntBuitenZoekAfstand)
                            { _ArcObjectsHelper.AddGraphicToMap(ArcMap.Document.FocusMap, Point, this.KleurVormpuntBuitenZoekAfstand, this.KleurVormpuntBuitenZoekAfstand); }
                        }

                        #region Markeer de bijgewerkte en niet bijgewerkte punten
                        if ((bUpdated) && (this.MarkeerVormpuntBijgewerkt))
                        {
                            _ArcObjectsHelper.AddGraphicToMap(ArcMap.Document.FocusMap, Point, this.KleurVormpuntBijgewerkt, this.KleurVormpuntBijgewerkt);
                        }
                        if (!(bUpdated) && (this.MarkeerVormpuntNietBijgewerkt))
                        {
                            _ArcObjectsHelper.AddGraphicToMap(ArcMap.Document.FocusMap, Point, this.KleurVormpuntNietBijgewerkt, this.KleurVormpuntNietBijgewerkt);
                        }
                        #endregion

                    }
                    #endregion // doorloop de vormpunten

                    #region Reset begin- en eindkilometer
                    this.ResetBeginEnEindMeasure(Polyline, m_begin, m_eind, false);
                    #endregion

                    #region Controleer of de lijn monotoon oplopend of aflopend is en markeer de lijn.
                    int MMonotonicity = ((PointCollection as IMSegmentation3).MMonotonicity);
                    if (MMonotonicity == 5 || MMonotonicity == 7 || MMonotonicity == 15)
                    {
                        bNietMonotoon = true;
                        if (this.MarkeerLijnNietMonotoon)
                        {
                            _ArcObjectsHelper.AddGraphicToMap(ArcMap.Document.FocusMap, PointCollection as IPolyline, this.KleurLijnNietMonotoon, this.KleurLijnNietMonotoon);
                        }
                    }

                    if ((bNietMonotoon) && (this.OpslaanLijnNietMonotoon))
                    {
                        feature.Shape = (PointCollection as IGeometry);
                        // UpdateCursor.UpdateFeature(feature);
                    }
                    else if (!bNietMonotoon)
                    {
                        feature.Shape = (PointCollection as IGeometry);
                    }
                    #endregion

                    // Voortgang
                    featurecounter += 1;
                    this.progress = (100 * featurecounter) / featurecount;

                    // Bijwerken
                    feature.Store();

                    // Volgende feature
                    feature = SelectionCursor.NextRow() as IFeature;
                }
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Er is een onverwachte fout opgetreden; raadpleeg de logfile: " + ex.Message + ": " + ex.StackTrace, "Foutmelding");
                logger.LogException(LogLevel.Trace, "FOUT", ex);
                throw;
            }
            finally
            {
                ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(SelectionCursor);
            }
        }
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            try
            {
                // count how many mileposts were assigned.
                int assignedCounter = 0;

                // show the cursor as busy
                System.Windows.Forms.Cursor.Current = Cursors.WaitCursor;

                // create a text file for logging
                // first check if c:\temp exists, if not create it.
                bool tempDirExists = System.IO.Directory.Exists(@"C:\temp");
                if (!tempDirExists)
                {
                    System.IO.Directory.CreateDirectory(@"C:\temp");
                }

                string path = @"C:\temp\AssignMilepostsToRoads" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm") + ".txt";
                System.IO.FileStream fileStream = new System.IO.FileStream(path, FileMode.Create);
                streamWriter = new StreamWriter(fileStream);
                streamWriter.WriteLine("Assign Mileposts to Road Centerlines began at: " + DateTime.Now.ToString());

                clsGlobals.pMxDocument = (IMxDocument)clsGlobals.arcApplication.Document;
                clsGlobals.pMap        = clsGlobals.pMxDocument.FocusMap;
                clsGlobals.pActiveView = clsGlobals.pMxDocument.ActiveView;

                // make sure the user is editing
                //get the editor extension
                UID arcUID = new UID();
                arcUID.Value         = "esriEditor.Editor";
                clsGlobals.arcEditor = clsGlobals.arcApplication.FindExtensionByCLSID(arcUID) as IEditor3;

                // check if editing first
                if (clsGlobals.arcEditor.EditState == ESRI.ArcGIS.Editor.esriEditState.esriStateNotEditing)
                {
                    MessageBox.Show("You must be editing in order to assign mileposts.", "Must Be Editing", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                // Get access to the needed layers (UTRANS Roads and LRS layers)
                // make sure the user has selected a layer in the toc
                if (clsGlobals.pMxDocument.SelectedLayer == null)
                {
                    MessageBox.Show("Please select the UTRANS roads layer in ArcMap's TOC.", "Select Layer in TOC", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (!(clsGlobals.pMxDocument.SelectedLayer is IFeatureLayer))
                {
                    MessageBox.Show("Please select the UTRANS roads layer in ArcMap's TOC.", "Must be Feature Layer", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                // cast the selected layer as a feature layer
                clsGlobals.pGFlayer = (IGeoFeatureLayer)clsGlobals.pMxDocument.SelectedLayer;

                // check if the feaure layer is a line layer
                if (clsGlobals.pGFlayer.FeatureClass.ShapeType != esriGeometryType.esriGeometryPolyline)
                {
                    MessageBox.Show("Please select a  line layer (UTRANS Roads) in the TOC.", "Must be a Line Layer", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                // Set the Roads GeoFeatureLayer to a FeatureLayer.
                IFeatureLayer featureLayerRoads = (IFeatureLayer)clsGlobals.pGFlayer;

                // Get access to the UTRANS LRS layer in the map - expect it to be the top-most layer in the TOC.
                IFeatureLayer featureLayerLRS = (IFeatureLayer)clsGlobals.pMap.Layer[0];

                // Make sure the alias name for the LRS layer is as such...
                //if (featureLayerLRS.FeatureClass.AliasName != "SGID10.TRANSPORTATION.UDOTRoutes_LRS")
                //{
                //    MessageBox.Show("Make sure the top most layer in the TOC is pointed to SGID10.TRANSPORTATION.UDOTRoutes_LRS", "LRS Layer Missing", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //    return;
                //}
                if (!(featureLayerLRS.FeatureClass.AliasName.ToString().Contains("LRS")))
                {
                    MessageBox.Show("Make sure the top most layer in the TOC is the UDOTRoutes_LRS layer and that it's alias name contains LRS", "Missing LRS Layer Name", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                //// NULL OUT the existing from/to milepost values so we can track the new ones. ////
                clsGlobals.arcEditor.StartOperation();

                // Null out the existing DOT_F_MILE and DOT_T_MILE values
                IQueryFilter queryFilter = new QueryFilter();
                queryFilter.WhereClause = "DOT_F_MILE >= 0 or DOT_T_MILE >= 0";
                // IFeatureCursor arcFeatureCursor = featureLayerRoads.FeatureClass.Search(queryFilter, false);  // use this if you don't want to honor definition query on layer
                IFeatureCursor arcFeatureCursor = clsGlobals.pGFlayer.Search(queryFilter, false); // use this if you want to honor definition query on layer
                IFeature       arcFeature;
                int            nulloutCount = 0;

                streamWriter.WriteLine("Began nulling existing From/To values at: " + DateTime.Now.ToString());
                while ((arcFeature = arcFeatureCursor.NextFeature()) != null)
                {
                    nulloutCount = nulloutCount + 1;
                    arcFeature.set_Value(arcFeature.Fields.FindField("DOT_F_MILE"), DBNull.Value);
                    arcFeature.set_Value(arcFeature.Fields.FindField("DOT_T_MILE"), DBNull.Value);

                    // store edit
                    arcFeature.Store();
                }

                // null out variables
                queryFilter      = null;
                arcFeatureCursor = null;
                arcFeature       = null;

                // Stop Edit Operation.
                clsGlobals.arcEditor.StopOperation("Null MP Values");
                streamWriter.WriteLine("Finished nulling " + nulloutCount.ToString() + " existing From/To values at: " + DateTime.Now.ToString());



                //// ASSIGN THE MILEPOST VALUES ////
                streamWriter.WriteLine("Began assigning mileposts at: " + DateTime.Now.ToString());
                double searchOutDist = 15;
                queryFilter = new QueryFilter();

                // check if sde, filegeodatabase, or shapefile - to determine what query syntax to use
                IDataset datasetRoads = (IDataset)featureLayerRoads.FeatureClass;
                if (datasetRoads.Workspace.Type == esriWorkspaceType.esriLocalDatabaseWorkspace)
                {
                    // file geodatabase
                    queryFilter.WhereClause = "CHAR_LENGTH(DOT_RTNAME) = 5 and (DOT_RTNAME like '0%')";
                }
                else if (datasetRoads.Workspace.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace)
                {
                    // sde geodatabase
                    queryFilter.WhereClause = "LEN(DOT_RTNAME) = 5 and (DOT_RTNAME like '0%')";
                }
                else if (datasetRoads.Workspace.Type == esriWorkspaceType.esriFileSystemWorkspace)
                {
                    // shapefile
                    queryFilter.WhereClause = "(not DOT_RTNAME is null) and char_length (DOT_RTNAME)= 5";
                }

                // log roads layer name and dataset type
                streamWriter.WriteLine("Roads Layer Name: " + featureLayerRoads.Name.ToString());
                streamWriter.WriteLine("Dataset/Workspace Type: " + datasetRoads.Workspace.Type.ToString());

                //arcFeatureCursor = featureLayerRoads.FeatureClass.Search(queryFilter, false); // use this if you don't want to honor definition query on layer
                arcFeatureCursor = clsGlobals.pGFlayer.Search(queryFilter, false); // use this if you want to honor definition query on layer
                IFeature arcFeature_Roads;
                bool     hitStart = false;
                bool     hitEnd   = false;

                // Start edit operation
                clsGlobals.arcEditor.StartOperation();

                while ((arcFeature_Roads = arcFeatureCursor.NextFeature()) != null)
                {
                    // get the route name from roads
                    var roadsRouteName = arcFeature_Roads.get_Value(arcFeature_Roads.Fields.FindField("DOT_RTNAME"));

                    ////double roads_FromMile = 0;
                    ////double roads_ToMile = 0;

                    ////// get the from mile value from roads
                    ////if (arcFeature_Roads.get_Value(arcFeature_Roads.Fields.FindField("DOT_F_MILE")) != DBNull.Value || arcFeature_Roads.get_Value(arcFeature_Roads.Fields.FindField("DOT_F_MILE")).ToString() != "")
                    ////{
                    ////    roads_FromMile = Convert.ToDouble(arcFeature_Roads.get_Value(arcFeature_Roads.Fields.FindField("DOT_F_MILE")));
                    ////}

                    ////// get the to mile value from roads
                    ////if (arcFeature_Roads.get_Value(arcFeature_Roads.Fields.FindField("DOT_T_MILE")) != DBNull.Value || arcFeature_Roads.get_Value(arcFeature_Roads.Fields.FindField("DOT_T_MILE")).ToString() != "")
                    ////{
                    ////    roads_ToMile = Convert.ToDouble(arcFeature_Roads.get_Value(arcFeature_Roads.Fields.FindField("DOT_T_MILE")));
                    ////}

                    // Set up query filter and feature cursor for LRS layer.
                    IQueryFilter queryFilter_LRS = new QueryFilter();
                    queryFilter_LRS.WhereClause = "LABEL = '" + roadsRouteName + "'";
                    IFeatureCursor arcFeatureCursor_LRS = featureLayerLRS.FeatureClass.Search(queryFilter_LRS, false);
                    IFeature       arcFeature_LRS       = arcFeatureCursor_LRS.NextFeature();

                    if (arcFeature_LRS != null)
                    {
                        // START (FROM) POINT //
                        IPolyline polyline_Roads  = (IPolyline)arcFeature_Roads.Shape;
                        IPolyline polyline_LRS    = (IPolyline)arcFeature_LRS.Shape;
                        IPoint    fromPoint_Roads = polyline_Roads.FromPoint;

                        double dist      = 0;
                        int    partIndex = 0;
                        int    segIndex  = 0;
                        bool   right     = false;
                        hitStart = false;

                        IPoint   point_Hit = new ESRI.ArcGIS.Geometry.Point();
                        IHitTest hitTest   = (IHitTest)polyline_LRS;

                        // Hit test to see if a vertex is hit.
                        hitStart = hitTest.HitTest(fromPoint_Roads, searchOutDist, esriGeometryHitPartType.esriGeometryPartVertex, point_Hit, dist, ref partIndex, ref segIndex, right);

                        if (hitStart)
                        {
                            if (point_Hit.M >= 0)
                            {
                                // round to 3 decimals for David Buell's Spillman stuff
                                double dot_f_mile_double = Convert.ToDouble((point_Hit.M * 1000) / 1000);
                                arcFeature_Roads.set_Value(arcFeature_Roads.Fields.FindField("DOT_F_MILE"), Math.Round(dot_f_mile_double, 3));
                                //arcFeature_Roads.set_Value(arcFeature_Roads.Fields.FindField("DOT_F_MILE"), Convert.ToDouble((point_Hit.M * 1000) / 1000));
                            }
                            else
                            {
                                streamWriter.WriteLine("Start/From M coordinate missing on ROUTE: " + roadsRouteName + " with OID:" + arcFeature_Roads.OID.ToString() + " pointHit_M Value: " + point_Hit.M.ToString());
                            }
                        }
                        else
                        {
                            // if no vertex to vertex hit, then interpolate along route segment.
                            // hit test to see if polyline is hit anywhere, not necessarily at vertex
                            hitStart = hitTest.HitTest(fromPoint_Roads, searchOutDist, esriGeometryHitPartType.esriGeometryPartBoundary, point_Hit, dist, ref partIndex, ref segIndex, right);

                            if (hitStart)
                            {
                                IGeometryCollection        geometryCollection = (IGeometryCollection)polyline_LRS;
                                ISegmentCollection         segmentCollection  = (ISegmentCollection)geometryCollection.Geometry[partIndex];
                                ISegment                   segment            = segmentCollection.Segment[segIndex];
                                ESRI.ArcGIS.Geometry.Point outPoint           = new ESRI.ArcGIS.Geometry.Point();
                                double outDist  = 0;
                                double awayDist = 0;
                                double mcoord   = 0;

                                // interpolate
                                segment.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, fromPoint_Roads, true, outPoint, outDist, awayDist, true);
                                mcoord = segment.FromPoint.M + ((segment.ToPoint.M - segment.FromPoint.M) * outDist);
                                // round to 3 decimals for David Buell's Spillman stuff
                                double dot_f_mile_double = Convert.ToDouble((mcoord * 1000) / 1000) + 0.001;
                                arcFeature_Roads.set_Value(arcFeature_Roads.Fields.FindField("DOT_F_MILE"), Math.Round(dot_f_mile_double, 3));
                                // arcFeature_Roads.set_Value(arcFeature_Roads.Fields.FindField("DOT_F_MILE"), Convert.ToDouble((mcoord * 1000) / 1000) + 0.001);
                            }
                            else
                            {
                                streamWriter.WriteLine("  end not found for OID: " + arcFeature_Roads.OID.ToString() + " RTNAME:" + roadsRouteName);
                            }
                        }



                        // END (TO) POINT //
                        ////polyline_Roads = (IPolyline)arcFeature_Roads.Shape;
                        ////polyline_LRS = (IPolyline)arcFeature_LRS.Shape;
                        IPoint toPoint_Roads = polyline_Roads.ToPoint;

                        dist      = 0;
                        partIndex = 0;
                        segIndex  = 0;
                        right     = false;
                        hitEnd    = false;

                        point_Hit = new ESRI.ArcGIS.Geometry.Point();
                        hitTest   = (IHitTest)polyline_LRS;

                        // Hit test to see if a vertex is hit.
                        hitEnd = hitTest.HitTest(toPoint_Roads, searchOutDist, esriGeometryHitPartType.esriGeometryPartVertex, point_Hit, dist, ref partIndex, ref segIndex, right);

                        if (hitEnd)
                        {
                            if (point_Hit.M >= 0)
                            {
                                // round to 3 decimals for David Buell's Spillman stuff
                                double dot_t_mile_double = Convert.ToDouble((point_Hit.M * 1000) / 1000);
                                arcFeature_Roads.set_Value(arcFeature_Roads.Fields.FindField("DOT_T_MILE"), Math.Round(dot_t_mile_double, 3));
                                //arcFeature_Roads.set_Value(arcFeature_Roads.Fields.FindField("DOT_T_MILE"), Convert.ToDouble((point_Hit.M * 1000) / 1000));
                            }
                            else
                            {
                                streamWriter.WriteLine("End/To M coordinate missing on ROUTE: " + roadsRouteName + " with OID:" + arcFeature_Roads.OID.ToString() + " pointHit_M Value: " + point_Hit.M.ToString());
                            }
                        }
                        else
                        {
                            // if no vertex to vertex hit, then interpolate along route segment.
                            // hit test to see if polyline is hit anywhere, not necessarily at vertex
                            hitEnd = hitTest.HitTest(toPoint_Roads, searchOutDist, esriGeometryHitPartType.esriGeometryPartBoundary, point_Hit, dist, ref partIndex, ref segIndex, right);

                            if (hitEnd)
                            {
                                IGeometryCollection        geometryCollection = (IGeometryCollection)polyline_LRS;
                                ISegmentCollection         segmentCollection  = (ISegmentCollection)geometryCollection.Geometry[partIndex];
                                ISegment                   segment            = segmentCollection.Segment[segIndex];
                                ESRI.ArcGIS.Geometry.Point outPoint           = new ESRI.ArcGIS.Geometry.Point();
                                double outDist  = 0;
                                double awayDist = 0;
                                double mcoord   = 0;

                                // interpolate
                                segment.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, toPoint_Roads, true, outPoint, outDist, awayDist, true);
                                mcoord = segment.FromPoint.M + ((segment.ToPoint.M - segment.FromPoint.M) * outDist);
                                // round to 3 decimals for David Buell's Spillman stuff
                                double dot_t_mile_double = Convert.ToDouble((mcoord * 1000) / 1000);
                                arcFeature_Roads.set_Value(arcFeature_Roads.Fields.FindField("DOT_T_MILE"), Math.Round(dot_t_mile_double, 3));
                                //arcFeature_Roads.set_Value(arcFeature_Roads.Fields.FindField("DOT_T_MILE"), Convert.ToDouble((mcoord * 1000) / 1000));
                            }
                            else
                            {
                                streamWriter.WriteLine("  end not found for OID: " + arcFeature_Roads.OID.ToString() + " RTNAME:" + roadsRouteName);
                            }
                        }
                    }
                    else
                    {
                        streamWriter.WriteLine("*** No LRS Route Found for OID:" + arcFeature_Roads.OID.ToString() + " RTNAME:" + roadsRouteName);
                    }

                    // store edit
                    if (hitStart || hitEnd)
                    {
                        arcFeature_Roads.Store();
                        assignedCounter = assignedCounter + 1;
                    }

                    // null out variables
                    queryFilter_LRS = null;
                    //arcFeatureCursor_LRS = null;
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(arcFeatureCursor_LRS);
                    arcFeature_Roads = null;
                }

                // Stop Edit Operation.
                clsGlobals.arcEditor.StopOperation("Assign MP Values");

                // Done! //
                streamWriter.WriteLine();
                streamWriter.WriteLine("Done! Finished with zero errors.  This code assigned " + assignedCounter.ToString() + " road segments/features new mileposts.");
                streamWriter.WriteLine("Finished at: " + DateTime.Now.ToString());
                MessageBox.Show("Done assigning milepost values from SGID LRS Layer.  Don't forget to SAVE edits!  Go to the C:/temp folder to see the log file for this code run.", "Done!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            catch (Exception ex)
            {
                streamWriter.WriteLine();
                streamWriter.WriteLine("Errored-out at: " + DateTime.Now.ToString());
                streamWriter.WriteLine("The code below this line is from the try-catch error message.");
                streamWriter.WriteLine("Error Message: " + Environment.NewLine + ex.Message + Environment.NewLine + Environment.NewLine +
                                       "Error Source: " + Environment.NewLine + ex.Source + Environment.NewLine + Environment.NewLine +
                                       "Error Location:" + Environment.NewLine + ex.StackTrace);

                MessageBox.Show("Error Message: " + Environment.NewLine + ex.Message + Environment.NewLine + Environment.NewLine +
                                "Error Source: " + Environment.NewLine + ex.Source + Environment.NewLine + Environment.NewLine +
                                "Error Location:" + Environment.NewLine + ex.StackTrace,
                                "clsBtnAssignMilepost: ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            finally
            {
                //close the stream writer
                streamWriter.Close();
            }
        }
Ejemplo n.º 47
0
        /// <summary>
        /// Zoekt het dichtstbijzijnde punt op de spoorhartlijnen die binnen de zoekafstand liggen en waarvoor geldt dat de gevonden waarde binnen
        /// het kilometerinterval km_begin en km_eind ligt. De resultaten worden via de parameters outPoint, outPointGevonden en pDistance
        /// </summary>
        /// <param name="Point"></param>
        /// <param name="IndexQueryLRS"></param>
        /// <param name="km_begin"></param>
        /// <param name="km_eind"></param>
        /// <param name="outPoint"></param>
        /// <param name="outPointGevonden"></param>
        /// <param name="pDistance"></param>
        private void ZoekPuntOpSpoorhartlijn(IPoint Point, IIndexQuery2 IndexQueryLRS, double km_begin, double km_eind, out IPoint outPoint, out bool outPointGevonden, out double outPointDistance)
        {
            try
            {
                IPolygon buffer = (Point as ITopologicalOperator).Buffer(this.mshape_maxafstand) as IPolygon;

                distanceAlongCurve = 0;
                bRightSide = false;

                object pSAIds = null;
                double pDistanceToNearestFeature = 0;
                IndexQueryLRS.NearestFeatures(buffer as IGeometry, out pSAIds, out pDistanceToNearestFeature);

                if ((pSAIds == null) || (pDistanceToNearestFeature > 0.001)) // 1 mm
                {
                    outPoint = null;
                    outPointGevonden = false;
                    outPointDistance = double.PositiveInfinity;
                }
                else // er zijn features gevonden binnen de zoekafstand
                {
                    IFeatureCursor FeatureCursorIntersectsLRS = fcLRS.GetFeatures(pSAIds, false);

                    try
                    {
                        outPoint = null;
                        outPointGevonden = false;
                        outPointDistance = double.PositiveInfinity;

                        IFeature featureLRS = FeatureCursorIntersectsLRS.NextFeature();

                        // Zoek het punt dat binnen de kilometertolerantie valt
                        double km_begin_mshape_tolerantie = km_begin - (this.mshape_tolerantie / 1000);
                        double km_eind_mshape_tolerantie = km_eind + (this.mshape_tolerantie / 1000);
                        while (featureLRS != null)
                        {

                            ICurve curveLRS = featureLRS.Shape as ICurve;
                            outPoint = new ESRI.ArcGIS.Geometry.Point();
                            curveLRS.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, Point as IPoint, false, outPoint, distanceAlongCurve, ref outPointDistance, bRightSide);
                            if (outPoint.M >= km_begin_mshape_tolerantie && outPoint.M < km_eind_mshape_tolerantie)
                            {
                                // punt gevonden, verlaat de loop.
                                outPointGevonden = true;
                                break;
                            }

                            featureLRS = FeatureCursorIntersectsLRS.NextFeature();
                        }
                    }
                    catch
                    {
                        throw;
                    }
                    finally
                    {
                        ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(FeatureCursorIntersectsLRS);
                    }
                }

            }
            catch (Exception ex)
            {
                logger.LogException(LogLevel.Trace, "FOUT", ex);
                System.Windows.Forms.MessageBox.Show("Er is een onverwachte fout opgetreden; raadpleeg de logfile: " + ex.Message + ": " + ex.StackTrace, "Foutmelding");
                throw;
            }
        }
Ejemplo n.º 48
0
        public void InsertPointAtIntersection2(ref IPolyline pPolyline, IGeometry pOther, double hmgetal)
        {
            bool SplitHappened = false;
            int newPartIndex = 0;
            int newSegmentIndex = 0;
            int index = 0;
            IPoint Point = null;
            IPoint HitPoint = new ESRI.ArcGIS.Geometry.Point();
            double hitDistance = 0;
            int hitPartIndex = 0;
            int hitSegmentIndex = 0;
            bool bRightSide = false;

            ITopologicalOperator5 pTopoOpOther = pOther as ITopologicalOperator5;
            pTopoOpOther.Simplify();

            ITopologicalOperator6 pTopoOpPolyline = pPolyline as ITopologicalOperator6;
            IGeometry pGeomResult = pTopoOpPolyline.IntersectEx(pOther,false, esriGeometryDimension.esriGeometry0Dimension);

            if ((pGeomResult is IPointCollection) && ((pGeomResult as IPointCollection).PointCount > 0))
            {
                for (int i = 0; i < (pGeomResult as IPointCollection).PointCount; i++)
                {

                    (pPolyline as IHitTest).HitTest(
                        (pGeomResult as IPointCollection).get_Point(i),
                        10,
                        esriGeometryHitPartType.esriGeometryPartBoundary,
                        HitPoint,
                        ref hitDistance,
                        ref hitPartIndex,
                        ref hitSegmentIndex,
                        ref bRightSide);

                    index = 0;
                    for (int j = 0; j < hitPartIndex; j++)
                    {
                        index += ((pPolyline as IGeometryCollection).get_Geometry(j) as IPointCollection).PointCount;
                    }
                    index += hitSegmentIndex;

                    HitPoint.M = hmgetal;
                    (pPolyline as IPointCollection).AddPoint(HitPoint, after: index);

                }

            }
            (pPolyline as ITopologicalOperator2).IsKnownSimple_2 = false;
            (pPolyline as IPolyline4).SimplifyEx(true);
        }
Ejemplo n.º 49
0
        public void fGetElements(double mapX, double mapY, ref  IElement pElement)
        {
            IGraphicsContainerSelect m_graphicsContainerSelect;
            IGraphicsContainer m_graphicsContainer = m_pagelayoutControl.ActiveView as IGraphicsContainer;
            int i, m_selectCount;
            IElement m_element, m_selectElement = null;
            IGeometry m_geometry;
            IMapFrame m_mapFrame;
            bool ifElementHited;

                IPoint m_point = new ESRI.ArcGIS.Geometry.Point();
                m_point.X = mapX;
                m_point.Y = mapY;

                m_mapFrame = m_graphicsContainer.FindFrame(m_pagelayoutControl.ActiveView.FocusMap) as IMapFrame;

                IFrameElement pFramElement = m_mapFrame as IFrameElement;

            ///////////////////////////////////////////////////////////////////////////////////////

                m_graphicsContainerSelect = m_pagelayoutControl.PageLayout as IGraphicsContainerSelect;
                m_selectCount = m_graphicsContainerSelect.ElementSelectionCount;//m_graphicsContainerSelect ���еĿɹ�ѡ���Ԫ��
                if (m_selectCount == 0)
                {
                    m_elementToMove = null;
                    if (pFramElement != null)
                        pElement = pFramElement as IElement;

                }
                else
                {
                    for (i = 0; i < m_selectCount; i++)
                    {
                        m_element = m_graphicsContainerSelect.SelectedElement(i);
                        m_geometry = m_element.Geometry;
                        m_graphicsContainer.LocateElementsByEnvelope(m_geometry.Envelope);//��λ��i��Ԫ�����ڵ�λ��
                        ifElementHited = m_element.HitTest(mapX, mapY, 0.1);//�ж������λ���Ƿ���Ԫ��λ����ͬ
                        if (ifElementHited)
                        {

                            m_graphicsContainerSelect.SelectElement(m_element);//ѡ��Ԫ�أ�һ���������ƶ�
                            m_selectElement = m_element;

                        }

                    }
                    if (m_selectElement == null)//�����û��ѡ��graphicsContainerSelect�е�Ԫ��ʱ
                    {
                          m_elementToMove = pFramElement as IElement ;
                        pElement = pFramElement as IElement;//���ѡ���ͼ���ݿ�
                    }
                    else
                    {
                        pElement = m_selectElement;
                        m_elementToMove = m_selectElement;//��������ƶ���Ԫ�ز�ѡ��Ԫ��
                    }

                }
        }